Merge pull request #174000 from mweinelt/pep621-optional-dependencies

This commit is contained in:
Martin Weinelt 2022-05-23 01:35:24 +02:00 committed by GitHub
commit bc38fcac7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 97 additions and 96 deletions

View file

@ -982,12 +982,13 @@ in python.withPackages(ps: [ps.blaze])).env
#### Optional extra dependencies
Some packages define optional dependencies for additional features. With
`setuptools` this is called `extras_require` and `flit` calls it `extras-require`. A
`setuptools` this is called `extras_require` and `flit` calls it
`extras-require`, while PEP 621 calls these `optional-dependencies`. A
method for supporting this is by declaring the extras of a package in its
`passthru`, e.g. in case of the package `dask`
```nix
passthru.extras-require = {
passthru.optional-dependencies = {
complete = [ distributed ];
};
```
@ -997,7 +998,7 @@ and letting the package requiring the extra add the list to its dependencies
```nix
propagatedBuildInputs = [
...
] ++ dask.extras-require.complete;
] ++ dask.optional-dependencies.complete;
```
Note this method is preferred over adding parameters to builders, as that can

View file

@ -14,7 +14,7 @@ buildPythonApplication rec {
};
propagatedBuildInputs = [ twisted certifi ]
++ twisted.extras-require.tls
++ twisted.optional-dependencies.tls
++ lib.optional enableGUI pyside2;
nativeBuildInputs = lib.optionals enableGUI [ qt5.wrapQtAppsHook ];

View file

@ -122,7 +122,7 @@ py.pkgs.pythonPackages.buildPythonApplication rec {
threadpoolctl
tika
tqdm
twisted.extras-require.tls
twisted.optional-dependencies.tls
txaio
tzlocal
urllib3

View file

@ -30,7 +30,7 @@ buildPythonPackage rec {
markupsafe
];
passthru.extras-require = {
passthru.optional-dependencies = {
babel = [
babel
];
@ -39,7 +39,7 @@ buildPythonPackage rec {
checkInputs = [
pytestCheckHook
mock
] ++ passthru.extras-require.babel;
] ++ passthru.optional-dependencies.babel;
disabledTests = lib.optionals isPyPy [
# https://github.com/sqlalchemy/mako/issues/315

View file

@ -33,7 +33,7 @@ buildPythonPackage rec {
rsa
];
passthru.extras-require = {
passthru.optional-dependencies = {
async = [
aiofiles
];
@ -47,8 +47,8 @@ buildPythonPackage rec {
pycryptodome
pytestCheckHook
]
++ passthru.extras-require.async
++ passthru.extras-require.usb;
++ passthru.optional-dependencies.async
++ passthru.optional-dependencies.usb;
disabledTests = lib.optionals (pythonAtLeast "3.10") [
# Tests are failing with Python 3.10

View file

@ -28,19 +28,19 @@ buildPythonPackage rec {
pure-python-adb
];
passthru.extras-require = {
passthru.optional-dependencies = {
async = [
aiofiles
];
inherit (adb-shell.extras-require) usb;
inherit (adb-shell.optional-dependencies) usb;
};
checkInputs = [
mock
pytestCheckHook
]
++ passthru.extras-require.async
++ passthru.extras-require.usb;
++ passthru.optional-dependencies.async
++ passthru.optional-dependencies.usb;
disabledTests = [
# Requires git but fails anyway

View file

@ -68,8 +68,8 @@ buildPythonPackage rec {
mock
pytest-asyncio
pytestCheckHook
] ++ passthru.extras-require.scram
++ passthru.extras-require.serialization;
] ++ passthru.optional-dependencies.scram
++ passthru.optional-dependencies.serialization;
postPatch = ''
substituteInPlace setup.py \
@ -89,7 +89,7 @@ buildPythonPackage rec {
"autobahn"
];
passthru.extras-require = rec {
passthru.optional-dependencies = rec {
all = accelerate ++ compress ++ encryption ++ nvx ++ serialization ++ scram ++ twisted ++ ui ++ xbr;
accelerate = [ /* wsaccel */ ];
compress = [ python-snappy ];

View file

@ -54,7 +54,7 @@ let
pyyaml
]
# tls
++ twisted.extras-require.tls;
++ twisted.optional-dependencies.tls;
checkInputs = [
treq

View file

@ -40,7 +40,7 @@ buildPythonPackage rec {
six
];
passthru.extras-require = {
passthru.optional-dependencies = {
datetime = [
python-dateutil
];

View file

@ -98,7 +98,7 @@ buildPythonPackage rec {
"dask.diagnostics"
];
passthru.extras-require = {
passthru.optional-dependencies = {
complete = [ distributed ];
};

View file

@ -46,7 +46,7 @@ buildPythonPackage rec {
param
pyct
scipy
] ++ dask.extras-require.complete;
] ++ dask.optional-dependencies.complete;
checkInputs = [
pytestCheckHook

View file

@ -27,11 +27,11 @@ buildPythonPackage rec {
pytz
];
passthru.extras-require.taggit = [
passthru.optional-dependencies.taggit = [
django-taggit
];
checkInputs = passthru.extras-require.taggit;
checkInputs = passthru.optional-dependencies.taggit;
checkPhase = ''
runHook preCheck

View file

@ -49,7 +49,7 @@ buildPythonPackage rec {
pytest-asyncio
sqlalchemy
trio
] ++ passlib.extras-require.bcrypt;
] ++ passlib.optional-dependencies.bcrypt;
patches = [
# Bump starlette, https://github.com/tiangolo/fastapi/pull/4483

View file

@ -63,7 +63,7 @@ buildPythonPackage rec {
passlib
];
passthru.extras-require = {
passthru.optional-dependencies = {
babel = [
babel
flask-babel
@ -95,10 +95,10 @@ buildPythonPackage rec {
pytestCheckHook
zxcvbn
]
++ passthru.extras-require.babel
++ passthru.extras-require.common
++ passthru.extras-require.fsqla
++ passthru.extras-require.mfa;
++ passthru.optional-dependencies.babel
++ passthru.optional-dependencies.common
++ passthru.optional-dependencies.fsqla
++ passthru.optional-dependencies.mfa;
pythonImportsCheck = [ "flask_security" ];

View file

@ -42,7 +42,7 @@ buildPythonPackage rec {
sniffio
];
passthru.extras-require = {
passthru.optional-dependencies = {
http2 = [ h2 ];
socks = [ socksio ];
};
@ -56,8 +56,8 @@ buildPythonPackage rec {
trio
trustme
uvicorn
] ++ passthru.extras-require.http2
++ passthru.extras-require.socks;
] ++ passthru.optional-dependencies.http2
++ passthru.optional-dependencies.socks;
pythonImportsCheck = [ "httpcore" ];

View file

@ -38,7 +38,7 @@ buildPythonPackage rec {
python-socks
];
passthru.extras-require = {
passthru.optional-dependencies = {
asyncio = [ async-timeout ];
trio = [ trio ];
};

View file

@ -49,7 +49,7 @@ buildPythonPackage rec {
async_generator
];
passthru.extras-require = {
passthru.optional-dependencies = {
http2 = [ h2 ];
socks = [ socksio ];
brotli = if isPyPy then [ brotlicffi ] else [ brotli ];
@ -63,9 +63,9 @@ buildPythonPackage rec {
trustme
typing-extensions
uvicorn
] ++ passthru.extras-require.http2
++ passthru.extras-require.brotli
++ passthru.extras-require.socks;
] ++ passthru.optional-dependencies.http2
++ passthru.optional-dependencies.brotli
++ passthru.optional-dependencies.socks;
postPatch = ''
substituteInPlace setup.py \

View file

@ -99,7 +99,7 @@ buildPythonPackage rec {
pytest-mock
pytest-randomly
pytest-xdist
] ++ lib.concatMap (name: passthru.extras-require.${name}) testBackends;
] ++ lib.concatMap (name: passthru.optional-dependencies.${name}) testBackends;
preBuild = ''
# setup.py exists only for developer convenience and is automatically generated
@ -139,7 +139,7 @@ buildPythonPackage rec {
] ++ map (backend: "ibis.backends.${backend}") testBackends;
passthru = {
extras-require = {
optional-dependencies = {
clickhouse = [ clickhouse-cityhash clickhouse-driver lz4 ];
dask = [ dask pyarrow ];
datafusion = [ datafusion ];

View file

@ -27,7 +27,7 @@ buildPythonPackage rec {
six
twisted
zope_interface
] ++ twisted.extras-require.tls;
] ++ twisted.optional-dependencies.tls;
checkInputs = [
twisted

View file

@ -25,8 +25,8 @@ buildPythonPackage rec {
six
twisted
autobahn
] ++ autobahn.extras-require.twisted
++ twisted.extras-require.tls;
] ++ autobahn.optional-dependencies.twisted
++ twisted.optional-dependencies.tls;
checkInputs = [
treq

View file

@ -42,8 +42,8 @@ buildPythonPackage rec {
click
humanize
txtorcon
] ++ autobahn.extras-require.twisted
++ twisted.extras-require.tls;
] ++ autobahn.optional-dependencies.twisted
++ twisted.optional-dependencies.tls;
checkInputs = [
mock

View file

@ -16,7 +16,7 @@ buildPythonPackage rec {
sha256 = "defd50f72b65c5402ab2c573830a6978e5f202ad0d984793c8dde2c4152ebe04";
};
passthru.extras-require = {
passthru.optional-dependencies = {
argon2 = [ argon2-cffi ];
bcrypt = [ bcrypt ];
totp = [ cryptography ];
@ -24,9 +24,9 @@ buildPythonPackage rec {
checkInputs = [
pytestCheckHook
] ++ passthru.extras-require.argon2
++ passthru.extras-require.bcrypt
++ passthru.extras-require.totp;
] ++ passthru.optional-dependencies.argon2
++ passthru.optional-dependencies.bcrypt
++ passthru.optional-dependencies.totp;
meta = with lib; {
description = "A password hashing library for Python";

View file

@ -17,7 +17,7 @@ buildPythonPackage rec {
sha256 = "0kdr7w2fhgjpcf1k3l6an9im583iqkr6v8hb4q1zw30nh3bqkk0f";
};
passthru.extras-require = {
passthru.optional-dependencies = {
async = [
aiofiles
];
@ -28,7 +28,7 @@ buildPythonPackage rec {
checkInputs = [
pytestCheckHook
]
++ passthru.extras-require.async;
++ passthru.optional-dependencies.async;
pythonImportsCheck = [
"ppadb.client"

View file

@ -25,7 +25,7 @@ buildPythonPackage rec {
pyserial
];
passthru.extras-require.GATTTOOL = [
passthru.optional-dependencies.GATTTOOL = [
pexpect
];
@ -34,7 +34,7 @@ buildPythonPackage rec {
nose
pytestCheckHook
]
++ passthru.extras-require.GATTTOOL;
++ passthru.optional-dependencies.GATTTOOL;
postPatch = ''
# Not support for Python < 3.4

View file

@ -23,7 +23,7 @@ buildPythonPackage rec {
setuptools-scm
];
passthru.extras-require = {
passthru.optional-dependencies = {
images = [
pillow
];
@ -38,7 +38,7 @@ buildPythonPackage rec {
checkInputs = [
pytestCheckHook
] ++ passthru.extras-require.images;
] ++ passthru.optional-dependencies.images;
pythonImportsCheck = [ "barcode" ];

View file

@ -21,7 +21,7 @@ buildPythonPackage rec {
hash = "sha256-12ol+2CnoPfkxmDGJJAkoafHGpQuWC4lh0N7lSvx2DE=";
};
passthru.extras-require = {
passthru.optional-dependencies = {
async = [
aiocoap
dtlssocket
@ -31,7 +31,7 @@ buildPythonPackage rec {
checkInputs = [
pytestCheckHook
]
++ passthru.extras-require.async;
++ passthru.optional-dependencies.async;
pythonImportsCheck = [
"pytradfri"

View file

@ -43,7 +43,7 @@ buildPythonPackage rec {
importlib-metadata
];
passthru.extras-require = {
passthru.optional-dependencies = {
html = [
html5lib
];
@ -55,8 +55,8 @@ buildPythonPackage rec {
checkInputs = [
pytestCheckHook
]
++ passthru.extras-require.networkx
++ passthru.extras-require.html;
++ passthru.optional-dependencies.networkx
++ passthru.optional-dependencies.html;
pytestFlagsArray = [
# requires network access

View file

@ -40,7 +40,7 @@ buildPythonPackage rec {
importlib-metadata
];
passthru.extras-require = {
passthru.optional-dependencies = {
hidredis = [
hiredis
];

View file

@ -27,14 +27,14 @@ buildPythonPackage rec {
lxml
];
passthru.extras-require = {
passthru.optional-dependencies = {
chart = [ /* pycha */ pyyaml ];
fodt = [ python-magic ];
};
checkInputs = [
pytestCheckHook
] ++ passthru.extras-require.fodt;
] ++ passthru.optional-dependencies.fodt;
pythonImportsCheck = [ "relatorio" ];

View file

@ -28,13 +28,13 @@ buildPythonPackage rec {
six
];
passthru.extras-require = {
passthru.optional-dependencies = {
httpx = [ httpx ];
};
checkInputs = [
pytestCheckHook
] ++ passthru.extras-require.httpx;
] ++ passthru.optional-dependencies.httpx;
pythonImportsCheck = [
"requests_aws4auth"

View file

@ -15,7 +15,7 @@ buildPythonPackage rec {
sha256 = "0ipz3fd65rqkxlb02sql0awc3vnslrwb2pfrsnpfnf8bfgxpbh9g";
};
passthru.extras-require = {
passthru.optional-dependencies = {
websocket = [
websocket-client
];

View file

@ -39,7 +39,7 @@ buildPythonPackage rec {
websocket-client
];
passthru.extras-require = {
passthru.optional-dependencies = {
async = [
aiohttp
websockets
@ -55,8 +55,8 @@ buildPythonPackage rec {
pytest-asyncio
pytestCheckHook
]
++ passthru.extras-require.async
++ passthru.extras-require.encrypted;
++ passthru.optional-dependencies.async
++ passthru.optional-dependencies.encrypted;
pythonImportsCheck = [ "samsungtvws" ];

View file

@ -20,7 +20,7 @@ buildPythonPackage rec {
requests
incremental
twisted
] ++ twisted.extras-require.tls;
] ++ twisted.optional-dependencies.tls;
checkInputs = [
httpbin

View file

@ -53,9 +53,9 @@ buildPythonPackage rec {
weasyprint
gevent
pillow
] ++ relatorio.extras-require.fodt
++ passlib.extras-require.bcrypt
++ passlib.extras-require.argon2
] ++ relatorio.optional-dependencies.fodt
++ passlib.optional-dependencies.bcrypt
++ passlib.optional-dependencies.argon2
++ lib.optional withPostgresql psycopg2;
checkPhase = ''

View file

@ -41,7 +41,7 @@ buildPythonPackage rec {
propagatedBuildInputs = [ zope_interface incremental automat constantly hyperlink pyhamcrest attrs setuptools typing-extensions ];
passthru.extras-require = rec {
passthru.optional-dependencies = rec {
tls = [ pyopenssl service-identity idna ];
conch = [ pyasn1 cryptography appdirs bcrypt ];
conch_nacl = conch ++ [ pynacl ];

View file

@ -13,7 +13,7 @@ buildPythonPackage rec {
propagatedBuildInputs = [
incremental twisted automat zope_interface
] ++ twisted.extras-require.tls
] ++ twisted.optional-dependencies.tls
++ lib.optionals (!isPy3k) [ ipaddress ];
checkInputs = [ pytestCheckHook mock lsof GeoIP ];

View file

@ -43,9 +43,9 @@ buildPythonPackage rec {
cxxfilt
msgpack
pycparser
] ++ lib.optionals (withGui) passthru.extras-require.gui;
] ++ lib.optionals (withGui) passthru.optional-dependencies.gui;
passthru.extras-require.gui = [
passthru.optional-dependencies.gui = [
pyqt5
pyqtwebengine
];

View file

@ -33,7 +33,7 @@ buildPythonPackage rec {
aiohttp
];
passthru.extras-require = {
passthru.optional-dependencies = {
console = [
certifi
docopt
@ -49,7 +49,7 @@ buildPythonPackage rec {
asynctest
pytest-asyncio
pytestCheckHook
] ++ passthru.extras-require.mqtt;
] ++ passthru.optional-dependencies.mqtt;
pythonImportsCheck = [ "volvooncall" ];

View file

@ -46,7 +46,7 @@ buildPythonApplication rec {
pyramid
strictyaml
waitress
] ++ passlib.extras-require.argon2;
] ++ passlib.optional-dependencies.argon2;
checkInputs = [
beautifulsoup4

View file

@ -118,9 +118,9 @@
androidtv
pure-python-adb
]
++ adb-shell.extras-require.async
++ androidtv.extras-require.async
++ pure-python-adb.extras-require.async;
++ adb-shell.optional-dependencies.async
++ androidtv.optional-dependencies.async
++ pure-python-adb.optional-dependencies.async;
"anel_pwrctrl" = ps: with ps; [
]; # missing inputs: anel_pwrctrl-homeassistant
"anthemav" = ps: with ps; [
@ -279,7 +279,7 @@
"bluetooth_le_tracker" = ps: with ps; [
pygatt
]
++ pygatt.extras-require.GATTTOOL;
++ pygatt.optional-dependencies.GATTTOOL;
"bluetooth_tracker" = ps: with ps; [
bt-proximity
pybluez
@ -2273,9 +2273,9 @@
wakeonlan
zeroconf
]
++ samsungctl.extras-require.websocket
++ samsungtvws.extras-require.async
++ samsungtvws.extras-require.encrypted;
++ samsungctl.optional-dependencies.websocket
++ samsungtvws.optional-dependencies.async
++ samsungtvws.optional-dependencies.encrypted;
"satel_integra" = ps: with ps; [
]; # missing inputs: satel_integra
"scene" = ps: with ps; [
@ -2388,7 +2388,7 @@
"skybeacon" = ps: with ps; [
pygatt
]
++ pygatt.extras-require.GATTTOOL;
++ pygatt.optional-dependencies.GATTTOOL;
"skybell" = ps: with ps; [
skybellpy
];
@ -2769,7 +2769,7 @@
"tradfri" = ps: with ps; [
pytradfri
]
++ pytradfri.extras-require.async;
++ pytradfri.optional-dependencies.async;
"trafikverket_ferry" = ps: with ps; [
pytrafikverket
];

View file

@ -103,13 +103,13 @@ def repository_root() -> str:
return os.path.abspath(sys.argv[0] + "/../../../..")
# For a package attribute and and an extra, check if the package exposes it via passthru.extras-require
# For a package attribute and and an extra, check if the package exposes it via passthru.optional-dependencies
def has_extra(package: str, extra: str):
cmd = [
"nix-instantiate",
repository_root(),
"-A",
f"{package}.extras-require.{extra}",
f"{package}.optional-dependencies.{extra}",
]
try:
subprocess.run(
@ -209,7 +209,7 @@ def main() -> None:
attr_paths.append(pname)
for extra in extras:
# Check if package advertises extra requirements
extra_attr = f"{pname}.extras-require.{extra}"
extra_attr = f"{pname}.optional-dependencies.{extra}"
if has_extra(attr_path, extra):
extra_attrs.append(extra_attr)
else:

View file

@ -21,7 +21,7 @@ python3.pkgs.buildPythonApplication rec {
vobject
python-dateutil
pytz # https://github.com/Kozea/Radicale/issues/816
] ++ passlib.extras-require.bcrypt;
] ++ passlib.optional-dependencies.bcrypt;
checkInputs = with python3.pkgs; [
pytestCheckHook

View file

@ -60,8 +60,8 @@ python3Packages.buildPythonApplication rec {
html5lib magic-wormhole netifaces pyasn1 pycrypto pyutil pyyaml recommonmark
service-identity simplejson sphinx_rtd_theme testtools treq twisted zfec
zope_interface
] ++ twisted.extras-require.tls
++ twisted.extras-require.conch;
] ++ twisted.optional-dependencies.tls
++ twisted.optional-dependencies.conch;
checkInputs = with python3Packages; [ mock hypothesis twisted ];

View file

@ -39,8 +39,8 @@ python3.pkgs.buildPythonApplication rec {
yaswfp
] ++ lib.optionals (python3.pythonOlder "3.8") [
importlib-metadata
] ++ httpx.extras-require.brotli
++ httpx.extras-require.socks;
] ++ httpx.optional-dependencies.brotli
++ httpx.optional-dependencies.socks;
checkInputs = with python3.pkgs; [
respx