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

View file

@ -1,6 +1,7 @@
{ lib { lib
, scripts , scripts
, python , python
, projectDir ? null
}: }:
let let
mkScript = bin: entrypoint: mkScript = bin: entrypoint:
@ -15,6 +16,11 @@ let
import sys import sys
import re 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 # Insert "" to add CWD to import path
sys.path.insert(0, "") sys.path.insert(0, "")