Allow specifying extras for build dependencies
This commit is contained in:
parent
3600e9832d
commit
d6e6bb7dfb
@ -17,7 +17,7 @@ if [ -d %{buildroot}%{python3_sitearch} ]; then
|
||||
fi
|
||||
}
|
||||
|
||||
%pyproject_buildrequires(r) %{expand:\\\
|
||||
%pyproject_buildrequires(rx:) %{expand:\\\
|
||||
echo 'python3-devel'
|
||||
echo 'python3dist(packaging)'
|
||||
echo 'python3dist(pip) >= 19'
|
||||
|
@ -42,7 +42,7 @@ def hook_call():
|
||||
|
||||
class Requirements:
|
||||
"""Requirement printer"""
|
||||
def __init__(self, freeze_output):
|
||||
def __init__(self, freeze_output, extras=''):
|
||||
self.installed_packages = {}
|
||||
for line in freeze_output.splitlines():
|
||||
line = line.strip()
|
||||
@ -51,6 +51,8 @@ class Requirements:
|
||||
name, version = line.split('==')
|
||||
self.installed_packages[name.strip()] = Version(version)
|
||||
|
||||
self.marker_env = {'extra': extras}
|
||||
|
||||
self.missing_requirements = False
|
||||
|
||||
def add(self, requirement_str, *, source=None):
|
||||
@ -68,7 +70,7 @@ class Requirements:
|
||||
|
||||
name = canonicalize_name(requirement.name)
|
||||
if (requirement.marker is not None
|
||||
and not requirement.marker.evaluate(environment={'extra': ''})
|
||||
and not requirement.marker.evaluate(environment=self.marker_env)
|
||||
):
|
||||
print_err(f'Ignoring alien requirement:', requirement_str)
|
||||
return
|
||||
@ -181,8 +183,10 @@ def python3dist(name, op=None, version=None):
|
||||
return f'python3dist({name}) {op} {version}'
|
||||
|
||||
|
||||
def generate_requires(freeze_output, *, include_runtime=False, toxenv=None):
|
||||
requirements = Requirements(freeze_output)
|
||||
def generate_requires(
|
||||
freeze_output, *, include_runtime=False, toxenv=None, extras='',
|
||||
):
|
||||
requirements = Requirements(freeze_output, extras=extras)
|
||||
|
||||
try:
|
||||
backend = get_backend(requirements)
|
||||
@ -206,6 +210,11 @@ def main(argv):
|
||||
help='generate test tequirements from tox environment '
|
||||
+ '(not implemented; implies --runtime)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-x', '--extras', metavar='EXTRAS', default='',
|
||||
help='comma separated list of "extras" for runtime requirements '
|
||||
+ '(e.g. -x testing,feature-x)',
|
||||
)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
if args.toxenv:
|
||||
@ -224,7 +233,11 @@ def main(argv):
|
||||
).stdout
|
||||
|
||||
try:
|
||||
generate_requires(freeze_output, include_runtime=args.runtime)
|
||||
generate_requires(
|
||||
freeze_output,
|
||||
include_runtime=args.runtime,
|
||||
extras=args.extras,
|
||||
)
|
||||
except Exception as e:
|
||||
# Log the traceback explicitly (it's useful debug info)
|
||||
traceback.print_exc()
|
||||
|
@ -29,6 +29,7 @@ def test_data(case_name, capsys, tmp_path, monkeypatch):
|
||||
generate_requires(
|
||||
case['freeze_output'],
|
||||
include_runtime=case.get('include_runtime', False),
|
||||
extras=case.get('extras', ''),
|
||||
)
|
||||
except SystemExit as e:
|
||||
assert e.code == case['result']
|
||||
|
@ -142,13 +142,13 @@ Default build system, run dependencies in setup.py:
|
||||
python3dist(inst2) < 3
|
||||
result: 0
|
||||
|
||||
Run dependencies with extras:
|
||||
Run dependencies with extras (not selected):
|
||||
freeze_output: |
|
||||
setuptools==50
|
||||
wheel==1
|
||||
pyyaml==1
|
||||
include_runtime: true
|
||||
setup.py: |
|
||||
setup.py: &pytest_setup_py |
|
||||
# slightly abriged copy of pytest's setup.py
|
||||
from setuptools import setup
|
||||
|
||||
@ -198,3 +198,29 @@ Run dependencies with extras:
|
||||
python3dist(pluggy) >= 0.11
|
||||
python3dist(more-itertools) >= 4
|
||||
result: 0
|
||||
|
||||
Run dependencies with extras (selected):
|
||||
freeze_output: |
|
||||
setuptools==50
|
||||
wheel==1
|
||||
pyyaml==1
|
||||
include_runtime: true
|
||||
extras: testing
|
||||
setup.py: *pytest_setup_py
|
||||
expected: |
|
||||
python3dist(setuptools) >= 40.8
|
||||
python3dist(wheel)
|
||||
python3dist(wheel)
|
||||
python3dist(setuptools) >= 40
|
||||
python3dist(py) >= 1.5
|
||||
python3dist(six) >= 1.10
|
||||
python3dist(setuptools)
|
||||
python3dist(attrs) >= 17.4
|
||||
python3dist(atomicwrites) >= 1
|
||||
python3dist(pluggy) >= 0.11
|
||||
python3dist(more-itertools) >= 4
|
||||
python3dist(argcomplete)
|
||||
python3dist(hypothesis) >= 3.56
|
||||
python3dist(nose)
|
||||
python3dist(requests)
|
||||
result: 0
|
||||
|
@ -27,7 +27,7 @@ py.test provides simple, yet powerful testing for Python.
|
||||
|
||||
|
||||
%generate_buildrequires
|
||||
%pyproject_buildrequires -r
|
||||
%pyproject_buildrequires -r -x testing
|
||||
|
||||
|
||||
%build
|
||||
@ -37,6 +37,12 @@ py.test provides simple, yet powerful testing for Python.
|
||||
%install
|
||||
%pyproject_install
|
||||
|
||||
%check
|
||||
# Only run one test (which uses a test-only dependency, hypothesis).
|
||||
# (Unfortunately, some other tests still fail.)
|
||||
export PYTHONPATH=%{buildroot}%{python3_sitelib}
|
||||
%{__python3} -m pytest -k metafunc
|
||||
|
||||
|
||||
%files -n python3-%{pypi_name}
|
||||
%doc README.rst
|
||||
|
Loading…
Reference in New Issue
Block a user