From fbcf2aed41b1dfdaabcb161de3600b0378303426 Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 26 Jun 2024 23:37:27 +0000 Subject: [PATCH] python packages: port away from buildPythonPackage -> stdenv.mkDerivation in a future refactoring, maybe i can remove them from the special 'pkgs/python-packages' directory altogether --- pkgs/default.nix | 4 +- pkgs/python-packages/default.nix | 20 +++--- .../depthcharge-tools/default.nix | 22 ++++-- pkgs/python-packages/fastcluster/default.nix | 25 ++++--- .../feedsearch-crawler/default.nix | 44 ++++++------ pkgs/python-packages/listparser/default.nix | 72 +++++++++---------- pkgs/python-packages/ols/default.nix | 29 ++++---- pkgs/python-packages/pa-dlna/default.nix | 25 ++++--- pkgs/python-packages/pyln-bolt7/default.nix | 32 ++++++--- pkgs/python-packages/pyln-client/default.nix | 27 +++++-- pkgs/python-packages/pyln-proto/default.nix | 34 +++++---- templates/pkgs/python/default.nix | 42 +++++++---- 12 files changed, 224 insertions(+), 152 deletions(-) diff --git a/pkgs/default.nix b/pkgs/default.nix index 2af0dcbb..51a2e8ce 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -10,8 +10,8 @@ let lib = pkgs.lib; unpatched = pkgs; - pythonPackagesOverlayFor = pkgs: py-final: py-prev: import ./python-packages { - inherit (py-final) callPackage; + pythonPackagesOverlayFor = pkgs: pyFinal: _pyPrev: import ./python-packages { + inherit (pyFinal) callPackage toPythonModule; inherit pkgs; }; final' = if final != null then final else pkgs.extend (_: _: sane-overlay); diff --git a/pkgs/python-packages/default.nix b/pkgs/python-packages/default.nix index b44e0f4a..46eab7b6 100644 --- a/pkgs/python-packages/default.nix +++ b/pkgs/python-packages/default.nix @@ -1,13 +1,13 @@ -{ callPackage, pkgs }: +{ callPackage, pkgs, toPythonModule }: { - depthcharge-tools = callPackage ./depthcharge-tools { }; - feedsearch-crawler = callPackage ./feedsearch-crawler { }; - fastcluster = callPackage ./fastcluster { }; - listparser = callPackage ./listparser { }; - ols = callPackage ./ols { }; - pa-dlna = callPackage ./pa-dlna { }; - pyln-bolt7 = callPackage ./pyln-bolt7 { }; - pyln-client = callPackage ./pyln-client { }; - pyln-proto = callPackage ./pyln-proto { }; + depthcharge-tools = toPythonModule (callPackage ./depthcharge-tools { }); + feedsearch-crawler = toPythonModule (callPackage ./feedsearch-crawler { }); + fastcluster = toPythonModule (callPackage ./fastcluster { }); + listparser = toPythonModule (callPackage ./listparser { }); + ols = toPythonModule (callPackage ./ols { }); + pa-dlna = toPythonModule (callPackage ./pa-dlna { }); + pyln-bolt7 = toPythonModule (callPackage ./pyln-bolt7 { }); + pyln-client = toPythonModule (callPackage ./pyln-client { }); + pyln-proto = toPythonModule (callPackage ./pyln-proto { }); sane-lib = pkgs.sane-scripts.lib; } diff --git a/pkgs/python-packages/depthcharge-tools/default.nix b/pkgs/python-packages/depthcharge-tools/default.nix index 49202175..240960f1 100644 --- a/pkgs/python-packages/depthcharge-tools/default.nix +++ b/pkgs/python-packages/depthcharge-tools/default.nix @@ -1,8 +1,11 @@ -{ lib -, buildPythonPackage -, fetchFromGitHub -, setuptools -}: buildPythonPackage rec { +{ + lib, + fetchFromGitHub, + pypaBuildHook, + pypaInstallHook, + setuptools, + stdenv +}: stdenv.mkDerivation (finalAttrs: { pname = "depthcharge-tools"; version = "0.6.2"; format = "setuptools"; @@ -10,10 +13,15 @@ src = fetchFromGitHub { owner = "alpernebbi"; repo = "depthcharge-tools"; - rev = "v${version}"; + rev = "v${finalAttrs.version}"; hash = "sha256-3xPRNDUXLOwYy8quMfYSiBfzQl4peauTloqtZBGbvlw="; }; + nativeBuildInputs = [ + pypaBuildHook + pypaInstallHook + ]; + propagatedBuildInputs = [ setuptools #< needs `pkg_resources` at runtime ]; @@ -27,4 +35,4 @@ description = "Tools to manage the Chrome OS bootloader"; maintainers = with maintainers; [ colinsane ]; }; -} +}) diff --git a/pkgs/python-packages/fastcluster/default.nix b/pkgs/python-packages/fastcluster/default.nix index 4bceb8ba..3b879c67 100644 --- a/pkgs/python-packages/fastcluster/default.nix +++ b/pkgs/python-packages/fastcluster/default.nix @@ -1,24 +1,27 @@ -{ lib -, buildPythonPackage -, fetchFromGitHub -, oldest-supported-numpy -, numpy -, setuptools -}: buildPythonPackage rec { +{ + lib, + fetchFromGitHub, + oldest-supported-numpy, + numpy, + pypaBuildHook, + pypaInstallHook, + setuptools, + stdenv, +}: stdenv.mkDerivation (finalAttrs: { pname = "fastcluster"; version = "1.2.6"; - format = "pyproject"; - # format = "setuptools"; src = fetchFromGitHub { owner = "fastcluster"; repo = "fastcluster"; - rev = "v${version}"; + rev = "v${finalAttrs.version}"; hash = "sha256-8FDipkAcOAI5zAC7JaJExe6HO1xHg+eXAL7IUIVrA3k="; }; nativeBuildInputs = [ oldest-supported-numpy + pypaBuildHook + pypaInstallHook setuptools ]; @@ -35,4 +38,4 @@ description = "fast hierarchical clustering routines for R and Python"; maintainers = with maintainers; [ colinsane ]; }; -} +}) diff --git a/pkgs/python-packages/feedsearch-crawler/default.nix b/pkgs/python-packages/feedsearch-crawler/default.nix index 4d706b4c..94c63cc9 100644 --- a/pkgs/python-packages/feedsearch-crawler/default.nix +++ b/pkgs/python-packages/feedsearch-crawler/default.nix @@ -1,22 +1,24 @@ -{ lib -, buildPythonPackage -, fetchFromGitHub +{ + lib, + fetchFromGitHub, + pypaBuildHook, + pypaInstallHook, + stdenv, # nativeBuildInputs python packages -, poetry-core + poetry-core, # propagatedBuildInputs python packages -, aiodns -, aiohttp -, beautifulsoup4 -, brotlipy -, cchardet -, feedparser -, python-dateutil -, uvloop -, w3lib -, yarl + aiodns, + aiohttp, + beautifulsoup4, + brotlipy, + cchardet, + feedparser, + python-dateutil, + uvloop, + w3lib, + yarl, }: - -buildPythonPackage rec { +stdenv.mkDerivation { pname = "feedsearch-crawler"; version = "2022-05-28"; format = "pyproject"; @@ -34,10 +36,6 @@ buildPythonPackage rec { ./0001-response-chunk-size.patch ]; - nativeBuildInputs = [ - poetry-core - ]; - postPatch = '' substituteInPlace pyproject.toml \ --replace-fail 'w3lib = "^1.22.0"' 'w3lib = "*"' \ @@ -45,6 +43,12 @@ buildPythonPackage rec { --replace-fail 'uvloop = "^0.15.2"' 'uvloop = "*"' ''; + nativeBuildInputs = [ + poetry-core + pypaBuildHook + pypaInstallHook + ]; + propagatedBuildInputs = [ aiodns aiohttp diff --git a/pkgs/python-packages/listparser/default.nix b/pkgs/python-packages/listparser/default.nix index 2f5a4d96..55f361f4 100644 --- a/pkgs/python-packages/listparser/default.nix +++ b/pkgs/python-packages/listparser/default.nix @@ -9,50 +9,46 @@ pytestCheckHook, requests, stdenv, - toPythonModule, }: +stdenv.mkDerivation (finalAttrs: { + pname = "listparser"; + version = "0.20"; -toPythonModule ( - stdenv.mkDerivation (finalAttrs: { - pname = "listparser"; - version = "0.20"; + src = fetchFromGitHub { + owner = "kurtmckee"; + repo = "listparser"; + rev = "v${finalAttrs.version}"; + hash = "sha256-eg9TrjDgvHsYt/0JQ7MK/uGc3KK3uGr3jRxzG0FlySg="; + }; - src = fetchFromGitHub { - owner = "kurtmckee"; - repo = "listparser"; - rev = "v${finalAttrs.version}"; - hash = "sha256-eg9TrjDgvHsYt/0JQ7MK/uGc3KK3uGr3jRxzG0FlySg="; - }; + nativeBuildInputs = [ + poetry-core + pypaBuildHook + pypaInstallHook + ]; - nativeBuildInputs = [ - poetry-core - pypaBuildHook - pypaInstallHook - ]; + propagatedBuildInputs = [ + requests + lxml + ]; - propagatedBuildInputs = [ - requests - lxml - ]; + nativeCheckInputs = [ + pytestCheckHook + ]; - nativeCheckInputs = [ - pytestCheckHook - ]; + pythonImportsCheck = [ + "listparser" + ]; - pythonImportsCheck = [ - "listparser" - ]; + doCheck = true; - doCheck = true; + passthru.updateScript = nix-update-script { }; - passthru.updateScript = nix-update-script { }; - - meta = with lib; { - description = "Parse OPML subscription lists in Python"; - homepage = "https://github.com/kurtmckee/listparser"; - license = licenses.lgpl3Plus; - maintainers = [ maintainers.colinsane ]; - platforms = platforms.linux; - }; - }) -) + meta = with lib; { + description = "Parse OPML subscription lists in Python"; + homepage = "https://github.com/kurtmckee/listparser"; + license = licenses.lgpl3Plus; + maintainers = [ maintainers.colinsane ]; + platforms = platforms.linux; + }; +}) diff --git a/pkgs/python-packages/ols/default.nix b/pkgs/python-packages/ols/default.nix index 63c85bd1..506618b7 100644 --- a/pkgs/python-packages/ols/default.nix +++ b/pkgs/python-packages/ols/default.nix @@ -1,19 +1,22 @@ -{ lib -, buildPythonPackage -, fetchFromGitea -, aiohttp -, fastcluster -, fastjsonschema -, mercantile -, numpy -, scipy -, setuptools +{ + lib, + buildPythonPackage, + fetchFromGitea, + aiohttp, + fastcluster, + fastjsonschema, + mercantile, + numpy, + pypaBuildHook, + pypaInstallHook, + scipy, + setuptools, + stdenv, # , wheel -}: buildPythonPackage { +}: stdenv.mkDerivation { pname = "ols"; version = "0.1.0-unstable-2024-06-21"; format = "pyproject"; - # format = "setuptools"; src = fetchFromGitea { # my dev branch has a few changes: @@ -44,6 +47,8 @@ ]; nativeBuildInputs = [ + pypaBuildHook + pypaInstallHook setuptools # wheel ]; diff --git a/pkgs/python-packages/pa-dlna/default.nix b/pkgs/python-packages/pa-dlna/default.nix index ddd5caac..b7b42448 100644 --- a/pkgs/python-packages/pa-dlna/default.nix +++ b/pkgs/python-packages/pa-dlna/default.nix @@ -1,13 +1,16 @@ -{ lib -, buildPythonPackage -, fetchFromGitLab -, flit-core -, libpulseaudio -, psutil -, pulseaudio +{ + lib, + fetchFromGitLab, + flit-core, + libpulseaudio, + pypaBuildHook, + pypaInstallHook, + psutil, + pulseaudio, + stdenv, }: -buildPythonPackage rec { +stdenv.mkDerivation (finalAttrs: { pname = "pa-dlna"; version = "0.7"; format = "pyproject"; @@ -15,7 +18,7 @@ buildPythonPackage rec { src = fetchFromGitLab { owner = "xdegaye"; repo = "pa-dlna"; - rev = "v${version}"; + rev = "v${finalAttrs.version}"; hash = "sha256-tc3AjxTMeLH82d8R95xsqLeAH1t/orW7c9DGjBwDWaU="; }; @@ -27,6 +30,8 @@ buildPythonPackage rec { nativeBuildInputs = [ flit-core + pypaBuildHook + pypaInstallHook ]; propagatedBuildInputs = [ @@ -48,4 +53,4 @@ buildPythonPackage rec { license = licenses.mit; maintainers = with maintainers; [ colinsane ]; }; -} +}) diff --git a/pkgs/python-packages/pyln-bolt7/default.nix b/pkgs/python-packages/pyln-bolt7/default.nix index c9ab6295..49f00a13 100644 --- a/pkgs/python-packages/pyln-bolt7/default.nix +++ b/pkgs/python-packages/pyln-bolt7/default.nix @@ -1,7 +1,16 @@ # based on: -{ buildPythonPackage, poetry-core, pytestCheckHook, clightning, pyln-proto }: - -buildPythonPackage { +{ + buildPythonPackage, + clightning, + poetry-core, + pyln-proto, + pypaBuildHook, + pypaInstallHook, + pytestCheckHook, + stdenv, + unzip, +}: +stdenv.mkDerivation { pname = "pyln-bolt7"; # the version is defined here: # - @@ -10,13 +19,18 @@ buildPythonPackage { # - `dtrx ./result` # - `rg version /clightning-v23.11.2/contrib/pyln-spec/bolt7/pyproject.toml` version = "1.0.4.246"; - format = "pyproject"; inherit (clightning) src; - - nativeBuildInputs = [ poetry-core ]; - propagatedBuildInputs = [ pyln-proto ]; - checkInputs = [ pytestCheckHook ]; - sourceRoot = "clightning-v${clightning.version}/contrib/pyln-spec/bolt7"; + + nativeBuildInputs = [ + poetry-core + pypaBuildHook + pypaInstallHook + unzip # used by `unpackPhase` + ]; + propagatedBuildInputs = [ + pyln-proto + ]; + nativeCheckInputs = [ pytestCheckHook ]; } diff --git a/pkgs/python-packages/pyln-client/default.nix b/pkgs/python-packages/pyln-client/default.nix index 77f00cdc..5d3d44c0 100644 --- a/pkgs/python-packages/pyln-client/default.nix +++ b/pkgs/python-packages/pyln-client/default.nix @@ -1,20 +1,33 @@ # based on: -{ buildPythonPackage, poetry-core, pytestCheckHook, clightning, pyln-bolt7, pyln-proto }: - -buildPythonPackage { +{ + clightning, + poetry-core, + pyln-bolt7, + pyln-proto, + pypaBuildHook, + pypaInstallHook, + pytestCheckHook, + stdenv, + unzip, +}: +stdenv.mkDerivation { pname = "pyln-client"; format = "pyproject"; inherit (clightning) src version; + sourceRoot = "clightning-v${clightning.version}/contrib/pyln-client"; - nativeBuildInputs = [ poetry-core ]; + nativeBuildInputs = [ + poetry-core + pypaBuildHook + pypaInstallHook + unzip # used by `unpackPhase` + ]; propagatedBuildInputs = [ pyln-bolt7 pyln-proto ]; - checkInputs = [ pytestCheckHook ]; - - sourceRoot = "clightning-v${clightning.version}/contrib/pyln-client"; + nativeCheckInputs = [ pytestCheckHook ]; } diff --git a/pkgs/python-packages/pyln-proto/default.nix b/pkgs/python-packages/pyln-proto/default.nix index 413a7859..cff20282 100644 --- a/pkgs/python-packages/pyln-proto/default.nix +++ b/pkgs/python-packages/pyln-proto/default.nix @@ -1,16 +1,21 @@ # based on: -{ buildPythonPackage -, clightning -, poetry-core -, pytestCheckHook -, bitstring -, cryptography -, coincurve -, base58 -, pysocks +{ + clightning, + poetry-core, + pypaBuildHook, + pypaInstallHook, + pytestCheckHook, + stdenv, + unzip, + # python runtime deps + base58, + bitstring, + coincurve, + cryptography, + pysocks, }: -buildPythonPackage { +stdenv.mkDerivation { pname = "pyln-proto"; format = "pyproject"; @@ -25,7 +30,12 @@ buildPythonPackage { --replace-fail 'cryptography = "^41"' 'cryptography = ">=41"' ''; - nativeBuildInputs = [ poetry-core ]; + nativeBuildInputs = [ + poetry-core + pypaBuildHook + pypaInstallHook + unzip # used by `unpackPhase` + ]; propagatedBuildInputs = [ bitstring @@ -35,5 +45,5 @@ buildPythonPackage { pysocks ]; - checkInputs = [ pytestCheckHook ]; + nativeCheckInputs = [ pytestCheckHook ]; } diff --git a/templates/pkgs/python/default.nix b/templates/pkgs/python/default.nix index 8e02c3d2..1c729b6f 100644 --- a/templates/pkgs/python/default.nix +++ b/templates/pkgs/python/default.nix @@ -1,28 +1,42 @@ -{ lib -, buildPythonPackage -, fetchFromGitHub -}: buildPythonPackage { - pname = "mypackage"; - version = "0.1-unstable-2024-06-04"; - format = "pyproject"; # or setuptools +{ + lib, + fetchFromGitHub, + # pypaBuildHook, + # pypaInstallHook, + pytestCheckHook, + stdenv, +}: stdenv.mkDerivation (finalAttrs: { + # pname = "mypackage"; + # version = "0.1-unstable-2024-06-04"; src = fetchFromGitHub { - owner = "owner"; - repo = "repo"; - rev = "${version}"; + # owner = "owner"; + # repo = "repo"; + rev = "v${finalAttrs.version}"; + # hash = ""; }; + nativeBuildInputs = [ + # poetry-core + # pypaBuildHook + # pypaInstallHook + ]; + propagatedBuildInputs = [ # other python modules this depends on, if this package is supposed to be importable ]; + nativeCheckInputs = [ + # pytestCheckHook + ]; + pythonImportsCheck = [ - "mymodule" + # "mymodule" ]; meta = with lib; { - homepage = "https://example.com"; - description = "python template project"; + # homepage = "https://example.com"; + # description = "python template project"; maintainers = with maintainers; [ colinsane ]; }; -} +})