python3Packages.mkPythonEditablePackage: init

This commit is contained in:
adisbladis
2024-09-08 17:13:21 +12:00
parent 4f673395c7
commit de1fdc9fe0
4 changed files with 184 additions and 2 deletions
+38 -1
View File
@@ -122,6 +122,43 @@ let
}
);
# Test editable package support
editableTests = let
testPython = python.override {
self = testPython;
packageOverrides = pyfinal: pyprev: {
# An editable package with a script that loads our mutable location
my-editable = pyfinal.mkPythonEditablePackage {
pname = "my-editable";
version = "0.1.0";
root = "$NIX_BUILD_TOP/src"; # Use environment variable expansion at runtime
# Inject a script
scripts = {
my-script = "my_editable.main:main";
};
};
};
};
in {
editable-script = runCommand "editable-test" {
nativeBuildInputs = [ (testPython.withPackages (ps: [ ps.my-editable ])) ];
} ''
mkdir -p src/my_editable
cat > src/my_editable/main.py << EOF
def main():
print("hello mutable")
EOF
test "$(my-script)" == "hello mutable"
test "$(python -c 'import sys; print(sys.path[1])')" == "$NIX_BUILD_TOP/src"
touch $out
'';
};
# Tests to ensure overriding works as expected.
overrideTests = let
extension = self: super: {
@@ -192,4 +229,4 @@ let
'';
};
in lib.optionalAttrs (stdenv.hostPlatform == stdenv.buildPlatform ) (environmentTests // integrationTests // overrideTests // condaTests)
in lib.optionalAttrs (stdenv.hostPlatform == stdenv.buildPlatform ) (environmentTests // integrationTests // overrideTests // condaTests // editableTests)