split mkPoetryPackage into mkPoetryPython and mkPoetryApplication

This commit is contained in:
Andreas Rammhold 2019-12-16 11:23:09 +01:00
parent 84f27ee31d
commit d8fde74219
No known key found for this signature in database
GPG key ID: E432E410B5E48C86
7 changed files with 38 additions and 20 deletions

View file

@ -21,25 +21,22 @@ let
);
mkPoetryPackage =
mkPoetryPython =
{ src
, pyproject ? src + "/pyproject.toml"
, poetrylock ? src + "/poetry.lock"
, overrides ? defaultPoetryOverrides
, meta ? {}
, python ? pkgs.python3
, ...
}@attrs: let
pyProject = readTOML pyproject;
poetryLock = readTOML poetrylock;
lockFiles = lib.getAttrFromPath [ "metadata" "files" ] poetryLock;
specialAttrs = [ "pyproject" "poetrylock" "overrides" ];
specialAttrs = [ "poetrylock" "overrides" ];
passedAttrs = builtins.removeAttrs attrs specialAttrs;
evalPep508 = mkEvalPep508 python;
poetryPkg = poetry.override { inherit python; };
# Create an overriden version of pythonPackages
#
@ -81,13 +78,36 @@ let
} // nulledPkgs // lockPkgs;
in
python.override { inherit packageOverrides; self = py; };
pythonPackages = py.pkgs;
in
py;
mkPoetryApplication =
{ src
, pyproject ? src + "/pyproject.toml"
, poetrylock ? src + "/poetry.lock"
, overrides ? defaultPoetryOverrides
, meta ? {}
, python ? pkgs.python3
, ...
}@attrs: let
poetryPkg = poetry.override { inherit python; };
py = mkPoetryPython (
{
inherit src pyproject poetrylock overrides meta python;
} // attrs
);
pyProject = readTOML pyproject;
specialAttrs = [ "pyproject" "poetrylock" "overrides" ];
passedAttrs = builtins.removeAttrs attrs specialAttrs;
getDeps = depAttr: let
deps = getAttrDefault depAttr pyProject.tool.poetry {};
depAttrs = builtins.map (d: lib.toLower d) (builtins.attrNames deps);
in
builtins.map (dep: pythonPackages."${dep}") depAttrs;
builtins.map (dep: py.pkgs."${dep}") depAttrs;
getInputs = attr: getAttrDefault attr attrs [];
mkInput = attr: extraInputs: getInputs attr ++ extraInputs;
@ -103,7 +123,7 @@ let
in
knownBuildSystems.${buildSystem} or (throw "unsupported build system ${buildSystem}");
in
pythonPackages.buildPythonApplication (
py.pkgs.buildPythonApplication (
passedAttrs // {
pname = pyProject.tool.poetry.name;
version = pyProject.tool.poetry.version;
@ -111,11 +131,10 @@ let
format = "pyproject";
buildInputs = mkInput "buildInputs" getBuildSystemPkgs;
propagatedBuildInputs = mkInput "propagatedBuildInputs" (getDeps "dependencies") ++ ([ pythonPackages.setuptools ]);
propagatedBuildInputs = mkInput "propagatedBuildInputs" (getDeps "dependencies") ++ ([ py.pkgs.setuptools ]);
checkInputs = mkInput "checkInputs" (getDeps "dev-dependencies");
passthru = {
inherit pythonPackages;
python = py;
};
@ -126,8 +145,8 @@ let
}
);
in
{
inherit mkPoetryPackage defaultPoetryOverrides;
inherit mkPoetryPython mkPoetryApplication defaultPoetryOverrides;
mkPoetryPackage = attrs: builtins.trace "mkPoetryPackage is deprecated. Use mkPoetryApplication instead." (mkPoetryApplication attrs);
}

View file

@ -1,6 +1,6 @@
{ lib, poetry2nix, python, fetchFromGitHub, runtimeShell }:
poetry2nix.mkPoetryPackage {
poetry2nix.mkPoetryApplication {
inherit python;

View file

@ -1,6 +1,6 @@
{ lib, poetry2nix, python3 }:
poetry2nix.mkPoetryPackage {
poetry2nix.mkPoetryApplication {
python = python3;
pyproject = ./pyproject.toml;
poetryLock = ./poetry.lock;

View file

@ -1,6 +1,6 @@
{ lib, poetry2nix, python3 }:
poetry2nix.mkPoetryPackage {
poetry2nix.mkPoetryApplication {
python = python3;
pyproject = ./pyproject.toml;
poetryLock = ./poetry.lock;

View file

@ -1,7 +1,7 @@
{ runCommand, lib, poetry2nix, python3 }:
let
pkg = poetry2nix.mkPoetryPackage {
pkg = poetry2nix.mkPoetryApplication {
python = python3;
pyproject = ./pyproject.toml;
poetryLock = ./poetry.lock;

View file

@ -1,9 +1,8 @@
{ lib, python3, poetry2nix, runCommand }:
let
pyApp = poetry2nix.mkPoetryPackage {
python = poetry2nix.mkPoetryPython {
python = python3;
pyproject = ./pyproject.toml;
poetryLock = ./poetry.lock;
src = lib.cleanSource ./.;
overrides = poetry2nix.defaultPoetryOverrides // {
@ -16,7 +15,7 @@ let
};
in
runCommand "test" {} ''
x=${builtins.toString (pyApp.pythonPackages.alembic.TESTING_FOOBAR)}
x=${builtins.toString (python.pkgs.alembic.TESTING_FOOBAR)}
[ "$x" = "42" ] || exit 1
mkdir $out
''

View file

@ -1,6 +1,6 @@
{ lib, poetry2nix, python3 }:
poetry2nix.mkPoetryPackage {
poetry2nix.mkPoetryApplication {
python = python3;
pyproject = ./pyproject.toml;
poetryLock = ./poetry.lock;