-t means "use tox", -e means "use this toxenv", -e implies -t

Further fixes
This commit is contained in:
Miro Hrončok 2019-08-13 14:42:21 +02:00
parent c975fbe6ec
commit fda0a23075
7 changed files with 45 additions and 27 deletions

View File

@ -56,30 +56,31 @@ For example, if upstream suggests installing test dependencies with
%pyproject_buildrequires -r -x testing %pyproject_buildrequires -r -x testing
For projects that specify test requirements in their [tox] configuration, For projects that specify test requirements in their [tox] configuration,
these can be added using the `-t` flag followed by the tox environment. these can be added using the `-t` flag (default tox environment)
The recommended tox environment (such as `py37` assuming the Fedora's Python version is 3.7) or the `-e` flag followed by the tox environment.
The default tox environment (such as `py37` assuming the Fedora's Python version is 3.7)
is available in the `%{toxenv}` macro. is available in the `%{toxenv}` macro.
For example, if upstream suggests running the tests on Python 3.7 with `tox -e py37`, For example, if upstream suggests running the tests on Python 3.7 with `tox -e py37`,
the test deps would be generated by: the test deps would be generated by:
%generate_buildrequires %generate_buildrequires
%pyproject_buildrequires -t %{toxenv} %pyproject_buildrequires -t
If upstream uses a custom derived environment, such as `py37-unit`, use: If upstream uses a custom derived environment, such as `py37-unit`, use:
%pyproject_buildrequires -t %{toxenv}-unit %pyproject_buildrequires -e %{toxenv}-unit
Or specify more environments if needed: Or specify more environments if needed:
%pyproject_buildrequires -t %{toxenv}-unit,%{toxenv}-integration %pyproject_buildrequires -e %{toxenv}-unit,%{toxenv}-integration
The `-t` option redefines `%{toxenv}` for further reuse. The `-e` option redefines `%{toxenv}` for further reuse.
Use `%{default_toxenv}` to get the default value. Use `%{default_toxenv}` to get the default value.
Note that `-t` implies `-r`, because tox normally assumes the package is installed Note that `-t` implies `-r`, because tox normally assumes the package is installed
including all the runtime dependencies. including all the runtime dependencies.
The `-t` option uses [tox-current-env]'s `--print-deps-only` behind the scenes. The `-t`/`-e` option uses [tox-current-env]'s `--print-deps-to-file` behind the scenes.
[tox]: https://tox.readthedocs.io/ [tox]: https://tox.readthedocs.io/
[tox-current-env]: https://github.com/fedora-python/tox-current-env/ [tox-current-env]: https://github.com/fedora-python/tox-current-env/
@ -122,8 +123,8 @@ Or (note the two sequential `--`s):
%tox -- -- --flag-for-posargs %tox -- -- --flag-for-posargs
**Warning:** This macro assumes you have used `%pyproject_buildrequires -t` in **Warning:** This macro assumes you have used `%pyproject_buildrequires -t` or `-e`
`%generate_buildrequires`. If not, you need to add: in `%generate_buildrequires`. If not, you need to add:
BuildRequires: python3dist(tox-current-env) BuildRequires: python3dist(tox-current-env)
@ -141,7 +142,5 @@ Some valid Python version specifiers are not supported.
The `-x` flag does not yet support multiple (comma-separated) extras. The `-x` flag does not yet support multiple (comma-separated) extras.
The `-t` flag does not yet support being used without a value.
[PEP 517]: https://www.python.org/dev/peps/pep-0517/ [PEP 517]: https://www.python.org/dev/peps/pep-0517/
[PEP 518]: https://www.python.org/dev/peps/pep-0518/ [PEP 518]: https://www.python.org/dev/peps/pep-0518/

View File

@ -20,8 +20,8 @@ fi
%default_toxenv py%{python3_version_nodots} %default_toxenv py%{python3_version_nodots}
%toxenv %{default_toxenv} %toxenv %{default_toxenv}
%pyproject_buildrequires(rx:t:) %{expand:\\\ %pyproject_buildrequires(rxte:) %{expand:\\\
%{-t:%{expand:%global toxenv %{-t*}}} %{-e:%{expand:%global toxenv %{-e*}}}
echo 'python3-devel' echo 'python3-devel'
echo 'python3dist(packaging)' echo 'python3dist(packaging)'
echo 'python3dist(pip) >= 19' echo 'python3dist(pip) >= 19'
@ -29,7 +29,7 @@ echo 'python3dist(pytoml)'
# setuptools assumes no pre-existing dist-info # setuptools assumes no pre-existing dist-info
rm -rfv *.dist-info/ rm -rfv *.dist-info/
if [ -f %{__python3} ]; then if [ -f %{__python3} ]; then
%{__python3} -I %{_rpmconfigdir}/redhat/pyproject_buildrequires.py %{?**} RPM_TOXENV=%{toxenv} %{__python3} -I %{_rpmconfigdir}/redhat/pyproject_buildrequires.py %{?**}
fi fi
} }

View File

@ -35,7 +35,7 @@ BuildRequires: python3dist(packaging)
BuildRequires: python3dist(pytoml) BuildRequires: python3dist(pytoml)
BuildRequires: python3dist(pip) BuildRequires: python3dist(pip)
BuildRequires: python3dist(setuptools) BuildRequires: python3dist(setuptools)
BuildRequires: python3dist(tox-current-env) BuildRequires: python3dist(tox-current-env) >= 0.0.2
BuildRequires: python3dist(wheel) BuildRequires: python3dist(wheel)
%endif %endif

View File

@ -1,3 +1,4 @@
import os
import sys import sys
import importlib import importlib
import argparse import argparse
@ -176,13 +177,18 @@ def generate_run_requirements(backend, requirements):
def generate_tox_requirements(toxenv, requirements): def generate_tox_requirements(toxenv, requirements):
requirements.extend(['tox-current-env >= 0.0.2'], source='tox itself') requirements.add('tox-current-env >= 0.0.2', source='tox itself')
requirements.check(source='tox itself')
with tempfile.NamedTemporaryFile('r') as depfile: with tempfile.NamedTemporaryFile('r') as depfile:
with hook_call(): r = subprocess.run(
subprocess.run( ['tox', '--print-deps-to-file', depfile.name, '-qre', toxenv],
['tox', '--print-deps-to-file', depfile.name, '-qre', toxenv], check=True,
check=True, encoding='utf-8',
) stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if r.stdout:
print_err(r.stdout)
requirements.extend(depfile.read().splitlines(), requirements.extend(depfile.read().splitlines(),
source=f'tox --print-deps-only: {toxenv}') source=f'tox --print-deps-only: {toxenv}')
@ -222,7 +228,12 @@ def main(argv):
help='Generate run-time requirements', help='Generate run-time requirements',
) )
parser.add_argument( parser.add_argument(
'-t', '--toxenv', metavar='TOXENVS', '-e', '--toxenv', metavar='TOXENVS', default=None,
help=('specify tox environments'
'(implies --tox)'),
)
parser.add_argument(
'-t', '--tox', action='store_true',
help=('generate test tequirements from tox environment ' help=('generate test tequirements from tox environment '
'(implies --runtime)'), '(implies --runtime)'),
) )
@ -235,8 +246,15 @@ def main(argv):
) )
args = parser.parse_args(argv) args = parser.parse_args(argv)
if args.toxenv: if args.toxenv:
args.tox = True
if args.tox:
args.runtime = True args.runtime = True
args.toxenv = (args.toxenv or os.getenv('RPM_TOXENV') or
f'py{sys.version_info.major}{sys.version_info.minor}')
if args.extras and not args.runtime: if args.extras and not args.runtime:
print_err('-x (--extras) are only useful with -r (--runtime)') print_err('-x (--extras) are only useful with -r (--runtime)')
exit(1) exit(1)
@ -255,7 +273,7 @@ def main(argv):
toxenv=args.toxenv, toxenv=args.toxenv,
extras=args.extras, extras=args.extras,
) )
except Exception as e: except Exception:
# Log the traceback explicitly (it's useful debug info) # Log the traceback explicitly (it's useful debug info)
traceback.print_exc() traceback.print_exc()
exit(1) exit(1)

View File

@ -257,6 +257,8 @@ Tox depndencies:
freeze_output: | freeze_output: |
setuptools==50 setuptools==50
wheel==1 wheel==1
tox==3.5.3
tox-current-env==0.0.2
toxenv: py3 toxenv: py3
setup.py: | setup.py: |
from setuptools import setup from setuptools import setup

View File

@ -28,7 +28,7 @@ Summary: %{summary}
%generate_buildrequires %generate_buildrequires
%pyproject_buildrequires -t %{toxenv}-pytestrelease %pyproject_buildrequires -e %{toxenv}-pytestrelease
%build %build

View File

@ -27,7 +27,7 @@ py.test provides simple, yet powerful testing for Python.
%generate_buildrequires %generate_buildrequires
%pyproject_buildrequires -r -x testing %pyproject_buildrequires -x testing -t
%build %build
@ -40,8 +40,7 @@ py.test provides simple, yet powerful testing for Python.
%check %check
# Only run one test (which uses a test-only dependency, hypothesis). # Only run one test (which uses a test-only dependency, hypothesis).
# (Unfortunately, some other tests still fail.) # (Unfortunately, some other tests still fail.)
export PYTHONPATH=%{buildroot}%{python3_sitelib} %tox -- -- -k metafunc
%{__python3} -m pytest -k metafunc
%files -n python3-%{pypi_name} %files -n python3-%{pypi_name}