Skip to content

Commit

Permalink
rendeners: Use new-style buildPythonPackage options
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Aug 18, 2024
1 parent 0c81cc6 commit 86cadfc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
19 changes: 10 additions & 9 deletions lib/renderers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ in
Example:
# buildPythonPackage { project = lib.project.loadPyproject ...; python = pkgs.python3; }
{ pname = "blinker"; version = "1.3.3.7"; propagatedBuildInputs = [ ]; }
{ pname = "blinker"; version = "1.3.3.7"; dependencies = [ ]; }
*/
buildPythonPackage =
{
Expand All @@ -82,7 +82,7 @@ in
, # Map a Python extras group name to a Nix attribute set like:
# { dev = "checkInputs"; }
# This is intended to be used with optionals such as test dependencies that you might
# want to add to checkInputs instead of propagatedBuildInputs
# want to add to checkInputs instead of dependencies
extrasAttrMappings ? { }
, # Which package format to pass to buildPythonPackage
# If the format is "wheel" PEP-518 build-systems are excluded from the build.
Expand Down Expand Up @@ -142,19 +142,20 @@ in
foldl'
(attrs: group:
let
attr = extrasAttrMappings.${group} or "propagatedBuildInputs";
attr = extrasAttrMappings.${group} or "dependencies";
in
attrs // {
${attr} = attrs.${attr} or [ ] ++ map (dep: python.pkgs.${dep}) namedDeps.extras.${group};
})
({
propagatedBuildInputs = map (dep: python.pkgs.${dep}) namedDeps.dependencies;
inherit format meta;
passthru = {
optional-dependencies = lib.mapAttrs (_group: deps: map (dep: python.pkgs.${dep.name}) deps) project.dependencies.extras;
};
pyproject = format == "pyproject";
dependencies = map (dep: python.pkgs.${dep}) namedDeps.dependencies;
optional-dependencies = lib.mapAttrs (_group: deps: map (dep: python.pkgs.${dep.name}) deps) project.dependencies.extras;
inherit meta;
} // optionalAttrs (format != "pyproject") {
inherit format;
} // optionalAttrs (format != "wheel") {
nativeBuildInputs =
build-system =
if namedDeps.build-systems != [ ] then map (dep: pythonPackages.${dep}) namedDeps.build-systems
else [ pythonPackages.setuptools pythonPackages.wheel ];
} // optionalAttrs (pyproject.project ? name) {
Expand Down
24 changes: 12 additions & 12 deletions lib/test_project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ lib.fix (self: {
getPkgs' = getPkgs mocks.cpythonLinux38;
in
{
format = "pyproject";
pyproject = true;
disabled = true;
meta = { description = "Powerful data structures for data analysis, time series, and statistics"; };
passthru.optional-dependencies = lib.mapAttrs (_: getPkgs') {
optional-dependencies = lib.mapAttrs (_: getPkgs') {
all = [ "beautifulsoup4" "bottleneck" "brotlipy" "fastparquet" "fsspec" "gcsfs" "html5lib" "hypothesis" "Jinja2" "lxml" "matplotlib" "numba" "numexpr" "odfpy" "openpyxl" "pandas-gbq" "psycopg2" "pyarrow" "PyMySQL" "PyQt5" "pyreadstat" "pytest" "pytest-xdist" "pytest-asyncio" "python-snappy" "pyxlsb" "QtPy" "scipy" "s3fs" "SQLAlchemy" "tables" "tabulate" "xarray" "xlrd" "xlsxwriter" "zstandard" ];
aws = [ "s3fs" ];
clipboard = [ "PyQt5" "QtPy" ];
Expand All @@ -71,7 +71,7 @@ lib.fix (self: {
test = [ "hypothesis" "pytest" "pytest-xdist" "pytest-asyncio" ];
xml = [ "lxml" ];
};
nativeBuildInputs = getPkgs' [
build-system = getPkgs' [
"meson-python"
"meson"
"wheel"
Expand All @@ -80,7 +80,7 @@ lib.fix (self: {
"versioneer"
];
pname = "pandas";
propagatedBuildInputs = getPkgs' [
dependencies = getPkgs' [
"numpy"
"python-dateutil"
"pytz"
Expand Down Expand Up @@ -117,8 +117,8 @@ lib.fix (self: {
{
disabled = false;
src = true;
format = "pyproject";
passthru.optional-dependencies = lib.mapAttrs (_: getPkgs') {
pyproject = true;
optional-dependencies = lib.mapAttrs (_: getPkgs') {
all = [ "pdm" ];
cookiecutter = [ "cookiecutter" ];
copier = [ "copier" ];
Expand All @@ -144,11 +144,11 @@ lib.fix (self: {
};
mainProgram = "pdm";
};
nativeBuildInputs = getPkgs mocks.cpythonLinux38 [
build-system = getPkgs mocks.cpythonLinux38 [
"pdm-backend"
];
pname = "pdm";
propagatedBuildInputs = getPkgs mocks.cpythonLinux38 [
dependencies = getPkgs mocks.cpythonLinux38 [
"blinker"
"certifi"
"packaging"
Expand Down Expand Up @@ -189,8 +189,8 @@ lib.fix (self: {
getPkgs' = getPkgs mocks.cpythonLinux38;
in
{
format = "pyproject";
passthru.optional-dependencies = lib.mapAttrs (_: getPkgs') {
pyproject = true;
optional-dependencies = lib.mapAttrs (_: getPkgs') {
dev = [ "pre-commit" ];
github-actions = [ "pytest-github-actions-annotate-failures" ];
test = [ "cachy" "deepdiff" "deepdiff" "httpretty" "pytest" "pytest-cov" "pytest-mock" "pytest-randomly" "pytest-xdist" "zipp" ];
Expand All @@ -209,11 +209,11 @@ lib.fix (self: {
};
mainProgram = "poetry";
};
nativeBuildInputs = getPkgs mocks.cpythonLinux38 [
build-system = getPkgs mocks.cpythonLinux38 [
"poetry-core"
];
pname = "poetry";
propagatedBuildInputs = getPkgs mocks.cpythonLinux38 [
dependencies = getPkgs mocks.cpythonLinux38 [
"build"
"cachecontrol"
"cleo"
Expand Down
24 changes: 11 additions & 13 deletions lib/test_renderers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ let
# Clear drv inputs from stuff like version and just return the name string
# so our tests don't start failing randomly just because we upgrade and nixpkgs moved
clearDrvInputs = attrs: attrs // {
propagatedBuildInputs = map (drv: drv.pname) attrs.propagatedBuildInputs;
nativeBuildInputs = map (drv: drv.pname) attrs.nativeBuildInputs;
passthru = attrs.passthru // {
optional-dependencies = lib.mapAttrs (_group: deps: map (drv: drv.pname) deps) attrs.passthru.optional-dependencies;
};
dependencies = map (drv: drv.pname) attrs.dependencies;
build-system = map (drv: drv.pname) attrs.build-system;
optional-dependencies = lib.mapAttrs (_group: deps: map (drv: drv.pname) deps) attrs.optional-dependencies;
} // optionalAttrs (attrs ? checkInputs) {
checkInputs = map (drv: drv.pname) attrs.checkInputs;
};
Expand Down Expand Up @@ -55,16 +53,16 @@ in
});
expected = {
disabled = false;
format = "pyproject";
pyproject = true;
meta = {
description = "A modern Python package and dependency manager supporting the latest PEP standards";
license = lib.licenses.mit;
mainProgram = "pdm";
};
nativeBuildInputs = [ "pdm-backend" ];
build-system = [ "pdm-backend" ];
pname = "pdm";
passthru = { optional-dependencies = { all = [ "pdm" ]; cookiecutter = [ "cookiecutter" ]; copier = [ "copier" ]; doc = [ "mkdocs" "mkdocs-material" "mkdocstrings" "mike" "setuptools" "markdown-exec" "mkdocs-redirects" ]; keyring = [ "keyring" ]; pytest = [ "pytest" "pytest-mock" ]; template = [ "pdm" ]; test = [ "pdm" "pytest-cov" "pytest-xdist" "pytest-rerunfailures" "pytest-httpserver" ]; tox = [ "tox" "tox-pdm" ]; truststore = [ "truststore" ]; workflow = [ "pdm-pep517" "parver" "towncrier" "pycomplete" ]; }; };
propagatedBuildInputs = [ "blinker" "certifi" "packaging" "platformdirs" "rich" "virtualenv" "pyproject-hooks" "requests-toolbelt" "unearth" "findpython" "tomlkit" "shellingham" "python-dotenv" "resolvelib" "installer" "cachecontrol" "tomli" "importlib-resources" "importlib-metadata" ];
optional-dependencies = { all = [ "pdm" ]; cookiecutter = [ "cookiecutter" ]; copier = [ "copier" ]; doc = [ "mkdocs" "mkdocs-material" "mkdocstrings" "mike" "setuptools" "markdown-exec" "mkdocs-redirects" ]; keyring = [ "keyring" ]; pytest = [ "pytest" "pytest-mock" ]; template = [ "pdm" ]; test = [ "pdm" "pytest-cov" "pytest-xdist" "pytest-rerunfailures" "pytest-httpserver" ]; tox = [ "tox" "tox-pdm" ]; truststore = [ "truststore" ]; workflow = [ "pdm-pep517" "parver" "towncrier" "pycomplete" ]; };
dependencies = [ "blinker" "certifi" "packaging" "platformdirs" "rich" "virtualenv" "pyproject-hooks" "requests-toolbelt" "unearth" "findpython" "tomlkit" "shellingham" "python-dotenv" "resolvelib" "installer" "cachecontrol" "tomli" "importlib-resources" "importlib-metadata" ];
};
};

Expand Down Expand Up @@ -94,16 +92,16 @@ in
expected = {
disabled = false;
checkInputs = [ "tox" "tox-pdm" ];
format = "pyproject";
pyproject = true;
meta = {
description = "A modern Python package and dependency manager supporting the latest PEP standards";
license = lib.licenses.mit;
mainProgram = "pdm";
};
nativeBuildInputs = [ "pdm-backend" ];
build-system = [ "pdm-backend" ];
pname = "pdm";
passthru = { optional-dependencies = { all = [ "pdm" ]; cookiecutter = [ "cookiecutter" ]; copier = [ "copier" ]; doc = [ "mkdocs" "mkdocs-material" "mkdocstrings" "mike" "setuptools" "markdown-exec" "mkdocs-redirects" ]; keyring = [ "keyring" ]; pytest = [ "pytest" "pytest-mock" ]; template = [ "pdm" ]; test = [ "pdm" "pytest-cov" "pytest-xdist" "pytest-rerunfailures" "pytest-httpserver" ]; tox = [ "tox" "tox-pdm" ]; truststore = [ "truststore" ]; workflow = [ "pdm-pep517" "parver" "towncrier" "pycomplete" ]; }; };
propagatedBuildInputs = [ "blinker" "certifi" "packaging" "platformdirs" "rich" "virtualenv" "pyproject-hooks" "requests-toolbelt" "unearth" "findpython" "tomlkit" "shellingham" "python-dotenv" "resolvelib" "installer" "cachecontrol" "tomli" "importlib-resources" "importlib-metadata" ];
optional-dependencies = { all = [ "pdm" ]; cookiecutter = [ "cookiecutter" ]; copier = [ "copier" ]; doc = [ "mkdocs" "mkdocs-material" "mkdocstrings" "mike" "setuptools" "markdown-exec" "mkdocs-redirects" ]; keyring = [ "keyring" ]; pytest = [ "pytest" "pytest-mock" ]; template = [ "pdm" ]; test = [ "pdm" "pytest-cov" "pytest-xdist" "pytest-rerunfailures" "pytest-httpserver" ]; tox = [ "tox" "tox-pdm" ]; truststore = [ "truststore" ]; workflow = [ "pdm-pep517" "parver" "towncrier" "pycomplete" ]; };
dependencies = [ "blinker" "certifi" "packaging" "platformdirs" "rich" "virtualenv" "pyproject-hooks" "requests-toolbelt" "unearth" "findpython" "tomlkit" "shellingham" "python-dotenv" "resolvelib" "installer" "cachecontrol" "tomli" "importlib-resources" "importlib-metadata" ];
};
};
};
Expand Down

0 comments on commit 86cadfc

Please sign in to comment.