Skip to content

Commit

Permalink
⚡ Make python nedryland 9.0.0 compatible
Browse files Browse the repository at this point in the history
With the new version of Nedryland, mkShell is no longer used, which
means that inputs are not resolved before the shell is created. Now we
need to place the checkHook first manually. And place it in
passthru.shellInputs.

TargetSetup has moved to shellInputs. This is because the target
setup is now a setup hook instead of something that the nedryland
shell does.
  • Loading branch information
simonrainerson authored and sakarias88 committed Nov 6, 2023
1 parent 860f9c6 commit cb8d367
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions python/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,41 @@ let
} else gitignoreSource args.src;

attrs = builtins.removeAttrs args [ "srcExclude" "shellInputs" "targetSetup" "docs" "docsConfig" ];
hookAndChecks = [ (checkHook src pythonPkgs) ]
++ (resolveInputs "checkInputs" attrs.checkInputs or [ ]);


# Aside from propagating dependencies, buildPythonPackage also injects
# code into and wraps executables with the paths included in this list.
# Items listed in install_requires go here
propagatedBuildInputs = resolveInputs "propagatedBuildInputs" attrs.propagatedBuildInputs or [ ];

targetSetup = if (args ? targetSetup && lib.isDerivation args.targetSetup) then args.targetSetup else
(base.mkTargetSetup {
name = args.targetSetup.name or args.name;
typeName = "python";
markerFiles = args.targetSetup.markerFiles or [ ] ++ [ "setup.py" "setup.cfg" "pyproject.toml" ];
templateDir = symlinkJoin {
name = "python-component-template";
paths = (
lib.optional (args ? targetSetup.templateDir) args.targetSetup.templateDir
) ++ [ ./component-template ];
};
variables = (rec {
inherit version;
pname = name;
mainPackage = lib.toLower (builtins.replaceStrings [ "-" " " ] [ "_" "_" ] name);
entryPoint = if setuptoolsLibrary then "{}" else "{\\\"console_scripts\\\": [\\\"${name}=${mainPackage}.main:main\\\"]}";
} // args.targetSetup.variables or { });
variableQueries = ({
desc = "✍️ Write a short description for your component:";
author = "🤓 Enter author name:";
email = "📧 Enter author email:";
url = "🏄 Enter author website url:";
} // args.targetSetup.variableQueries or { });
initCommands = "black .";
});

pythonPackageArgs = (attrs // {
inherit version format preBuild doStandardTests pythonVersion propagatedBuildInputs;
src = if lib.isStorePath src then src else filteredSrc;
Expand All @@ -60,12 +89,9 @@ let

# Dependencies needed for running the checkPhase. These are added to nativeBuildInputs when doCheck = true.
# Items listed in tests_require go here.
checkInputs = (
resolveInputs "checkInputs" attrs.checkInputs or [ ]
)
++ [ (checkHook src pythonPkgs) ]
++ (builtins.map (input: pythonPkgs."types-${input.pname or input.name}" or null) (builtins.filter lib.isDerivation propagatedBuildInputs))
++ (lib.optional (format == "setuptools") pythonPkgs.types-setuptools);
checkInputs = hookAndChecks
++ (builtins.map (input: pythonPkgs."types-${input.pname or input.name}" or null) (builtins.filter lib.isDerivation propagatedBuildInputs))
++ (lib.optional (format == "setuptools") pythonPkgs.types-setuptools);

# Build-time only dependencies. Typically executables as well
# as the items listed in setup_requires
Expand All @@ -76,39 +102,14 @@ let
buildInputs = resolveInputs "buildInputs" attrs.buildInputs or [ ];

passthru = {
shellInputs = (resolveInputs "shellInputs" args.shellInputs or [ ])
++ [ pythonPkgs.python-lsp-server pythonPkgs.pylsp-mypy pythonPkgs.pyls-isort ];
shellInputs = hookAndChecks
++ [ pythonPkgs.python-lsp-server pythonPkgs.pylsp-mypy pythonPkgs.pyls-isort targetSetup ]
++ args.shellInputs or [ ];
inherit pythonPackageArgs;
} // attrs.passthru or { };

dontUseSetuptoolsCheck = true;

targetSetup = if (args ? targetSetup && lib.isDerivation args.targetSetup) then args.targetSetup else
(base.mkTargetSetup {
name = args.targetSetup.name or args.name;
typeName = "python";
markerFiles = args.targetSetup.markerFiles or [ ] ++ [ "setup.py" "setup.cfg" "pyproject.toml" ];
templateDir = symlinkJoin {
name = "python-component-template";
paths = (
lib.optional (args ? targetSetup.templateDir) args.targetSetup.templateDir
) ++ [ ./component-template ];
};
variables = (rec {
inherit version;
pname = name;
mainPackage = lib.toLower (builtins.replaceStrings [ "-" " " ] [ "_" "_" ] name);
entryPoint = if setuptoolsLibrary then "{}" else "{\\\"console_scripts\\\": [\\\"${name}=${mainPackage}.main:main\\\"]}";
} // args.targetSetup.variables or { });
variableQueries = ({
desc = "✍️ Write a short description for your component:";
author = "🤓 Enter author name:";
email = "📧 Enter author email:";
url = "🏄 Enter author website url:";
} // args.targetSetup.variableQueries or { });
initCommands = "black .";
});

shellCommands = base.mkShellCommands name ({
check = {
script = ''eval ''${installCheckPhase:-echo "$name does not define an installCheckPhase"}'';
Expand Down

0 comments on commit cb8d367

Please sign in to comment.