diff --git a/README.md b/README.md index 24054d6..7865cd7 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,11 @@ Use `%{default_toxenv}` to get the default value. The `-t`/`-e` option uses [tox-current-env]'s `--print-deps-to-file` behind the scenes. +If your package specifies some tox plugins in `tox.requires`, +such plugins will be BuildRequired as well. +Not all plugins are guaranteed to play well with [tox-current-env], +in worst case, patch/sed the requirement out from the tox configuration. + Note that both `-x` and `-t` imply `-r`, because runtime dependencies are always required for testing. diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index 981ad8b..befcf39 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -12,7 +12,7 @@ License: MIT # In other cases, such as backports, increment the point # release. Version: 0 -Release: 39.1%{?dist} +Release: 39.2%{?dist} # Macro files Source001: macros.pyproject @@ -48,7 +48,7 @@ BuildRequires: python3dist(packaging) BuildRequires: python3dist(pip) BuildRequires: python3dist(setuptools) BuildRequires: python3dist(toml) -BuildRequires: python3dist(tox-current-env) >= 0.0.3 +BuildRequires: python3dist(tox-current-env) >= 0.0.6 BuildRequires: python3dist(wheel) %endif @@ -110,6 +110,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856 %license LICENSE %changelog +* Thu Apr 22 2021 Miro HronĨok - 0-39.2 +- Handle tox provision (tox.requires / tox.minversion) + * Fri Apr 16 2021 Mohan Boddu - 0-39.1 - Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937 diff --git a/pyproject_buildrequires.py b/pyproject_buildrequires.py index 2c9992e..b0ad2ca 100644 --- a/pyproject_buildrequires.py +++ b/pyproject_buildrequires.py @@ -6,6 +6,7 @@ import functools import traceback import contextlib from io import StringIO +import json import subprocess import re import tempfile @@ -248,13 +249,16 @@ def parse_tox_requires_lines(lines): def generate_tox_requirements(toxenv, requirements): toxenv = ','.join(toxenv) - requirements.add('tox-current-env >= 0.0.3', source='tox itself') + requirements.add('tox-current-env >= 0.0.6', source='tox itself') requirements.check(source='tox itself') - with tempfile.NamedTemporaryFile('r') as deps, tempfile.NamedTemporaryFile('r') as extras: + with tempfile.NamedTemporaryFile('r') as deps, \ + tempfile.NamedTemporaryFile('r') as extras, \ + tempfile.NamedTemporaryFile('r') as provision: r = subprocess.run( [sys.executable, '-m', 'tox', '--print-deps-to', deps.name, '--print-extras-to', extras.name, + '--no-provision', provision.name, '-qre', toxenv], check=False, encoding='utf-8', @@ -263,7 +267,22 @@ def generate_tox_requirements(toxenv, requirements): ) if r.stdout: print_err(r.stdout, end='') - r.check_returncode() + + provision_content = provision.read() + if provision_content and r.returncode != 0: + provision_requires = json.loads(provision_content) + if 'minversion' in provision_requires: + requirements.add(f'tox >= {provision_requires["minversion"]}', + source='tox provision (minversion)') + if 'requires' in provision_requires: + requirements.extend(provision_requires["requires"], + source='tox provision (requires)') + requirements.check(source='tox provision') # this terminates the script + raise RuntimeError( + 'Dependencies requested by tox provisioning appear installed, ' + 'but tox disagreed.') + else: + r.check_returncode() deplines = deps.read().splitlines() packages = parse_tox_requires_lines(deplines) diff --git a/pyproject_buildrequires_testcases.yaml b/pyproject_buildrequires_testcases.yaml index d3121e4..cceaca3 100644 --- a/pyproject_buildrequires_testcases.yaml +++ b/pyproject_buildrequires_testcases.yaml @@ -290,7 +290,7 @@ Tox dependencies: setuptools: 50 wheel: 1 tox: 3.5.3 - tox-current-env: 0.0.3 + tox-current-env: 0.0.6 toxenv: - py3 setup.py: | @@ -313,7 +313,7 @@ Tox dependencies: python3dist(setuptools) >= 40.8 python3dist(wheel) python3dist(wheel) - python3dist(tox-current-env) >= 0.0.3 + python3dist(tox-current-env) >= 0.0.6 python3dist(toxdep1) python3dist(toxdep2) python3dist(inst) @@ -324,7 +324,7 @@ Tox extras: setuptools: 50 wheel: 1 tox: 3.5.3 - tox-current-env: 0.0.3 + tox-current-env: 0.0.6 toxenv: - py3 setup.py: | @@ -354,7 +354,7 @@ Tox extras: python3dist(setuptools) >= 40.8 python3dist(wheel) python3dist(wheel) - python3dist(tox-current-env) >= 0.0.3 + python3dist(tox-current-env) >= 0.0.6 python3dist(toxdep) python3dist(inst) python3dist(dep11) > 11 @@ -363,3 +363,74 @@ Tox extras: python3dist(dep22) python3dist(dep23) result: 0 + +Tox provision unsatisfied: + installed: + setuptools: 50 + wheel: 1 + tox: 3.5.3 + tox-current-env: 0.0.6 + toxenv: + - py3 + setup.py: | + from setuptools import setup + setup( + name='test', + version='0.1', + install_requires=['inst'], + ) + tox.ini: | + [tox] + minversion = 3.999 + requires = + setuptools > 40 + wheel > 2 + [testenv] + deps = + toxdep1 + toxdep2 + expected: | + python3dist(setuptools) >= 40.8 + python3dist(wheel) + python3dist(wheel) + python3dist(tox-current-env) >= 0.0.6 + python3dist(tox) >= 3.999 + python3dist(setuptools) > 40 + python3dist(wheel) > 2 + result: 0 + +Tox provision satisfied: + installed: + setuptools: 50 + wheel: 1 + tox: 3.5.3 + tox-current-env: 0.0.6 + toxenv: + - py3 + setup.py: | + from setuptools import setup + setup( + name='test', + version='0.1', + install_requires=['inst'], + ) + tox.ini: | + [tox] + minversion = 3.5 + requires = + setuptools > 40 + [testenv] + deps = + toxdep1 + toxdep2 + expected: | + python3dist(setuptools) >= 40.8 + python3dist(wheel) + python3dist(wheel) + python3dist(tox-current-env) >= 0.0.6 + python3dist(tox) >= 3.5 + python3dist(setuptools) > 40 + python3dist(toxdep1) + python3dist(toxdep2) + python3dist(inst) + result: 0