From 94ef93f0397cddcac442fe866132361a422fc433 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Fri, 1 Oct 2021 18:07:42 -0500 Subject: [PATCH] Add projectDir to import path for scripts packages This ensures that packages retain their editable property despite not being in the current working directory. --- default.nix | 6 +++--- shell-scripts.nix | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/default.nix b/default.nix index dae0a02..cc6e241 100644 --- a/default.nix +++ b/default.nix @@ -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; diff --git a/shell-scripts.nix b/shell-scripts.nix index cbaa443..0196ce0 100644 --- a/shell-scripts.nix +++ b/shell-scripts.nix @@ -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, "")