Add projectDir to import path for scripts packages

This ensures that packages retain their editable property despite not
being in the current working directory.
This commit is contained in:
adisbladis 2021-10-01 18:07:42 -05:00
parent aee8f04296
commit 94ef93f039
No known key found for this signature in database
GPG key ID: 110BFAD44C6249B7
2 changed files with 9 additions and 3 deletions

View file

@ -105,7 +105,7 @@ lib.makeScope pkgs.newScope (self: {
}:
assert scripts != { };
import ./shell-scripts.nix {
inherit lib python scripts;
inherit lib python scripts projectDir;
};
/*
@ -130,7 +130,7 @@ lib.makeScope pkgs.newScope (self: {
scripts = pyProject.tool.poetry.scripts or { };
hasScripts = scripts != { };
scriptsPackage = self.mkPoetryScriptsPackage {
inherit python scripts;
inherit python scripts projectDir;
};
hasEditable = editablePackageSources != { };
@ -264,7 +264,7 @@ lib.makeScope pkgs.newScope (self: {
}:
let
poetryPython = self.mkPoetryPackages {
inherit pyproject poetrylock overrides python pwd preferWheels editablePackageSources;
inherit projectDir pyproject poetrylock overrides python pwd preferWheels editablePackageSources;
};
inherit (poetryPython) poetryPackages;

View file

@ -1,6 +1,7 @@
{ lib
, scripts
, python
, projectDir ? null
}:
let
mkScript = bin: entrypoint:
@ -15,6 +16,11 @@ let
import sys
import re
${lib.optionalString (projectDir != null) ''
# Add projectDir to load path
sys.path.insert(0, "${builtins.toString projectDir}")
''}
# Insert "" to add CWD to import path
sys.path.insert(0, "")