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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
%pyproject_buildrequires(r) %{expand:\\\
|
%pyproject_buildrequires(rx:) %{expand:\\\
|
||||||
echo 'python3-devel'
|
echo 'python3-devel'
|
||||||
echo 'python3dist(packaging)'
|
echo 'python3dist(packaging)'
|
||||||
echo 'python3dist(pip) >= 19'
|
echo 'python3dist(pip) >= 19'
|
||||||
|
@ -42,7 +42,7 @@ def hook_call():
|
|||||||
|
|
||||||
class Requirements:
|
class Requirements:
|
||||||
"""Requirement printer"""
|
"""Requirement printer"""
|
||||||
def __init__(self, freeze_output):
|
def __init__(self, freeze_output, extras=''):
|
||||||
self.installed_packages = {}
|
self.installed_packages = {}
|
||||||
for line in freeze_output.splitlines():
|
for line in freeze_output.splitlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
@ -51,6 +51,8 @@ class Requirements:
|
|||||||
name, version = line.split('==')
|
name, version = line.split('==')
|
||||||
self.installed_packages[name.strip()] = Version(version)
|
self.installed_packages[name.strip()] = Version(version)
|
||||||
|
|
||||||
|
self.marker_env = {'extra': extras}
|
||||||
|
|
||||||
self.missing_requirements = False
|
self.missing_requirements = False
|
||||||
|
|
||||||
def add(self, requirement_str, *, source=None):
|
def add(self, requirement_str, *, source=None):
|
||||||
@ -68,7 +70,7 @@ class Requirements:
|
|||||||
|
|
||||||
name = canonicalize_name(requirement.name)
|
name = canonicalize_name(requirement.name)
|
||||||
if (requirement.marker is not None
|
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)
|
print_err(f'Ignoring alien requirement:', requirement_str)
|
||||||
return
|
return
|
||||||
@ -181,8 +183,10 @@ def python3dist(name, op=None, version=None):
|
|||||||
return f'python3dist({name}) {op} {version}'
|
return f'python3dist({name}) {op} {version}'
|
||||||
|
|
||||||
|
|
||||||
def generate_requires(freeze_output, *, include_runtime=False, toxenv=None):
|
def generate_requires(
|
||||||
requirements = Requirements(freeze_output)
|
freeze_output, *, include_runtime=False, toxenv=None, extras='',
|
||||||
|
):
|
||||||
|
requirements = Requirements(freeze_output, extras=extras)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
backend = get_backend(requirements)
|
backend = get_backend(requirements)
|
||||||
@ -206,6 +210,11 @@ def main(argv):
|
|||||||
help='generate test tequirements from tox environment '
|
help='generate test tequirements from tox environment '
|
||||||
+ '(not implemented; implies --runtime)',
|
+ '(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)
|
args = parser.parse_args(argv)
|
||||||
if args.toxenv:
|
if args.toxenv:
|
||||||
@ -224,7 +233,11 @@ def main(argv):
|
|||||||
).stdout
|
).stdout
|
||||||
|
|
||||||
try:
|
try:
|
||||||
generate_requires(freeze_output, include_runtime=args.runtime)
|
generate_requires(
|
||||||
|
freeze_output,
|
||||||
|
include_runtime=args.runtime,
|
||||||
|
extras=args.extras,
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Log the traceback explicitly (it's useful debug info)
|
# Log the traceback explicitly (it's useful debug info)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
@ -29,6 +29,7 @@ def test_data(case_name, capsys, tmp_path, monkeypatch):
|
|||||||
generate_requires(
|
generate_requires(
|
||||||
case['freeze_output'],
|
case['freeze_output'],
|
||||||
include_runtime=case.get('include_runtime', False),
|
include_runtime=case.get('include_runtime', False),
|
||||||
|
extras=case.get('extras', ''),
|
||||||
)
|
)
|
||||||
except SystemExit as e:
|
except SystemExit as e:
|
||||||
assert e.code == case['result']
|
assert e.code == case['result']
|
||||||
|
@ -142,13 +142,13 @@ Default build system, run dependencies in setup.py:
|
|||||||
python3dist(inst2) < 3
|
python3dist(inst2) < 3
|
||||||
result: 0
|
result: 0
|
||||||
|
|
||||||
Run dependencies with extras:
|
Run dependencies with extras (not selected):
|
||||||
freeze_output: |
|
freeze_output: |
|
||||||
setuptools==50
|
setuptools==50
|
||||||
wheel==1
|
wheel==1
|
||||||
pyyaml==1
|
pyyaml==1
|
||||||
include_runtime: true
|
include_runtime: true
|
||||||
setup.py: |
|
setup.py: &pytest_setup_py |
|
||||||
# slightly abriged copy of pytest's setup.py
|
# slightly abriged copy of pytest's setup.py
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
@ -198,3 +198,29 @@ Run dependencies with extras:
|
|||||||
python3dist(pluggy) >= 0.11
|
python3dist(pluggy) >= 0.11
|
||||||
python3dist(more-itertools) >= 4
|
python3dist(more-itertools) >= 4
|
||||||
result: 0
|
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
|
%generate_buildrequires
|
||||||
%pyproject_buildrequires -r
|
%pyproject_buildrequires -r -x testing
|
||||||
|
|
||||||
|
|
||||||
%build
|
%build
|
||||||
@ -37,6 +37,12 @@ py.test provides simple, yet powerful testing for Python.
|
|||||||
%install
|
%install
|
||||||
%pyproject_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}
|
%files -n python3-%{pypi_name}
|
||||||
%doc README.rst
|
%doc README.rst
|
||||||
|
Loading…
Reference in New Issue
Block a user