From fa190fd6aa5d9060342b5c5d1527036a38af184e Mon Sep 17 00:00:00 2001 From: Sigmanificient Date: Tue, 13 Jan 2026 00:19:17 +0100 Subject: [PATCH] doc/python: use finalAttrs in examples --- doc/languages-frameworks/python.section.md | 59 +++++++++++----------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index d367775d60c2..f7a0ba9e4ba9 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -99,13 +99,14 @@ The following is an example: hypothesis, }: -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "pytest"; version = "3.3.1"; pyproject = true; src = fetchPypi { - inherit pname version; + inherit (finalAttrs) pname version; + hash = "sha256-z4Q23FnYaVNG/NOrKW3kZCXsqwDWQJbOvnn7Ueyy65M="; }; @@ -130,7 +131,7 @@ buildPythonPackage rec { nativeCheckInputs = [ hypothesis ]; meta = { - changelog = "https://github.com/pytest-dev/pytest/releases/tag/${version}"; + changelog = "https://github.com/pytest-dev/pytest/releases/tag/${finalAttrs.version}"; description = "Framework for writing tests"; homepage = "https://github.com/pytest-dev/pytest"; license = lib.licenses.mit; @@ -140,7 +141,7 @@ buildPythonPackage rec { lsix ]; }; -} +}) ``` The `buildPythonPackage` mainly does four things: @@ -304,13 +305,13 @@ specifying an interpreter version), like this: fetchPypi, }: -python3Packages.buildPythonApplication rec { +python3Packages.buildPythonApplication (finalAttrs: { pname = "luigi"; version = "2.7.9"; pyproject = true; src = fetchPypi { - inherit pname version; + inherit (finalAttrs) pname version; hash = "sha256-Pe229rT0aHwA98s+nTHQMEFKZPo/yw6sot8MivFDvAw="; }; @@ -324,7 +325,7 @@ python3Packages.buildPythonApplication rec { meta = { # ... }; -} +}) ``` This is then added to `pkgs/by-name` just as any other application would be. @@ -928,13 +929,13 @@ building Python libraries is [`buildPythonPackage`](#buildpythonpackage-function setuptools, }: -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "toolz"; version = "0.10.0"; pyproject = true; src = fetchPypi { - inherit pname version; + inherit (finalAttrs) pname version; hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; }; @@ -950,12 +951,12 @@ buildPythonPackage rec { ]; meta = { - changelog = "https://github.com/pytoolz/toolz/releases/tag/${version}"; + changelog = "https://github.com/pytoolz/toolz/releases/tag/${finalAttrs.version}"; homepage = "https://github.com/pytoolz/toolz"; description = "List processing tools and functional utilities"; license = lib.licenses.bsd3; }; -} +}) ``` What happens here? The function [`buildPythonPackage`](#buildpythonpackage-function) is called and as argument @@ -985,13 +986,13 @@ with import { }; ( let - my_toolz = python313.pkgs.buildPythonPackage rec { + my_toolz = python313.pkgs.buildPythonPackage (finalAttrs: { pname = "toolz"; version = "0.10.0"; pyproject = true; src = fetchPypi { - inherit pname version; + inherit (finalAttrs) pname version; hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; }; @@ -1005,7 +1006,7 @@ with import { }; description = "List processing tools and functional utilities"; # [...] }; - }; + }); in python313.withPackages ( @@ -1062,13 +1063,13 @@ order to build [`datashape`](https://github.com/blaze/datashape). pytestCheckHook, }: -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "datashape"; version = "0.4.7"; pyproject = true; src = fetchPypi { - inherit pname version; + inherit (finalAttrs) pname version; hash = "sha256-FLLvdm1MllKrgTGC6Gb0k0deZeVYvtCCLji/B7uhong="; }; @@ -1083,12 +1084,12 @@ buildPythonPackage rec { nativeCheckInputs = [ pytestCheckHook ]; meta = { - changelog = "https://github.com/blaze/datashape/releases/tag/${version}"; + changelog = "https://github.com/blaze/datashape/releases/tag/${finalAttrs.version}"; homepage = "https://github.com/ContinuumIO/datashape"; description = "Data description language"; license = lib.licenses.bsd2; }; -} +}) ``` We can see several runtime dependencies, `numpy`, `multipledispatch`, and @@ -1111,13 +1112,13 @@ when building the bindings and are therefore added as [`buildInputs`](#var-stden libxslt, }: -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "lxml"; version = "3.4.4"; pyproject = true; src = fetchPypi { - inherit pname version; + inherit (finalAttrs) pname version; hash = "sha256-s9NiusRxFydHzaNRMjjxFcvWxfi45jGb9ql6eJJyQJk="; }; @@ -1137,13 +1138,13 @@ buildPythonPackage rec { ]; meta = { - changelog = "https://github.com/lxml/lxml/releases/tag/lxml-${version}"; + changelog = "https://github.com/lxml/lxml/releases/tag/lxml-${finalAttrs.version}"; description = "Pythonic binding for the libxml2 and libxslt libraries"; homepage = "https://lxml.de"; license = lib.licenses.bsd3; maintainers = with lib.maintainers; [ sjourdois ]; }; -} +}) ``` In this example `lxml` and Nix are able to work out exactly where the relevant @@ -1173,13 +1174,13 @@ therefore we have to set `LDFLAGS` and `CFLAGS`. scipy, }: -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "pyfftw"; version = "0.9.2"; pyproject = true; src = fetchPypi { - inherit pname version; + inherit (finalAttrs) pname version; hash = "sha256-9ru2r6kwhUCaskiFoaPNuJCfCVoUL01J40byvRt4kHQ="; }; @@ -1207,7 +1208,7 @@ buildPythonPackage rec { pythonImportsCheck = [ "pyfftw" ]; meta = { - changelog = "https://github.com/pyFFTW/pyFFTW/releases/tag/v${version}"; + changelog = "https://github.com/pyFFTW/pyFFTW/releases/tag/v${finalAttrs.version}"; description = "Pythonic wrapper around FFTW, the FFT library, presenting a unified interface for all the supported transforms"; homepage = "http://hgomersall.github.com/pyFFTW"; license = with lib.licenses; [ @@ -1215,7 +1216,7 @@ buildPythonPackage rec { bsd3 ]; }; -} +}) ``` Note also the line [`doCheck = false;`](#var-stdenv-doCheck), we explicitly disabled running the test-suite. @@ -1609,13 +1610,13 @@ We first create a function that builds `toolz` in `~/path/to/toolz/release.nix` setuptools, }: -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "toolz"; version = "0.10.0"; pyproject = true; src = fetchPypi { - inherit pname version; + inherit (finalAttrs) pname version; hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; }; @@ -1627,7 +1628,7 @@ buildPythonPackage rec { description = "List processing tools and functional utilities"; license = lib.licenses.bsd3; }; -} +}) ``` It takes an argument [`buildPythonPackage`](#buildpythonpackage-function). We now call this function using