Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect subdirectory from poetry.lock when fetching sources #1267

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"