Skip to content

Commit

Permalink
style: Apply statix/deadnix
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Oct 25, 2023
1 parent 4a829c9 commit c89e48d
Show file tree
Hide file tree
Showing 59 changed files with 250 additions and 280 deletions.
78 changes: 36 additions & 42 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs ? import <nixpkgs> { }
, lib ? pkgs.lib
, poetryLib ? import ./lib.nix { inherit lib pkgs; stdenv = pkgs.stdenv; }
, poetryLib ? import ./lib.nix { inherit lib pkgs; inherit (pkgs) stdenv; }
}:
let
inherit (poetryLib) isCompatible readTOML normalizePackageName normalizePackageSet;
Expand All @@ -11,7 +11,7 @@ let
getLicenseBySpdxId = spdxId: spdxLicenses.${spdxId} or spdxId;

# Experimental withPlugins functionality
toPluginAble = (import ./plugins.nix { inherit pkgs lib; }).toPluginAble;
inherit ((import ./plugins.nix { inherit pkgs lib; })) toPluginAble;

# List of known build systems that are passed through from nixpkgs unmodified
knownBuildSystems = lib.importJSON ./known-build-systems.json;
Expand All @@ -35,19 +35,17 @@ let
compat = isCompatible (poetryLib.getPythonVersion py);
depAttrs = builtins.map (d: lib.toLower d) (builtins.attrNames depSet);
in
(
builtins.map
(
dep:
let
pkg = py.pkgs."${normalizePackageName dep}";
constraints = depSet.${dep}.python or "";
isCompat = compat constraints;
in
if isCompat then pkg else null
)
depAttrs
);
builtins.map
(
dep:
let
pkg = py.pkgs."${normalizePackageName dep}";
constraints = depSet.${dep}.python or "";
isCompat = compat constraints;
in
if isCompat then pkg else null
)
depAttrs;

buildSystemPkgs = poetryLib.getBuildSystemPkgs {
inherit pyProject;
Expand Down Expand Up @@ -156,7 +154,7 @@ lib.makeScope pkgs.newScope (self: {
inherit python scripts;
};

editablePackageSources' = lib.filterAttrs (name: path: path != null) editablePackageSources;
editablePackageSources' = lib.filterAttrs (_name: path: path != null) editablePackageSources;
hasEditable = editablePackageSources' != { };
editablePackage = self.mkPoetryEditablePackage {
inherit pyProject python;
Expand Down Expand Up @@ -205,12 +203,10 @@ lib.makeScope pkgs.newScope (self: {
files = pkgMeta.files or lockFiles.${normalizedName};
pythonPackages = self;

sourceSpec = (
(normalizePackageSet pyProject.tool.poetry.dependencies or { }).${normalizedName}
or (normalizePackageSet pyProject.tool.poetry.dev-dependencies or { }).${normalizedName}
or (normalizePackageSet pyProject.tool.poetry.group.dev.dependencies or { }).${normalizedName} # Poetry 1.2.0+
or { }
);
sourceSpec = (normalizePackageSet pyProject.tool.poetry.dependencies or { }).${normalizedName}
or (normalizePackageSet pyProject.tool.poetry.dev-dependencies or { }).${normalizedName}
or (normalizePackageSet pyProject.tool.poetry.group.dev.dependencies or { }).${normalizedName} # Poetry 1.2.0+
or { };
}
);
}
Expand All @@ -228,7 +224,7 @@ lib.makeScope pkgs.newScope (self: {
(
[
# Remove Python packages aliases with non-normalized names to avoid issues with infinite recursion (issue #750).
(self: super: {
(_self: super: {
# Upstream nixpkgs uses non canonical names
async-generator = super.async-generator or super.async_generator or null;
})
Expand Down Expand Up @@ -257,28 +253,28 @@ lib.makeScope pkgs.newScope (self: {
)

# Fix infinite recursion in a lot of packages because of checkInputs
(self: super: lib.mapAttrs
(name: value: (
(_self: super: lib.mapAttrs
(_name: value: (
if lib.isDerivation value && lib.hasAttr "overridePythonAttrs" value
then value.overridePythonAttrs (_: { doCheck = false; })
else value
))
super)

# Null out any filtered packages, we don't want python.pkgs from nixpkgs
(self: super: builtins.listToAttrs (builtins.map (x: { name = normalizePackageName x.name; value = null; }) incompatible))
(_self: _super: builtins.listToAttrs (builtins.map (x: { name = normalizePackageName 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 groups checkGroups extras; attrs = { }; includeBuildSystem = false; };

requiredPythonModules = python.pkgs.requiredPythonModules;
inherit (python.pkgs) requiredPythonModules;
/* Include all the nested dependencies which are required for each package.
This guarantees that using the "poetryPackages" attribute will return
complete list of dependencies for the poetry project to be portable.
Expand All @@ -290,7 +286,7 @@ lib.makeScope pkgs.newScope (self: {
poetryPackages = storePackages
++ lib.optional hasScripts scriptsPackage
++ lib.optional hasEditable editablePackage;
poetryLock = poetryLock;
inherit poetryLock;
inherit pyProject;
};

Expand All @@ -310,7 +306,7 @@ lib.makeScope pkgs.newScope (self: {
, python ? pkgs.python3
, preferWheels ? false
, editablePackageSources ? { }
, extraPackages ? ps: [ ]
, extraPackages ? _ps: [ ]
, groups ? [ "dev" ]
, checkGroups ? [ "dev" ]
, extras ? [ "*" ]
Expand All @@ -322,24 +318,22 @@ lib.makeScope pkgs.newScope (self: {

# Automatically add dependencies with develop = true as editable packages, but only if path dependencies
getEditableDeps = set: lib.mapAttrs
(name: value: projectDir + "/${value.path}")
(lib.filterAttrs (name: dep: dep.develop or false && hasAttr "path" dep) set);
(_name: value: projectDir + "/${value.path}")
(lib.filterAttrs (_name: dep: dep.develop or false && hasAttr "path" dep) set);

excludedEditablePackageNames = builtins.filter
(pkg: editablePackageSources."${pkg}" == null)
(builtins.attrNames editablePackageSources);

allEditablePackageSources = (
(getEditableDeps (pyProject.tool.poetry."dependencies" or { }))
allEditablePackageSources = (getEditableDeps (pyProject.tool.poetry."dependencies" or { }))
// (getEditableDeps (pyProject.tool.poetry."dev-dependencies" or { }))
// (
# Poetry>=1.2.0
if pyProject.tool.poetry.group or { } != { } then
builtins.foldl' (acc: g: acc // getEditableDeps pyProject.tool.poetry.group.${g}.dependencies) { } groups
else { }
)
// editablePackageSources
);
# Poetry>=1.2.0
if pyProject.tool.poetry.group or { } != { } then
builtins.foldl' (acc: g: acc // getEditableDeps pyProject.tool.poetry.group.${g}.dependencies) { } groups
else { }
)
// editablePackageSources;

editablePackageSources' = builtins.removeAttrs
allEditablePackageSources
Expand Down Expand Up @@ -413,7 +407,7 @@ lib.makeScope pkgs.newScope (self: {
];
} // {
pname = normalizePackageName pyProject.tool.poetry.name;
version = pyProject.tool.poetry.version;
inherit (pyProject.tool.poetry) version;

inherit src;

Expand Down
10 changes: 5 additions & 5 deletions lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ let
# hash: SRI hash
# kind: Language implementation and version tag
predictURLFromPypi = lib.makeOverridable (
{ pname, file, hash, kind }:
{ pname, file, kind }:
"https://files.pythonhosted.org/packages/${kind}/${lib.toLower (builtins.substring 0 1 file)}/${pname}/${file}"
);

Expand All @@ -116,7 +116,7 @@ let
let
predictedURL = predictURLFromPypi { inherit pname file hash kind; };
in
(pkgs.stdenvNoCC.mkDerivation {
pkgs.stdenvNoCC.mkDerivation {
name = file;
nativeBuildInputs = [
pkgs.buildPackages.curl
Expand All @@ -141,16 +141,16 @@ let
passthru = {
urls = [ predictedURL ]; # retain compatibility with nixpkgs' fetchurl
};
})
}
);

fetchFromLegacy = lib.makeOverridable (
{ python, pname, url, file, hash }:
let
pathParts =
(builtins.filter
builtins.filter
({ prefix, path }: "NETRC" == prefix)
builtins.nixPath);
builtins.nixPath;
netrc_file = if (pathParts != [ ]) then (builtins.head pathParts).path else "";
in
pkgs.runCommand file
Expand Down
2 changes: 1 addition & 1 deletion overlay.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
final: prev: {
final: _prev: {
poetry2nix = import ./default.nix { pkgs = final; };
}
Loading

0 comments on commit c89e48d

Please sign in to comment.