From 4d9bee6f81cd17a4f37971d8b09efdfc649b7bb0 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Mon, 24 Feb 2020 12:23:09 +0000 Subject: [PATCH] Refactor mkPoetryPython (mkPoetryPackages) - Renamed mkPoetryPython to mkPoetryPackages as it's more descriptive We intend to expose this function soon so a better name is in order. - Put TOML parsing inside mkPoetryPackages to unify parsing and avoid double parsing. --- default.nix | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/default.nix b/default.nix index 20e1546..f4fe5ad 100644 --- a/default.nix +++ b/default.nix @@ -25,11 +25,11 @@ let # Get license by id falling back to input string getLicenseBySpdxId = spdxId: spdxLicenses.${spdxId} or spdxId; - # - # Returns an attrset { python, poetryPackages } for the given lockfile - # - mkPoetryPython = - { pyProject + /* + Returns an attrset { python, poetryPackages, pyProject, poetryLock } for the given pyproject/lockfile. + */ + mkPoetryPackages = + { pyproject , poetrylock , poetryPkg , overrides ? [ defaultPoetryOverrides ] @@ -37,8 +37,9 @@ let , python ? pkgs.python3 , pwd ? null }@attrs: let - lockData = readTOML poetrylock; - lockFiles = lib.getAttrFromPath [ "metadata" "files" ] lockData; + pyProject = readTOML pyproject; + poetryLock = readTOML poetrylock; + lockFiles = lib.getAttrFromPath [ "metadata" "files" ] poetryLock; specialAttrs = [ "overrides" @@ -60,7 +61,7 @@ let in pyprojectResult && pep508Result; in - lib.partition supportsPythonVersion lockData.package; + lib.partition supportsPythonVersion poetryLock.package; compatible = partitions.right; incompatible = partitions.wrong; @@ -122,6 +123,8 @@ let { python = py; poetryPackages = map (pkg: py.pkgs.${pkg.name}) compatible; + poetryLock = poetryLock; + inherit pyProject; }; /* Returns a package with a python interpreter and all packages specified in the poetry.lock lock file. @@ -139,10 +142,9 @@ let }: let poetryPkg = poetry.override { inherit python; }; - py = mkPoetryPython ( + py = mkPoetryPackages ( { - inherit poetryPkg poetrylock overrides meta python pwd; - pyProject = readTOML pyproject; + inherit poetryPkg pyproject poetrylock overrides meta python pwd; } ); in @@ -161,13 +163,12 @@ let }@attrs: let poetryPkg = poetry.override { inherit python; }; - pyProject = readTOML pyproject; + poetryPython = mkPoetryPackages { + inherit poetryPkg pyproject poetrylock overrides meta python pwd; + }; + py = poetryPython.python; - py = ( - mkPoetryPython { - inherit poetryPkg pyProject poetrylock overrides meta python pwd; - } - ).python; + inherit (poetryPython) pyProject; specialAttrs = [ "overrides"