Skip to content

Commit

Permalink
Respect subdirectory from poetry.lock when fetching sources
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk committed Sep 21, 2023
1 parent 406a978 commit fe08c9f
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 46 deletions.
99 changes: 53 additions & 46 deletions mk-poetry-dep.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,54 +170,61 @@ pythonPackages.callPackage
# Interpreters should declare what wheel types they're compatible with (python type + ABI)
# Here we can then choose a file based on that info.
src =
if isGit then
(
builtins.fetchGit ({
inherit (source) url;
rev = source.resolved_reference or source.reference;
ref = sourceSpec.branch or (if sourceSpec ? tag then "refs/tags/${sourceSpec.tag}" else "HEAD");
} // (
lib.optionalAttrs
(((sourceSpec ? rev) || (sourceSpec ? branch) || (source ? resolved_reference) || (source ? reference))
&& (lib.versionAtLeast builtins.nixVersion "2.4"))
let
srcRoot =
if isGit then
(
builtins.fetchGit ({
inherit (source) url;
rev = source.resolved_reference or source.reference;
ref = sourceSpec.branch or (if sourceSpec ? tag then "refs/tags/${sourceSpec.tag}" else "HEAD");
} // (
lib.optionalAttrs
(((sourceSpec ? rev) || (sourceSpec ? branch) || (source ? resolved_reference) || (source ? reference))
&& (lib.versionAtLeast builtins.nixVersion "2.4"))
{
allRefs = true;
}) // (
lib.optionalAttrs (lib.versionAtLeast builtins.nixVersion "2.4") {
submodules = true;
})
)
)
else if isWheelUrl then
builtins.fetchurl
{
allRefs = true;
}) // (
lib.optionalAttrs (lib.versionAtLeast builtins.nixVersion "2.4") {
submodules = true;
})
)
)
else if isWheelUrl then
builtins.fetchurl
{
inherit (source) url;
sha256 = fileInfo.hash;
}
else if isUrl then
builtins.fetchTarball
{
inherit (source) url;
sha256 = fileInfo.hash;
}
else if isDirectory then
(poetryLib.cleanPythonSources { src = localDepPath; })
else if isFile then
localDepPath
else if isLegacy then
fetchFromLegacy
{
pname = name;
inherit python;
inherit (fileInfo) file hash;
inherit (source) url;
}
inherit (source) url;
sha256 = fileInfo.hash;
}
else if isUrl then
builtins.fetchTarball
{
inherit (source) url;
sha256 = fileInfo.hash;
}
else if isDirectory then
(poetryLib.cleanPythonSources { src = localDepPath; })
else if isFile then
localDepPath
else if isLegacy then
fetchFromLegacy
{
pname = name;
inherit python;
inherit (fileInfo) file hash;
inherit (source) url;
}
else
fetchFromPypi {
pname = name;
inherit (fileInfo) file hash kind;
inherit version;
};
in
if source ? subdirectory then
srcRoot + "/${source.subdirectory}"
else
fetchFromPypi {
pname = name;
inherit (fileInfo) file hash kind;
inherit version;
};
srcRoot;
}
)
{ }
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ in
rpds-py-no-wheel = callTest ./rpds-py-no-wheel { };
contourpy-wheel = callTest ./contourpy-wheel { };
contourpy-no-wheel = callTest ./contourpy-no-wheel { };
subdirectory = callTest ./subdirectory { };
} // lib.optionalAttrs (!stdenv.isDarwin) {
# pyqt5 = (callTest ./pyqt5 { });

Expand Down
14 changes: 14 additions & 0 deletions tests/subdirectory/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ lib, poetry2nix, postgresql_14, runCommandCC, stdenv }:

let env = poetry2nix.mkPoetryEnv { projectDir = ./.; };
in if stdenv.isDarwin then
env
else
runCommandCC "subdirectory-test"
{
PSYCOPG_IMPL = "python";
LD_LIBRARY_PATH = lib.makeLibraryPath [ postgresql_14 ];
} ''
'${env}/bin/python' -c 'import psycopg'
touch "$out"
''
58 changes: 58 additions & 0 deletions tests/subdirectory/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/subdirectory/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[tool.poetry]
name = "subdirectory-test"
version = "0.1.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = "^3.10"
psycopg = {git = "https://github.com/psycopg/psycopg.git", rev = "3.1.10", subdirectory = "psycopg"}

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0 comments on commit fe08c9f

Please sign in to comment.