Allow to fetch test dependencies from tox
This commit is contained in:
parent
6cfe9d4b22
commit
8a60635881
20
README.md
20
README.md
@ -55,6 +55,21 @@ For example, if upstream suggests installing test dependencies with
|
||||
%generate_buildrequires
|
||||
%pyproject_buildrequires -r -x testing
|
||||
|
||||
For projects that specify test requirements in their [tox] configuration,
|
||||
these can be added using the `-t` flag followed by the tox environment.
|
||||
For example, if upstream suggests running the tests on Python 3.7 with `tox -e py37`,
|
||||
the test deps would be generated by:
|
||||
|
||||
%generate_buildrequires
|
||||
%pyproject_buildrequires -t py37
|
||||
|
||||
Note that `-t` implies `-r`, because tox normally assumes the package is installed
|
||||
including all the runtime dependencies.
|
||||
|
||||
The `-t` option uses [tox-current-env]'s `--print-deps-only` behind the scenes.
|
||||
|
||||
[tox]: https://tox.readthedocs.io/
|
||||
[tox-current-env]: https://github.com/fedora-python/tox-current-env/
|
||||
|
||||
Limitations
|
||||
-----------
|
||||
@ -64,14 +79,13 @@ Limitations
|
||||
This macro changes shebang lines of every Python script in `%{buildroot}%{_bindir}` to `#! %{__python3} %{py3_shbang_opt}` (`#! /usr/bin/python3 -s`).
|
||||
We plan to preserve existing Python flags in shebangs, but the work is not yet finished.
|
||||
|
||||
The PEPs don't (yet) define a way to specify test dependencies and test runners.
|
||||
That means you still need to handle test dependencies and `%check` on your own.
|
||||
|
||||
Extras are currently ignored.
|
||||
|
||||
Some valid Python version specifiers are not supported.
|
||||
|
||||
The `-x` flag does not yet support multiple (comma-separated) extras.
|
||||
|
||||
The `-t` flag does not yet support a reasonable default.
|
||||
|
||||
[PEP 517]: https://www.python.org/dev/peps/pep-0517/
|
||||
[PEP 518]: https://www.python.org/dev/peps/pep-0518/
|
||||
|
@ -17,7 +17,7 @@ if [ -d %{buildroot}%{python3_sitearch} ]; then
|
||||
fi
|
||||
}
|
||||
|
||||
%pyproject_buildrequires(rx:) %{expand:\\\
|
||||
%pyproject_buildrequires(rx:t:) %{expand:\\\
|
||||
echo 'python3-devel'
|
||||
echo 'python3dist(packaging)'
|
||||
echo 'python3dist(pip) >= 19'
|
||||
|
@ -6,7 +6,7 @@ License: MIT
|
||||
|
||||
# Keep the version at zero and increment only release
|
||||
Version: 0
|
||||
Release: 4%{?dist}
|
||||
Release: 5%{?dist}
|
||||
|
||||
Source0: macros.pyproject
|
||||
Source1: pyproject_buildrequires.py
|
||||
@ -35,6 +35,7 @@ BuildRequires: python3dist(packaging)
|
||||
BuildRequires: python3dist(pytoml)
|
||||
BuildRequires: python3dist(pip)
|
||||
BuildRequires: python3dist(setuptools)
|
||||
BuildRequires: python3dist(tox-current-env)
|
||||
BuildRequires: python3dist(wheel)
|
||||
%endif
|
||||
|
||||
@ -75,6 +76,9 @@ install -m 644 pyproject_buildrequires.py %{buildroot}%{_rpmconfigdir}/redhat/
|
||||
%license LICENSE
|
||||
|
||||
%changelog
|
||||
* Fri Jul 26 2019 Miro Hrončok <mhroncok@redhat.com> - 0-5
|
||||
- Allow to fetch test dependencies from tox
|
||||
|
||||
* Fri Jul 26 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0-4
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
|
||||
|
||||
|
@ -174,6 +174,19 @@ def generate_run_requirements(backend, requirements):
|
||||
requirements.extend(requires, source=f'wheel metadata: {key}')
|
||||
|
||||
|
||||
def generate_tox_requirements(toxenv, requirements):
|
||||
requirements.extend(['tox-current-env'], source='tox itself')
|
||||
tox_output = subprocess.run(
|
||||
['tox', '--print-deps-only', '-qre', toxenv],
|
||||
encoding='utf-8',
|
||||
stdout=subprocess.PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
lines = tox_output.splitlines()
|
||||
summary = lines.index(35 * '_' + ' summary ' + 36 * '_')
|
||||
requirements.extend(lines[:summary], source=f'tox --print-deps-only: {toxenv}')
|
||||
|
||||
|
||||
def python3dist(name, op=None, version=None):
|
||||
if op is None:
|
||||
if version is not None:
|
||||
@ -191,6 +204,9 @@ def generate_requires(
|
||||
try:
|
||||
backend = get_backend(requirements)
|
||||
generate_build_requirements(backend, requirements)
|
||||
if toxenv is not None:
|
||||
include_runtime = True
|
||||
generate_tox_requirements(toxenv, requirements)
|
||||
if include_runtime:
|
||||
generate_run_requirements(backend, requirements)
|
||||
except EndPass:
|
||||
@ -207,8 +223,8 @@ def main(argv):
|
||||
)
|
||||
parser.add_argument(
|
||||
'-t', '--toxenv', metavar='TOXENVS',
|
||||
help='generate test tequirements from tox environment '
|
||||
+ '(not implemented; implies --runtime)',
|
||||
help=('generate test tequirements from tox environment '
|
||||
'(implies --runtime)'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'-x', '--extras', metavar='EXTRAS', default='',
|
||||
@ -219,10 +235,6 @@ def main(argv):
|
||||
)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
if args.toxenv:
|
||||
args.runtime = True
|
||||
print_err('-t (--toxenv) is not implemented')
|
||||
exit(1)
|
||||
if args.extras and not args.runtime:
|
||||
print_err('-x (--extras) are only useful with -r (--runtime)')
|
||||
exit(1)
|
||||
@ -238,6 +250,7 @@ def main(argv):
|
||||
generate_requires(
|
||||
freeze_output,
|
||||
include_runtime=args.runtime,
|
||||
toxenv=args.toxenv,
|
||||
extras=args.extras,
|
||||
)
|
||||
except Exception as e:
|
||||
|
@ -22,17 +22,16 @@ def test_data(case_name, capsys, tmp_path, monkeypatch):
|
||||
if case.get('xfail'):
|
||||
pytest.xfail(case.get('xfail'))
|
||||
|
||||
if 'pyproject.toml' in case:
|
||||
cwd.joinpath('pyproject.toml').write_text(case['pyproject.toml'])
|
||||
|
||||
if 'setup.py' in case:
|
||||
cwd.joinpath('setup.py').write_text(case['setup.py'])
|
||||
for filename in 'pyproject.toml', 'setup.py', 'tox.ini':
|
||||
if filename in case:
|
||||
cwd.joinpath(filename).write_text(case[filename])
|
||||
|
||||
try:
|
||||
generate_requires(
|
||||
case['freeze_output'],
|
||||
include_runtime=case.get('include_runtime', False),
|
||||
extras=case.get('extras', ''),
|
||||
toxenv=case.get('toxenv', None),
|
||||
)
|
||||
except SystemExit as e:
|
||||
assert e.code == case['result']
|
||||
|
@ -252,3 +252,34 @@ Run dependencies with multiple extras:
|
||||
python3dist(dep3)
|
||||
python3dist(dep4)
|
||||
result: 0
|
||||
|
||||
Tox depndencies:
|
||||
freeze_output: |
|
||||
setuptools==50
|
||||
wheel==1
|
||||
toxenv: py3
|
||||
setup.py: |
|
||||
from setuptools import setup
|
||||
setup(
|
||||
name='test',
|
||||
version='0.1',
|
||||
install_requires=['inst'],
|
||||
)
|
||||
tox.ini: |
|
||||
[tox]
|
||||
envlist = py36,py37,py38
|
||||
[testenv]
|
||||
deps =
|
||||
toxdep1
|
||||
toxdep2
|
||||
commands =
|
||||
true
|
||||
expected: |
|
||||
python3dist(setuptools) >= 40.8
|
||||
python3dist(wheel)
|
||||
python3dist(wheel)
|
||||
python3dist(tox-current-env)
|
||||
python3dist(toxdep1)
|
||||
python3dist(toxdep2)
|
||||
python3dist(inst)
|
||||
result: 0
|
||||
|
51
tests/python-pluggy.spec
Normal file
51
tests/python-pluggy.spec
Normal file
@ -0,0 +1,51 @@
|
||||
%global pypi_name pluggy
|
||||
Name: python-%{pypi_name}
|
||||
Version: 0.12.0
|
||||
Release: 1%{?dist}
|
||||
Summary: The plugin manager stripped of pytest specific details
|
||||
|
||||
License: MIT
|
||||
URL: https://github.com/pytest-dev/pluggy
|
||||
Source0: %{pypi_source}
|
||||
|
||||
BuildArch: noarch
|
||||
BuildRequires: pyproject-rpm-macros
|
||||
|
||||
%description
|
||||
%{summary}.
|
||||
|
||||
|
||||
%package -n python3-%{pypi_name}
|
||||
Summary: %{summary}
|
||||
%{?python_provide:%python_provide python3-%{pypi_name}}
|
||||
|
||||
%description -n python3-%{pypi_name}
|
||||
%{summary}.
|
||||
|
||||
|
||||
%prep
|
||||
%autosetup -p1 -n %{pypi_name}-%{version}
|
||||
|
||||
|
||||
%generate_buildrequires
|
||||
%pyproject_buildrequires -t py%{python3_version_nodots}-pytestrelease
|
||||
|
||||
|
||||
%build
|
||||
%pyproject_wheel
|
||||
|
||||
|
||||
%install
|
||||
%pyproject_install
|
||||
|
||||
|
||||
%check
|
||||
export PYTHONPATH=%{buildroot}%{python3_sitelib}
|
||||
%{__python3} -m pytest
|
||||
|
||||
|
||||
%files -n python3-%{pypi_name}
|
||||
%doc README.rst
|
||||
%license LICENSE
|
||||
%{python3_sitelib}/%{pypi_name}/
|
||||
%{python3_sitelib}/%{pypi_name}-%{version}.dist-info/
|
@ -19,6 +19,9 @@
|
||||
- entrypoints:
|
||||
dir: .
|
||||
run: ./mocktest.sh python-entrypoints
|
||||
- pluggy:
|
||||
dir: .
|
||||
run: ./mocktest.sh python-pluggy
|
||||
required_packages:
|
||||
- mock
|
||||
- rpmdevtools
|
||||
|
Loading…
Reference in New Issue
Block a user