Skip to content

Commit

Permalink
Merge pull request #1267 from andersk/subdirectory
Browse files Browse the repository at this point in the history
Respect `subdirectory` from `poetry.lock` when fetching sources
  • Loading branch information
adisbladis authored Oct 26, 2023
2 parents b005f34 + 65ab8f0 commit 1ef8d81
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 @@ -178,54 +178,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 @@ -141,6 +141,7 @@ in
contourpy-no-wheel = callTest ./contourpy-no-wheel { };
pytesseract = callTest ./pytesseract { };
sphinx5 = callTest ./sphinx5 { };
subdirectory = callTest ./subdirectory { };
} // lib.optionalAttrs (!stdenv.isDarwin) {
# Test deadlocks on darwin, sandboxing issue?
dependency-environment = callTest ./dependency-environment { };
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 1ef8d81

Please sign in to comment.