mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-11-23 00:13:02 +03:00
refactor(pip): move flattenDependencies and ignoredDependencies to separate module pip-hotfixes
This commit is contained in:
parent
b58cc53fac
commit
6646e20dfb
48
modules/drv-parts/pip-hotfixes/default.nix
Normal file
48
modules/drv-parts/pip-hotfixes/default.nix
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
l = lib // builtins;
|
||||
cfg = config.pip;
|
||||
metadata = config.lock.content.fetchPipMetadata;
|
||||
|
||||
ignored = l.genAttrs cfg.ignoredDependencies (name: true);
|
||||
|
||||
filterTarget = target:
|
||||
l.filterAttrs (name: target: ! ignored ? ${name}) target;
|
||||
|
||||
# filter out ignored dependencies
|
||||
targets = l.flip l.mapAttrs metadata.targets (
|
||||
targetName: target:
|
||||
l.flip l.mapAttrs (filterTarget target) (
|
||||
packageName: deps:
|
||||
l.filter (dep: ! ignored ? ${dep}) deps
|
||||
)
|
||||
);
|
||||
in {
|
||||
imports = [
|
||||
./interface.nix
|
||||
];
|
||||
pip.targets = targets;
|
||||
mkDerivation.propagatedBuildInputs =
|
||||
if cfg.flattenDependencies
|
||||
then
|
||||
if targets.default ? ${config.name}
|
||||
then
|
||||
throw ''
|
||||
Top-level package ${config.name} is listed in the lockfile.
|
||||
Set `pip.flattenDependencies` to false to use only the top-level dependencies.
|
||||
''
|
||||
else let
|
||||
topLevelDepNames = l.attrNames (targets.default);
|
||||
in
|
||||
l.map (name: cfg.drvs.${name}.public.out) topLevelDepNames
|
||||
else if ! targets.default ? ${config.name}
|
||||
then
|
||||
throw ''
|
||||
Top-level package ${config.name} is not listed in the lockfile.
|
||||
Set `pip.flattenDependencies` to true to use all dependencies for the top-level package.
|
||||
''
|
||||
else [];
|
||||
}
|
25
modules/drv-parts/pip-hotfixes/interface.nix
Normal file
25
modules/drv-parts/pip-hotfixes/interface.nix
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
l = lib // builtins;
|
||||
t = l.types;
|
||||
in {
|
||||
options.pip = {
|
||||
flattenDependencies = l.mkOption {
|
||||
type = t.bool;
|
||||
description = ''
|
||||
Use all dependencies as top-level dependencies
|
||||
'';
|
||||
default = false;
|
||||
};
|
||||
ignoredDependencies = l.mkOption {
|
||||
type = t.listOf t.str;
|
||||
description = ''
|
||||
list of dependencies to ignore
|
||||
'';
|
||||
default = ["wheel"];
|
||||
};
|
||||
};
|
||||
}
|
@ -9,19 +9,8 @@
|
||||
python = config.deps.python;
|
||||
metadata = config.lock.content.fetchPipMetadata;
|
||||
|
||||
ignored = l.genAttrs cfg.ignoredDependencies (name: true);
|
||||
|
||||
filterTarget = target:
|
||||
l.filterAttrs (name: target: ! ignored ? ${name}) target;
|
||||
|
||||
# filter out ignored dependencies
|
||||
targets = l.flip l.mapAttrs metadata.targets (
|
||||
targetName: target:
|
||||
l.flip l.mapAttrs (filterTarget target) (
|
||||
packageName: deps:
|
||||
l.filter (dep: ! ignored ? ${dep}) deps
|
||||
)
|
||||
);
|
||||
targets = cfg.targets;
|
||||
|
||||
writers = import ../../../pkgs/writers {
|
||||
inherit lib;
|
||||
@ -113,6 +102,7 @@ in {
|
||||
imports = [
|
||||
commonModule
|
||||
./interface.nix
|
||||
../pip-hotfixes
|
||||
];
|
||||
|
||||
config = {
|
||||
@ -138,26 +128,6 @@ in {
|
||||
|
||||
mkDerivation = {
|
||||
dontStrip = l.mkDefault true;
|
||||
propagatedBuildInputs =
|
||||
if cfg.flattenDependencies
|
||||
then
|
||||
if targets.default ? ${config.name}
|
||||
then
|
||||
throw ''
|
||||
Top-level package ${config.name} is listed in the lockfile.
|
||||
Set `pip.flattenDependencies` to false to use only the top-level dependencies.
|
||||
''
|
||||
else let
|
||||
topLevelDepNames = l.attrNames (targets.default);
|
||||
in
|
||||
l.map (name: cfg.drvs.${name}.public.out) topLevelDepNames
|
||||
else if ! targets.default ? ${config.name}
|
||||
then
|
||||
throw ''
|
||||
Top-level package ${config.name} is not listed in the lockfile.
|
||||
Set `pip.flattenDependencies` to true to use all dependencies for the top-level package.
|
||||
''
|
||||
else [];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -9,19 +9,11 @@
|
||||
t = l.types;
|
||||
in {
|
||||
options.pip = {
|
||||
flattenDependencies = l.mkOption {
|
||||
type = t.bool;
|
||||
description = ''
|
||||
Use all dependencies as top-level dependencies
|
||||
'';
|
||||
default = false;
|
||||
};
|
||||
ignoredDependencies = l.mkOption {
|
||||
type = t.listOf t.str;
|
||||
description = ''
|
||||
list of dependencies to ignore
|
||||
'';
|
||||
default = ["wheel"];
|
||||
# internal options to pass data between pip-hotfixes and pip
|
||||
targets = l.mkOption {
|
||||
type = t.raw;
|
||||
internal = true;
|
||||
description = "the targets of the lock file to build";
|
||||
};
|
||||
pypiSnapshotDate = l.mkOption {
|
||||
type = t.str;
|
||||
|
Loading…
Reference in New Issue
Block a user