Skip to content

Commit

Permalink
buildPython*: restructure expression
Browse files Browse the repository at this point in the history
Restructure the derivation to prepare for
- fixed-point arguments support
- overridePythonAttrs deprecation
  • Loading branch information
ShamrockLee committed Jan 22, 2025
1 parent 16f0cec commit b2644e7
Showing 1 changed file with 66 additions and 61 deletions.
127 changes: 66 additions & 61 deletions pkgs/development/interpreters/python/mk-python-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -205,75 +205,85 @@ in
...
}@attrs:

let
format' =
assert (pyproject != null) -> (format == null);
if pyproject != null then
if pyproject then "pyproject" else "other"
else if format != null then
format
else
"setuptools";

withDistOutput = withDistOutput' format';

validatePythonMatches =
let
throwMismatch =
attrName: drv:
let
myName = "'${namePrefix}${name}'";
theirName = "'${drv.name}'";
optionalLocation =
let
pos = unsafeGetAttrPos (if attrs ? "pname" then "pname" else "name") attrs;
in
optionalString (pos != null) " at ${pos.file}:${toString pos.line}:${toString pos.column}";
in
throw ''
Python version mismatch in ${myName}:
# This derivation transformation function must be independent to `attrs`
# for fixed-point arguments support in the future.
(
drv:
extendDerivation (
disabled
-> throw "${lib.removePrefix namePrefix drv.name} not supported for interpreter ${python.executable}"
) { } (toPythonModule drv)
)
(
stdenv.mkDerivation (
finalAttrs:
let
format' =
assert (pyproject != null) -> (format == null);
if pyproject != null then
if pyproject then "pyproject" else "other"
else if format != null then
format
else
"setuptools";

withDistOutput = withDistOutput' format';

validatePythonMatches =
let
throwMismatch =
attrName: drv:
let
myName = "'${namePrefix}${name}'";
theirName = "'${drv.name}'";
optionalLocation =
let
pos = unsafeGetAttrPos (if attrs ? "pname" then "pname" else "name") attrs;
in
optionalString (pos != null) " at ${pos.file}:${toString pos.line}:${toString pos.column}";
in
throw ''
Python version mismatch in ${myName}:
The Python derivation ${myName} depends on a Python derivation
named ${theirName}, but the two derivations use different versions
of Python:
The Python derivation ${myName} depends on a Python derivation
named ${theirName}, but the two derivations use different versions
of Python:
${leftPadName myName theirName} uses ${python}
${leftPadName theirName myName} uses ${toString drv.pythonModule}
${leftPadName myName theirName} uses ${python}
${leftPadName theirName myName} uses ${toString drv.pythonModule}
Possible solutions:
Possible solutions:
* If ${theirName} is a Python library, change the reference to ${theirName}
in the ${attrName} of ${myName} to use a ${theirName} built from the same
version of Python
* If ${theirName} is a Python library, change the reference to ${theirName}
in the ${attrName} of ${myName} to use a ${theirName} built from the same
version of Python
* If ${theirName} is used as a tool during the build, move the reference to
${theirName} in ${myName} from ${attrName} to nativeBuildInputs
* If ${theirName} is used as a tool during the build, move the reference to
${theirName} in ${myName} from ${attrName} to nativeBuildInputs
* If ${theirName} provides executables that are called at run time, pass its
bin path to makeWrapperArgs:
* If ${theirName} provides executables that are called at run time, pass its
bin path to makeWrapperArgs:
makeWrapperArgs = [ "--prefix PATH : ''${lib.makeBinPath [ ${getName drv} ] }" ];
makeWrapperArgs = [ "--prefix PATH : ''${lib.makeBinPath [ ${getName drv} ] }" ];
${optionalLocation}
'';
${optionalLocation}
'';

checkDrv =
attrName: drv:
if (isPythonModule drv) && (isMismatchedPython drv) then throwMismatch attrName drv else drv;
checkDrv =
attrName: drv:
if (isPythonModule drv) && (isMismatchedPython drv) then throwMismatch attrName drv else drv;

in
attrName: inputs: map (checkDrv attrName) inputs;
in
attrName: inputs: map (checkDrv attrName) inputs;

isBootstrapInstallPackage = isBootstrapInstallPackage' (attrs.pname or null);
isBootstrapInstallPackage = isBootstrapInstallPackage' (attrs.pname or null);

isBootstrapPackage = isBootstrapInstallPackage || isBootstrapPackage' (attrs.pname or null);
isBootstrapPackage = isBootstrapInstallPackage || isBootstrapPackage' (attrs.pname or null);

isSetuptoolsDependency = isSetuptoolsDependency' (attrs.pname or null);
isSetuptoolsDependency = isSetuptoolsDependency' (attrs.pname or null);

# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
self = toPythonModule (
stdenv.mkDerivation (
finalAttrs:
in
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
(cleanAttrs attrs)
// {

Expand Down Expand Up @@ -449,9 +459,4 @@ let
}
)
)
);

in
extendDerivation (
disabled -> throw "${name} not supported for interpreter ${python.executable}"
) { } self
)

0 comments on commit b2644e7

Please sign in to comment.