Perform dead code elimination using deadnix

deadnix: https://github.com/astro/deadnix
This commit is contained in:
adisbladis 2021-12-07 21:07:30 -08:00
parent a4b7692032
commit 6c432f2dd2
13 changed files with 51 additions and 61 deletions

View file

@ -144,14 +144,6 @@ lib.makeScope pkgs.newScope (self: {
lockfiles = lib.getAttrFromPath [ "metadata" "files" ] poetryLock;
in
lib.listToAttrs (lib.mapAttrsToList (n: v: { name = moduleName n; value = v; }) lockfiles);
specialAttrs = [
"overrides"
"poetrylock"
"projectDir"
"pwd"
"preferWheels"
];
passedAttrs = builtins.removeAttrs attrs specialAttrs;
evalPep508 = mkEvalPep508 python;
# Filter packages by their PEP508 markers & pyproject interpreter version
@ -167,9 +159,8 @@ lib.makeScope pkgs.newScope (self: {
#
# We need to avoid mixing multiple versions of pythonPackages in the same
# closure as python can only ever have one version of a dependency
baseOverlay = self: super:
baseOverlay = self: _super:
let
getDep = depName: self.${depName};
lockPkgs = builtins.listToAttrs (
builtins.map
(
@ -218,13 +209,13 @@ lib.makeScope pkgs.newScope (self: {
}
)
# Null out any filtered packages, we don't want python.pkgs from nixpkgs
(self: super: builtins.listToAttrs (builtins.map (x: { name = moduleName x.name; value = null; }) incompatible))
(_self: _super: builtins.listToAttrs (builtins.map (x: { name = moduleName x.name; value = null; }) incompatible))
# Create poetry2nix layer
baseOverlay
] ++ # User provided overrides
(if builtins.typeOf overrides == "list" then overrides else [ overrides ])
);
packageOverrides = lib.foldr lib.composeExtensions (self: super: { }) overlays;
packageOverrides = lib.foldr lib.composeExtensions (_self: _super: { }) overlays;
py = python.override { inherit packageOverrides; self = py; };
inputAttrs = mkInputAttrs { inherit py pyProject; attrs = { }; includeBuildSystem = false; };

View file

@ -136,11 +136,11 @@ pythonPackages.callPackage
let
compat = isCompatible (poetryLib.getPythonVersion python);
deps = lib.filterAttrs
(n: v: v)
(_n: v: v)
(
lib.mapAttrs
(
n: v:
_n: v:
let
constraints = v.python or "";
pep508Markers = v.markers or "";

View file

@ -100,7 +100,7 @@ self: super:
);
black = super.black.overridePythonAttrs (
old: {
_old: {
dontPreferSetupPy = true;
}
);
@ -156,13 +156,13 @@ self: super:
);
cheroot = super.cheroot.overridePythonAttrs (
old: {
_old: {
dontPreferSetupPy = true;
}
);
cloudflare = super.cloudflare.overridePythonAttrs (
old: {
_old: {
postPatch = ''
rm -rf examples/*
'';
@ -228,7 +228,7 @@ self: super:
'';
});
daphne = super.daphne.overridePythonAttrs (old: {
daphne = super.daphne.overridePythonAttrs (_old: {
postPatch = ''
substituteInPlace setup.py --replace 'setup_requires=["pytest-runner"],' ""
'';
@ -427,7 +427,7 @@ self: super:
DISABLE_LIBC_COMPATIBILITY = 1;
});
grpcio-tools = super.grpcio-tools.overridePythonAttrs (old: {
grpcio-tools = super.grpcio-tools.overridePythonAttrs (_old: {
outputs = [ "out" "dev" ];
});
@ -473,7 +473,7 @@ self: super:
);
hid = super.hid.overridePythonAttrs (
old: {
_old: {
postPatch = ''
found=
for name in libhidapi-hidraw libhidapi-libusb libhidapi-iohidmanager libhidapi; do
@ -566,14 +566,14 @@ self: super:
);
importlib-resources = super.importlib-resources.overridePythonAttrs (
old: {
_old: {
# disable the removal of pyproject.toml, required because of setuptools_scm
dontPreferSetupPy = true;
}
);
intreehooks = super.intreehooks.overridePythonAttrs (
old: {
_old: {
doCheck = false;
}
);
@ -617,7 +617,7 @@ self: super:
);
jsonpickle = super.jsonpickle.overridePythonAttrs (
old: {
_old: {
dontPreferSetupPy = true;
}
);
@ -628,7 +628,7 @@ self: super:
});
jupyter = super.jupyter.overridePythonAttrs (
old: rec {
_old: rec {
# jupyter is a meta-package. Everything relevant comes from the
# dependencies. It does however have a jupyter.py file that conflicts
# with jupyter-core so this meta solves this conflict.
@ -678,7 +678,7 @@ self: super:
propagatedBuildInputs = [ pkgs.libvirt ];
});
licensecheck = super.licensecheck.overridePythonAttrs (old: {
licensecheck = super.licensecheck.overridePythonAttrs (_old: {
dontPreferSetupPy = true;
});
@ -992,7 +992,7 @@ self: super:
}
);
paramiko = super.paramiko.overridePythonAttrs (old: {
paramiko = super.paramiko.overridePythonAttrs (_old: {
doCheck = false; # requires networking
});
@ -1003,7 +1003,7 @@ self: super:
);
pdal = super.pdal.overridePythonAttrs (
old: {
_old: {
PDAL_CONFIG = "${pkgs.pdal}/bin/pdal-config";
}
);
@ -1035,7 +1035,7 @@ self: super:
'';
});
poetry-core = super.poetry-core.overridePythonAttrs (old: {
poetry-core = super.poetry-core.overridePythonAttrs (_old: {
# "Vendor" dependencies (for build-system support)
postPatch = ''
echo "import sys" >> poetry/__init__.py
@ -1182,7 +1182,7 @@ self: super:
});
pygame = super.pygame.overridePythonAttrs (
old: rec {
_old: rec {
nativeBuildInputs = [
pkgs.pkg-config
pkgs.SDL
@ -1284,7 +1284,7 @@ self: super:
);
pytoml = super.pytoml.overridePythonAttrs (
old: {
_old: {
doCheck = false;
}
);
@ -1394,7 +1394,7 @@ self: super:
);
pytest-datadir = super.pytest-datadir.overridePythonAttrs (
old: {
_old: {
postInstall = ''
rm -f $out/LICENSE
'';
@ -1411,7 +1411,7 @@ self: super:
);
pytest-django = super.pytest-django.overridePythonAttrs (
old: {
_old: {
postPatch = ''
substituteInPlace setup.py --replace "'pytest>=3.6'," ""
substituteInPlace setup.py --replace "'pytest>=3.6'" ""
@ -1428,7 +1428,7 @@ self: super:
pytest-runner = super.pytest-runner or super.pytestrunner;
pytest-pylint = super.pytest-pylint.overridePythonAttrs (
old: {
_old: {
buildInputs = [ self.pytest-runner ];
}
);
@ -1455,7 +1455,7 @@ self: super:
});
python-jose = super.python-jose.overridePythonAttrs (
old: {
_old: {
buildInputs = [ self.pytest-runner ];
}
);
@ -1485,7 +1485,7 @@ self: super:
);
pyusb = super.pyusb.overridePythonAttrs (
old: {
_old: {
postPatch = ''
libusb=${pkgs.libusb1.out}/lib/libusb-1.0${pkgs.stdenv.hostPlatform.extensions.sharedLibrary}
test -f $libusb || { echo "ERROR: $libusb doesn't exist, please update/fix this build expression."; exit 1; }
@ -1509,7 +1509,7 @@ self: super:
);
rockset = super.rockset.overridePythonAttrs (
old: rec {
_old: rec {
postPatch = ''
cp ./setup_rockset.py ./setup.py
'';
@ -1517,7 +1517,7 @@ self: super:
);
scaleapi = super.scaleapi.overridePythonAttrs (
old: {
_old: {
postPatch = ''
substituteInPlace setup.py --replace "install_requires = ['requests>=2.4.2', 'enum34']" "install_requires = ['requests>=2.4.2']" || true
'';
@ -1701,7 +1701,7 @@ self: super:
);
tensorflow = super.tensorflow.overridePythonAttrs (
old: {
_old: {
postInstall = ''
rm $out/bin/tensorboard
'';
@ -1709,7 +1709,7 @@ self: super:
);
tensorpack = super.tensorpack.overridePythonAttrs (
old: {
_old: {
postPatch = ''
substituteInPlace setup.cfg --replace "# will call find_packages()" ""
'';
@ -1811,7 +1811,7 @@ self: super:
);
vose-alias-method = super.vose-alias-method.overridePythonAttrs (
old: {
_old: {
postInstall = ''
rm -f $out/LICENSE
'';
@ -1883,7 +1883,7 @@ self: super:
}
).wheel.override {
inherit (self) buildPythonPackage bootstrapped-pip setuptools;
}).overrideAttrs (old: {
}).overrideAttrs (_old: {
inherit (super.wheel) pname name version src;
});
in
@ -2079,13 +2079,13 @@ self: super:
);
lazy-object-proxy = super.lazy-object-proxy.overridePythonAttrs (
old: {
_old: {
# disable the removal of pyproject.toml, required because of setuptools_scm
dontPreferSetupPy = true;
}
);
pendulum = super.pendulum.overridePythonAttrs (old: {
pendulum = super.pendulum.overridePythonAttrs (_old: {
# Technically incorrect, but fixes the build error..
preInstall = lib.optionalString stdenv.isLinux ''
mv --no-clobber ./dist/*.whl $(echo ./dist/*.whl | sed s/'manylinux_[0-9]*_[0-9]*'/'manylinux1'/)

View file

@ -157,9 +157,8 @@ let
else if v == "False" then false
else builtins.fromJSON v
);
hasElem = needle: haystack: builtins.elem needle (builtins.filter (x: builtins.typeOf x == "string") (builtins.split " " haystack));
op = {
"true" = x: y: true;
"true" = _x: _y: true;
"<=" = x: y: op.">=" y x;
"<" = x: y: lib.versionOlder (unmarshal x) (unmarshal y);
"!=" = x: y: x != y;

View file

@ -11,7 +11,7 @@ let
, buildInputs ? [ ]
}:
let
env = self.python.withPackages (ps: plugins);
env = self.python.withPackages (_ps: plugins);
in
stdenv.mkDerivation {
pname = drv.pname + "-with-plugins";

View file

@ -10,7 +10,7 @@
# Nixpkgs overlay providing the application
overlay = nixpkgs.lib.composeManyExtensions [
poetry2nix.overlay
(final: prev: {
(_final: prev: {
# The application
myapp = prev.poetry2nix.mkPoetryApplication {
projectDir = ./.;

View file

@ -10,9 +10,9 @@ poetry2nix.mkPoetryApplication {
poetry2nix.defaultPoetryOverrides
(import ./poetry-git-overlay.nix { inherit pkgs; })
(
self: super: {
_self: super: {
pyramid-deferred-sqla = super.pyramid-deferred-sqla.overridePythonAttrs (
old: {
_old: {
postPatch = ''
touch LICENSE
substituteInPlace setup.py --replace 'setup_requires=["pytest-runner"],' ""

View file

@ -1,5 +1,5 @@
{ pkgs }:
self: super: {
_self: super: {
pyramid-deferred-sqla = super.pyramid-deferred-sqla.overridePythonAttrs (
_: {

View file

@ -1,9 +1,9 @@
{ lib, poetry2nix, python3 }:
let
p2nix = poetry2nix.overrideScope' (self: super: {
p2nix = poetry2nix.overrideScope' (_self: super: {
defaultPoetryOverrides = (super.defaultPoetryOverrides.extend (pyself: pysuper: {
my-custom-pkg = super.my-custom-pkg.overridePythonAttrs (oldAttrs: { });
defaultPoetryOverrides = (super.defaultPoetryOverrides.extend (_pyself: _pysuper: {
my-custom-pkg = super.my-custom-pkg.overridePythonAttrs (_oldAttrs: { });
}));
});
@ -12,7 +12,7 @@ in
p2nix.mkPoetryApplication {
python = python3;
projectDir = ./.;
overrides = p2nix.overrides.withDefaults (self: super: {
overrides = p2nix.overrides.withDefaults (_self: super: {
customjox = super.customjox;
});
}

View file

@ -1,5 +1,5 @@
{ pkgs }:
self: super: {
_self: super: {
alembic = super.alembic.overridePythonAttrs (
_: {

View file

@ -8,15 +8,15 @@ let
overrides = [
((
poetry2nix.defaultPoetryOverrides.overrideOverlay (
self: super: {
_self: super: {
alembic = super.alembic.overrideAttrs (
old: {
_old: {
TESTING_FOOBAR = 42;
}
);
}
)
).extend (pyself: pysuper: { })) # Test .extend for good measure
).extend (_pyself: _pysuper: { })) # Test .extend for good measure
];
};
in

View file

@ -6,9 +6,9 @@ let
poetrylock = ./poetry.lock;
pyproject = ./pyproject.toml;
overrides = poetry2nix.overrides.withDefaults (
self: super: {
_self: super: {
alembic = super.alembic.overrideAttrs (
old: {
_old: {
TESTING_FOOBAR = 42;
}
);

View file

@ -7,7 +7,7 @@ let
overrides = poetry2nix.overrides.withDefaults
# This is also in overrides.nix but repeated for completeness
(
self: super: {
_: super: {
maturin = super.maturin.override {
preferWheel = true;
};