diff --git a/vendor/pyproject.nix/default.nix b/vendor/pyproject.nix/default.nix index 896cf9968..1c61750a3 100644 --- a/vendor/pyproject.nix/default.nix +++ b/vendor/pyproject.nix/default.nix @@ -1,4 +1,8 @@ { lib }: -{ +lib.fix (self: { lib = import ./lib { inherit lib; }; -} + build = import ./build { + pyproject-nix = self; + inherit lib; + }; +}) diff --git a/vendor/pyproject.nix/lib/pep440.nix b/vendor/pyproject.nix/lib/pep440.nix index 555488157..e488feac5 100644 --- a/vendor/pyproject.nix/lib/pep440.nix +++ b/vendor/pyproject.nix/lib/pep440.nix @@ -42,6 +42,7 @@ let post = null; pre = null; release = [ ]; + str = ""; }; # We consider some words to be alternate spellings of other words and @@ -164,11 +165,14 @@ fix (self: { # Split post345 into ["post" "345"] m = match "-?([^0-9]+)([0-9]+)" mod; in - assert m != null; - { - type = normalizedReleaseType (elemAt m 0); - value = toIntRelease (elemAt m 1); - } + if m == null then + throw "PEP-440 modifier segment invalid: ${mod}" + # assert m != null; + else + { + type = normalizedReleaseType (elemAt m 0); + value = toIntRelease (elemAt m 1); + } ) (filter (s: isString s && s != "") (split "\\." modifiersSegment)); in @@ -190,6 +194,11 @@ fix (self: { # Local releases needs to be treated specially. # The value isn't just a straight up number, but an arbitrary string. local = if local != "" then local else null; + + # Return the input verbatim for lexicographical comparisons such as those + # done for platform_release which is parsed as PEP-440 when compliant, + # but are compare lexicographically when the version string is non-compliant. + str = version; }; /* diff --git a/vendor/pyproject.nix/lib/pep508.nix b/vendor/pyproject.nix/lib/pep508.nix index c7322eb53..a717b1968 100644 --- a/vendor/pyproject.nix/lib/pep508.nix +++ b/vendor/pyproject.nix/lib/pep508.nix @@ -23,11 +23,19 @@ let length isList any + isAttrs + tryEval + deepSeq + splitVersion + concatStringsSep + tail ; inherit (lib) stringToCharacters sublist hasInfix + take + toInt ; inherit (import ./util.nix { inherit lib; }) splitComma stripStr; @@ -42,6 +50,25 @@ let type = "version"; value = pep440.parseVersion value; }; + + emptyPlatformRelease = { + type = "platform_release"; + value = ""; + }; + + platform_release = + value: + if value == "" then + emptyPlatformRelease + else + let + parsed' = pep440.parseVersion value; + eval' = tryEval (deepSeq parsed' parsed'); + in + { + type = "platform_release"; + value = if eval'.success then eval'.value else value; + }; in { "implementation_name" = default; @@ -49,9 +76,9 @@ let "os_name" = default; "platform_machine" = default; "platform_python_implementation" = default; - "platform_release" = default; + "platform_release" = platform_release; "platform_system" = default; - "platform_version" = version; + "platform_version" = default; "python_full_version" = version; "python_version" = version; "sys_platform" = default; @@ -83,6 +110,31 @@ let "!=" = extras: extra: if typeOf extras == "list" then !(elem extra extras) else extras != extra; }; + # Platform_release parsing is more complicated than other fields. + # + # If both lhs and rhs were correctly parsed as PEP-440 versions run regular version comparison, + # otherwise compare lexicographically + # + # See: + # - https://github.com/pypa/packaging/issues/774 + # - https://github.com/astral-sh/uv/issues/3917#issuecomment-2141754917 + platformReleaseComparators = { + "==" = + a: b: if isAttrs a && isAttrs b then pep440.comparators."==" a b else (a.str or a) == (b.str or b); + "!=" = + a: b: if isAttrs a && isAttrs b then pep440.comparators."!=" a b else (a.str or a) != (b.str or b); + "<=" = + a: b: if isAttrs a && isAttrs b then pep440.comparators."<=" a b else (a.str or a) <= (b.str or b); + ">=" = + a: b: if isAttrs a && isAttrs b then pep440.comparators.">=" a b else (a.str or a) >= (b.str or b); + "<" = + a: b: if isAttrs a && isAttrs b then pep440.comparators."<" a b else (a.str or a) < (b.str or b); + + ">" = + a: b: if isAttrs a && isAttrs b then pep440.comparators.">" a b else (a.str or a) > (b.str or b); + "===" = a: b: a == b; + }; + boolOps = { "and" = x: y: x && y; "or" = x: y: x || y; @@ -614,22 +666,42 @@ in let inherit (python) stdenv; inherit (stdenv) targetPlatform; + inherit (targetPlatform) + isLinux + isDarwin + isFreeBSD + isAarch64 + isx86_64 + ; impl = python.passthru.implementation; in mapAttrs (name: markerFields.${name}) { os_name = if python.pname == "jython" then "java" else "posix"; sys_platform = - if stdenv.isLinux then + if isLinux then "linux" - else if stdenv.isDarwin then + else if isDarwin then "darwin" + else if isFreeBSD then + "freebsd${head (splitVersion stdenv.cc.libc.version)}" else throw "Unsupported platform"; platform_machine = - if targetPlatform.isDarwin then + if isDarwin then targetPlatform.darwinArch + else if isLinux then + pep599.manyLinuxTargetMachines.${targetPlatform.parsed.cpu.name} or targetPlatform.parsed.cpu.name + else if isFreeBSD then + ( + if isx86_64 then + "amd64" + else if isAarch64 then + "arm64" + else + throw "Unhandled FreeBSD architecture" + ) else - pep599.manyLinuxTargetMachines.${targetPlatform.parsed.cpu.name} or targetPlatform.parsed.cpu.name; + throw "Unsupported platform"; platform_python_implementation = if impl == "cpython" then "CPython" @@ -637,12 +709,30 @@ in "PyPy" else throw "Unsupported implementation ${impl}"; - platform_release = ""; # Field not reproducible + # We have no reliable value to set platform_release to. + # In theory this could be set to linuxHeaders.version on Linux, but that's + # not correct + platform_release = + if isLinux then + stdenv.cc.libc.linuxHeaders.version + else if isDarwin then + ( + let + tokens = splitVersion targetPlatform.darwinSdkVersion; + in + concatStringsSep "." ([ (toString ((toInt (head tokens)) + 9)) ] ++ tail tokens) + ) + else if isFreeBSD then + "${concatStringsSep "." (take 2 (splitVersion stdenv.cc.libc.version))}-RELEASE" + else + throw "Unsupported platform"; platform_system = - if stdenv.isLinux then + if isLinux then "Linux" - else if stdenv.isDarwin then + else if isDarwin then "Darwin" + else if isFreeBSD then + "FreeBSD" else throw "Unsupported platform"; platform_version = ""; # Field not reproducible @@ -675,8 +765,11 @@ in if value.type == "compare" then ( ( + # platform_release is being compared as foo + if value.lhs.type == "variable" && value.lhs.value == "platform_release" then + platformReleaseComparators.${value.op} # Version comparison - if value.lhs.type == "version" || value.rhs.type == "version" then + else if value.lhs.type == "version" || value.rhs.type == "version" then pep440.comparators.${value.op} # `Extra` environment marker comparison requires special casing because it's equality checks can # == can be considered a `"key" in set` comparison when multiple extras are activated for a dependency. @@ -694,7 +787,7 @@ in boolOps.${value.op} (evalMarkers environ value.lhs) (evalMarkers environ value.rhs) else if value.type == "variable" then (evalMarkers environ environ.${value.value}) - else if value.type == "version" || value.type == "extra" then + else if value.type == "version" || value.type == "extra" || value.type == "platform_release" then value.value else if elem value.type primitives then value.value diff --git a/vendor/pyproject.nix/lib/pep621.nix b/vendor/pyproject.nix/lib/pep621.nix index ed6b1f3bf..2ddedb55f 100644 --- a/vendor/pyproject.nix/lib/pep621.nix +++ b/vendor/pyproject.nix/lib/pep621.nix @@ -11,6 +11,8 @@ let foldl' split filter + concatMap + isAttrs ; inherit (lib) isString @@ -51,21 +53,49 @@ fix (_self: { pyproject, extrasAttrPaths ? [ ], extrasListPaths ? { }, + groupsAttrPaths ? [ ], + groupsListPaths ? { }, }: let # Fold extras from all considered attributes into one set extras' = - foldl' (acc: attr: acc // getAttrPath attr { } pyproject) (pyproject.project.optional-dependencies + (foldl' (acc: attr: acc // getAttrPath attr { } pyproject) (pyproject.project.optional-dependencies or { } - ) extrasAttrPaths + ) extrasAttrPaths) // filterAttrs (_: deps: length deps > 0) ( mapAttrs' (path: attr: nameValuePair attr (getAttrPath path [ ] pyproject)) extrasListPaths ); + + depGroups' = + (foldl' (acc: attr: acc // getAttrPath attr { } pyproject) (pyproject.dependency-groups or { } + ) groupsAttrPaths) + // filterAttrs (_: deps: length deps > 0) ( + mapAttrs' (path: attr: nameValuePair attr (getAttrPath path [ ] pyproject)) groupsListPaths + ); + in { dependencies = map pep508.parseString (pyproject.project.dependencies or [ ]); extras = mapAttrs (_: map pep508.parseString) extras'; build-systems = pep518.parseBuildSystems pyproject; + + # PEP-735 dependency groups + groups = + let + groups' = mapAttrs ( + _group: + concatMap ( + x: + if isString x then + [ (pep508.parseString x) ] + else if isAttrs x then + groups'.${x.include-group} + else + throw "Unsupported dependency group: ${x}" + ) + ) depGroups'; + in + groups'; }; /* @@ -115,6 +145,7 @@ fix (_self: { dependencies = filterList dependencies.dependencies; extras = mapAttrs (_: filterList) dependencies.extras; build-systems = filterList dependencies.build-systems; + groups = mapAttrs (_: filterList) dependencies.groups; } ); }) diff --git a/vendor/pyproject.nix/lib/poetry.nix b/vendor/pyproject.nix/lib/poetry.nix index b78274ac7..7f0921e9b 100644 --- a/vendor/pyproject.nix/lib/poetry.nix +++ b/vendor/pyproject.nix/lib/poetry.nix @@ -21,6 +21,7 @@ lib.fix ( length filter split + concatStringsSep ; inherit (lib) optionalAttrs concatLists; inherit (import ./util.nix { inherit lib; }) splitComma; @@ -234,6 +235,9 @@ lib.fix ( _: group: map parseDependency (normalizeDependendenciesToList group.dependencies) ) pyproject.tool.poetry.group or { }; build-systems = pep518.parseBuildSystems pyproject; + + # PEP-735 dependency groups + groups = { }; }; /* @@ -269,7 +273,7 @@ lib.fix ( } { op = "<"; - version = version // { + version = version // rec { release = lib.imap0 ( i: tok: if i >= segments - 1 then @@ -279,6 +283,7 @@ lib.fix ( else tok ) version.release; + str = concatStringsSep "." (map toString release); # Overwrite with upper bounds }; } ] @@ -291,8 +296,9 @@ lib.fix ( } { op = "<"; - version = version // { + version = version // rec { release = rewriteCaretRhs version.release; + str = concatStringsSep "." (map toString release); # Overwrite with upper bounds }; } ] diff --git a/vendor/pyproject.nix/lib/project.nix b/vendor/pyproject.nix/lib/project.nix deleted file mode 100644 index 9d6859fb9..000000000 --- a/vendor/pyproject.nix/lib/project.nix +++ /dev/null @@ -1,238 +0,0 @@ -{ - pep621, - poetry, - pip, - lib, - renderers, - validators, - ... -}: - -let - inherit (builtins) mapAttrs; - - # Map over renderers and inject project argument. - # This allows for a user interface like: - # project.renderers.buildPythonPackage { } where project is already curried. - curryProject = - attrs: project: - lib.mapAttrs ( - _: func: args: - func (args // { inherit project; }) - ) attrs; - - # Package manager specific extensions. - # Remap extension fields to optional-dependencies - uvListPaths = { - "tool.uv.dev-dependencies" = "dev-dependencies"; - }; - pdmAttrPaths = [ "tool.pdm.dev-dependencies" ]; - -in -lib.fix (self: { - /* - Load dependencies from a PEP-621 pyproject.toml. - - Type: loadPyproject :: AttrSet -> AttrSet - - Example: - # loadPyproject { pyproject = lib.importTOML } - { - dependencies = { }; # Parsed dependency structure in the schema of `lib.pep621.parseDependencies` - build-systems = [ ]; # Returned by `lib.pep518.parseBuildSystems` - pyproject = { }; # The unmarshaled contents of pyproject.toml - projectRoot = null; # Path to project root - requires-python = null; # requires-python as parsed by pep621.parseRequiresPython - } - */ - loadPyproject = - { - # The unmarshaled contents of pyproject.toml - pyproject ? lib.importTOML (projectRoot + "/pyproject.toml"), - # Example: extrasAttrPaths = [ "tool.pdm.dev-dependencies" ]; - extrasAttrPaths ? [ ], - # Example: extrasListPaths = { "tool.uv.dependencies.dev-dependencies" = "dev-dependencies"; } - extrasListPaths ? { }, - # Path to project root - projectRoot ? null, - }: - lib.fix (project: { - dependencies = pep621.parseDependencies { inherit pyproject extrasAttrPaths extrasListPaths; }; - inherit pyproject projectRoot; - renderers = curryProject renderers project; - validators = curryProject validators project; - requires-python = pep621.parseRequiresPython pyproject; - }); - - /* - Load dependencies from a uv pyproject.toml. - - Type: loadUVPyproject :: AttrSet -> AttrSet - - Example: - # loadUVPyproject { projectRoot = ./.; } - { - dependencies = { }; # Parsed dependency structure in the schema of `lib.pep621.parseDependencies` - build-systems = [ ]; # Returned by `lib.pep518.parseBuildSystems` - pyproject = { }; # The unmarshaled contents of pyproject.toml - projectRoot = null; # Path to project root - requires-python = null; # requires-python as parsed by pep621.parseRequiresPython - } - */ - loadUVPyproject = - { - # The unmarshaled contents of pyproject.toml - pyproject ? lib.importTOML (projectRoot + "/pyproject.toml"), - # Path to project root - projectRoot ? null, - }: - self.loadPyproject { - inherit pyproject projectRoot; - extrasListPaths = uvListPaths; - }; - - /* - Load dependencies from a PDM pyproject.toml. - - Type: loadPDMPyproject :: AttrSet -> AttrSet - - Example: - # loadPyproject { projectRoot = ./.; } - { - dependencies = { }; # Parsed dependency structure in the schema of `lib.pep621.parseDependencies` - build-systems = [ ]; # Returned by `lib.pep518.parseBuildSystems` - pyproject = { }; # The unmarshaled contents of pyproject.toml - projectRoot = null; # Path to project root - requires-python = null; # requires-python as parsed by pep621.parseRequiresPython - } - */ - loadPDMPyproject = - { - # The unmarshaled contents of pyproject.toml - pyproject ? lib.importTOML (projectRoot + "/pyproject.toml"), - # Path to project root - projectRoot ? null, - # The unmarshaled contents of pdm.lock - pdmLock ? lib.importTOML (projectRoot + "/pdm.lock"), - }: - self.loadPyproject { - inherit pyproject projectRoot; - extrasAttrPaths = pdmAttrPaths; - } - // { - inherit pdmLock; - }; - - /* - Load dependencies from a Poetry pyproject.toml. - - Type: loadPoetryPyproject :: AttrSet -> AttrSet - - Example: - # loadPoetryPyproject { projectRoot = ./.; } - { - dependencies = { }; # Parsed dependency structure in the schema of `lib.pep621.parseDependencies` - build-systems = [ ]; # Returned by `lib.pep518.parseBuildSystems` - pyproject = { }; # The unmarshaled contents of pyproject.toml - projectRoot = null; # Path to project root - requires-python = null; # requires-python as parsed by pep621.parseRequiresPython - } - */ - loadPoetryPyproject = - { - # The unmarshaled contents of pyproject.toml - pyproject ? lib.importTOML (projectRoot + "/pyproject.toml"), - # Path to project root - projectRoot ? null, - # The unmarshaled contents of poetry.lock - poetryLock ? lib.importTOML (projectRoot + "/poetry.lock"), - }: - let - pyproject-pep621 = poetry.translatePoetryProject pyproject; - in - lib.fix (project: { - dependencies = poetry.parseDependencies pyproject; - pyproject = pyproject-pep621; - pyproject-poetry = pyproject; - renderers = curryProject renderers project; - validators = curryProject validators project; - inherit projectRoot poetryLock; - requires-python = null; - }); - - /* - Load dependencies from a requirements.txt. - - Note that as requirements.txt is lacking important project metadata this is incompatible with some renderers. - - Type: loadRequirementsTxt :: AttrSet -> AttrSet - - Example: - # loadRequirementstxt { requirements = builtins.readFile ./requirements.txt; projectRoot = ./.; } - { - dependencies = { }; # Parsed dependency structure in the schema of `lib.pep621.parseDependencies` - build-systems = [ ]; # Returned by `lib.pep518.parseBuildSystems` - pyproject = null; # The unmarshaled contents of pyproject.toml - projectRoot = null; # Path to project root - requires-python = null; # requires-python as parsed by pep621.parseRequiresPython - } - */ - loadRequirementsTxt = - { - # The contents of requirements.txt - requirements ? builtins.readFile (projectRoot + "/requirements.txt"), - # Path to project root - projectRoot ? null, - }: - lib.fix (project: { - dependencies = { - dependencies = map (x: x.requirement) (pip.parseRequirementsTxt requirements); - extras = { }; - build-systems = [ ]; - }; - pyproject = null; - renderers = curryProject renderers project; - validators = curryProject validators project; - inherit projectRoot; - requires-python = null; - }); - - /* - Load dependencies from a either a PEP-621 or Poetry pyproject.toml file. - This function is intended for 2nix authors that wants to include local pyproject.toml files - but don't know up front whether they're from Poetry or PEP-621. - - Type: loadPyprojectDynamic :: AttrSet -> AttrSet - - Example: - # loadPyprojectDynamic { projectRoot = ./.; } - { - dependencies = { }; # Parsed dependency structure in the schema of `lib.pep621.parseDependencies` - build-systems = [ ]; # Returned by `lib.pep518.parseBuildSystems` - pyproject = { }; # The unmarshaled contents of pyproject.toml - projectRoot = null; # Path to project root - requires-python = null; # requires-python as parsed by pep621.parseRequiresPython - } - */ - loadPyprojectDynamic = - { - # The unmarshaled contents of pyproject.toml - pyproject ? lib.importTOML (projectRoot + "/pyproject.toml"), - # Path to project root - projectRoot ? null, - }: - let - isPoetry = pyproject ? tool.poetry; - isPep621 = pyproject ? project; - in - if isPoetry then - self.loadPoetryPyproject { inherit pyproject projectRoot; } - else if isPep621 then - self.loadPyproject { - inherit pyproject projectRoot; - extrasListPaths = uvListPaths; - extrasAttrPaths = pdmAttrPaths; - } - else - throw "Project is neither Poetry nor PEP-621"; -}) diff --git a/vendor/pyproject.nix/lib/pypa.nix b/vendor/pyproject.nix/lib/pypa.nix index 825fffeda..e468ed25a 100644 --- a/vendor/pyproject.nix/lib/pypa.nix +++ b/vendor/pyproject.nix/lib/pypa.nix @@ -37,15 +37,6 @@ let optionalString = s: if s != "" then s else null; - checkTagVersion = - sourceVersion: tagVersion: - tagVersion == null - || tagVersion == sourceVersion.major - || ( - hasPrefix sourceVersion.major tagVersion - && ((toInt (sourceVersion.major + sourceVersion.minor)) >= toInt tagVersion) - ); - in lib.fix (self: { /* @@ -227,7 +218,14 @@ lib.fix (self: { ) && # Check version - (checkTagVersion sourceVersion abiTag.version); + ( + abiTag.version == null + || abiTag.version == sourceVersion.major + || ( + hasPrefix sourceVersion.major abiTag.version + && ((toInt (sourceVersion.major + sourceVersion.minor)) == toInt abiTag.version) + ) + ); /* Check whether a platform tag is compatible with this python interpreter. @@ -328,7 +326,12 @@ lib.fix (self: { ) && # Check version - checkTagVersion sourceVersion pythonTag.version; + pythonTag.version == null + || pythonTag.version == sourceVersion.major + || ( + hasPrefix sourceVersion.major pythonTag.version + && ((toInt (sourceVersion.major + sourceVersion.minor)) >= toInt pythonTag.version) + ); /* Check whether wheel file name is compatible with this python interpreter. diff --git a/vendor/pyproject.nix/lib/renderers.nix b/vendor/pyproject.nix/lib/renderers.nix deleted file mode 100644 index 4ac77583a..000000000 --- a/vendor/pyproject.nix/lib/renderers.nix +++ /dev/null @@ -1,204 +0,0 @@ -{ - lib, - pep508, - pep440, - pep621, - ... -}: -let - inherit (builtins) - attrValues - length - attrNames - head - foldl' - ; - inherit (lib) - optionalAttrs - mapAttrs' - mapAttrs - filterAttrs - concatMap - ; - - # Group licenses by their SPDX IDs for easy lookup - licensesBySpdxId = mapAttrs' (_: license: { - name = license.spdxId; - value = license; - }) (filterAttrs (_: license: license ? spdxId) lib.licenses); - - getDependencies' = - pythonPackages: - concatMap ( - dep: - let - pkg = pythonPackages.${dep.name}; - in - [ pkg ] ++ concatMap (extra: pkg.optional-dependencies.${extra} or [ ]) dep.extras - ); - -in -{ - /* - Renders a project as an argument that can be passed to withPackages - - Evaluates PEP-508 environment markers to select correct dependencies for the platform but does not validate version constraints. - For validation see `lib.validators`. - - Type: withPackages :: AttrSet -> lambda - - Example: - # withPackages (lib.project.loadPyproject { ... }) - «lambda @ «string»:1:1» - */ - withPackages = - { - # Project metadata as returned by `lib.project.loadPyproject` - project, - # Python derivation - python, - # Python extras (optionals) to enable - extras ? [ ], - # Extra withPackages function - extraPackages ? _ps: [ ], - # PEP-508 environment - environ ? pep508.mkEnviron python, - }: - let - filteredDeps = pep621.filterDependenciesByEnviron environ extras project.dependencies; - getDependencies = getDependencies' python.pkgs; - in - ps: - let - buildSystems' = - if filteredDeps.build-systems != [ ] then - [ ] - else - [ - ps.setuptools - ps.wheel - ]; - in - getDependencies filteredDeps.dependencies - ++ attrValues (mapAttrs (_group: getDependencies) project.dependencies.extras) - ++ getDependencies filteredDeps.build-systems - ++ extraPackages ps - ++ buildSystems'; - - /* - Renders a project as an argument that can be passed to buildPythonPackage/buildPythonApplication. - - Evaluates PEP-508 environment markers to select correct dependencies for the platform but does not validate version constraints. - For validation see `lib.validators`. - - Type: buildPythonPackage :: AttrSet -> AttrSet - - Example: - # buildPythonPackage { project = lib.project.loadPyproject ...; python = pkgs.python3; } - { pname = "blinker"; version = "1.3.3.7"; dependencies = [ ]; } - */ - buildPythonPackage = - { - # Project metadata as returned by `lib.project.loadPyproject` - project, - # Python derivation - python, - # Python extras (markers) to enable. - extras ? [ ], - # Map a Python extras group name to a Nix attribute set like: - # { dev = "checkInputs"; } - # This is intended to be used with optionals such as test dependencies that you might - # want to remap to checkInputs. - extrasAttrMappings ? { }, - # Which package format to pass to buildPythonPackage - # If the format is "wheel" PEP-518 build-systems are excluded from the build. - format ? "pyproject", - # PEP-508 environment - environ ? pep508.mkEnviron python, - # - }: - let - filteredDeps = pep621.filterDependenciesByEnviron environ extras project.dependencies; - - pythonVersion = environ.python_full_version.value; - - pythonPackages = python.pkgs; - getDependencies = getDependencies' pythonPackages; - - inherit (project) pyproject; - - meta = - let - project' = project.pyproject.project; - urls = project'.urls or { }; - in - # Optional changelog - optionalAttrs (urls ? changelog) { inherit (urls) changelog; } - // - # Optional description - optionalAttrs (project' ? description) { inherit (project') description; } - // - # Optional license - optionalAttrs (project' ? license.text) ( - assert !(project'.license ? file); - { - # From PEP-621: - # "The text key has a string value which is the license of the project whose meaning is that of the License field from the core metadata. - # These keys are mutually exclusive, so a tool MUST raise an error if the metadata specifies both keys." - # Hence the assert above. - license = licensesBySpdxId.${project'.license.text} or project'.license.text; - } - ) - // - # Only set mainProgram if we only have one script, otherwise it's ambigious which one is main - ( - let - scriptNames = attrNames project'.scripts; - in - optionalAttrs (project' ? scripts && length scriptNames == 1) { mainProgram = head scriptNames; } - ); - - optional-dependencies = lib.mapAttrs (_group: getDependencies) project.dependencies.extras; - - in - foldl' - ( - attrs: group: - let - attr = extrasAttrMappings.${group} or "dependencies"; - in - if !extrasAttrMappings ? ${group} then - attrs - else - attrs // { ${attr} = attrs.${attr} or [ ] ++ getDependencies filteredDeps.extras.${group}; } - ) - ( - { - pyproject = format == "pyproject"; - dependencies = - getDependencies filteredDeps.dependencies - # map (dep: python.pkgs.${dep}) namedDeps.dependencies - ++ concatMap (group: optional-dependencies.${group} or [ ]) extras; - inherit optional-dependencies meta; - } - // optionalAttrs (format != "pyproject") { inherit format; } - // optionalAttrs (format != "wheel") { - build-system = - if filteredDeps.build-systems != [ ] then - getDependencies filteredDeps.build-systems - else - [ - pythonPackages.setuptools - pythonPackages.wheel - ]; - } - // optionalAttrs (pyproject.project ? name) { pname = pyproject.project.name; } - // optionalAttrs (project.projectRoot != null) { src = project.projectRoot; } - // optionalAttrs (pyproject.project ? version) { inherit (pyproject.project) version; } - // optionalAttrs (project.requires-python != null) { - disabled = - !lib.all (spec: pep440.comparators.${spec.op} pythonVersion spec.version) project.requires-python; - } - ) - (attrNames filteredDeps.extras); -} diff --git a/vendor/pyproject.nix/lib/validators.nix b/vendor/pyproject.nix/lib/validators.nix deleted file mode 100644 index 895f1d6eb..000000000 --- a/vendor/pyproject.nix/lib/validators.nix +++ /dev/null @@ -1,74 +0,0 @@ -{ - lib, - pep440, - pep508, - pep621, - pypa, - ... -}: -let - inherit (builtins) attrValues foldl' filter; - inherit (lib) concatLists; - -in -{ - /* - Validates the Python package set held by Python (`python.pkgs`) against the parsed project. - - Returns an attribute set where the name is the Python package derivation `pname` and the value is a list of the mismatching conditions. - - Type: validateVersionConstraints :: AttrSet -> AttrSet - - Example: - # validateVersionConstraints (lib.project.loadPyproject { ... }) - { - resolvelib = { - # conditions as returned by `lib.pep440.parseVersionCond` - conditions = [ { op = ">="; version = { dev = null; epoch = 0; local = null; post = null; pre = null; release = [ 1 0 1 ]; }; } ]; - # Version from Python package set - version = "0.5.5"; - }; - unearth = { - conditions = [ { op = ">="; version = { dev = null; epoch = 0; local = null; post = null; pre = null; release = [ 0 10 0 ]; }; } ]; - version = "0.9.1"; - }; - } - */ - validateVersionConstraints = - { - # Project metadata as returned by `lib.project.loadPyproject` - project, - # Python derivation - python, - # Python extras (optionals) to enable - extras ? [ ], - }: - let - environ = pep508.mkEnviron python; - filteredDeps = pep621.filterDependenciesByEnviron environ [ ] project.dependencies; - flatDeps = - filteredDeps.dependencies - ++ concatLists (attrValues filteredDeps.extras) - ++ filteredDeps.build-systems; - - in - foldl' ( - acc: dep: - let - pname = pypa.normalizePackageName dep.name; - pversion = python.pkgs.${pname}.version; - version = pep440.parseVersion python.pkgs.${pname}.version; - incompatible = filter (cond: !pep440.comparators.${cond.op} version cond.version) dep.conditions; - in - if incompatible == [ ] then - acc - else - acc - // { - ${pname} = { - version = pversion; - conditions = incompatible; - }; - } - ) { } flatDeps; -} diff --git a/vendor/update.py b/vendor/update.py index 1196cf513..790f7ed93 100755 --- a/vendor/update.py +++ b/vendor/update.py @@ -6,6 +6,16 @@ import os +# Skip parts of the tree which aren't used in poetry2nix +SKIP_FILES = [ + "renderers.nix", + "project.nix", + "pep723.nix", + "validators.nix", + "scripts.nix", +] + + if __name__ == "__main__": store_path = json.loads( subprocess.check_output( @@ -14,7 +24,7 @@ "--eval", "--json", "--expr", - 'builtins.fetchGit { url = "git@github.com:adisbladis/pyproject.nix.git"; }', + 'builtins.fetchGit { url = "git@github.com:nix-community/pyproject.nix.git"; }', ] ) ) @@ -31,8 +41,6 @@ # Copy lib/ for filename in os.listdir(f"{store_path}/lib"): - if filename.startswith("test") or not filename.endswith(".nix"): + if filename.startswith("test") or not filename.endswith(".nix") or filename in SKIP_FILES: continue shutil.copy(f"{store_path}/lib/{filename}", f"pyproject.nix/lib/{filename}") - - # shutil.copytree(f"{store_path}/fetchers", "pyproject.nix/fetchers")