Make %pyproject_buildrequires more universal
so it can work with any non-main Python version and generate proper dependencies.
This commit is contained in:
parent
64e45518ef
commit
5561755a00
@ -71,13 +71,18 @@ fi
|
||||
|
||||
%pyproject_buildrequires(rxte:) %{expand:\\\
|
||||
%{-e:%{expand:%global toxenv %{-e*}}}
|
||||
echo 'python3-devel'
|
||||
echo 'python3dist(packaging)'
|
||||
echo 'python3dist(toml)'
|
||||
echo 'python%{python3_pkgversion}-devel'
|
||||
echo 'python%{python3_pkgversion}dist(pip) >= 19'
|
||||
echo 'python%{python3_pkgversion}dist(packaging)'
|
||||
echo 'python%{python3_pkgversion}dist(toml)'
|
||||
# The first part is for cases when %%{python3_version_nodots} is not yet available
|
||||
if [ ! -z "%{?python3_version_nodots}" ] && [ %{python3_version_nodots} -lt 38 ]; then
|
||||
echo 'python%{python3_pkgversion}dist(importlib-metadata)'
|
||||
fi
|
||||
# setuptools assumes no pre-existing dist-info
|
||||
rm -rfv *.dist-info/ >&2
|
||||
if [ -f %{__python3} ]; then
|
||||
RPM_TOXENV="%{toxenv}" HOSTNAME="rpmbuild" %{__python3} -I %{_rpmconfigdir}/redhat/pyproject_buildrequires.py %{?**}
|
||||
RPM_TOXENV="%{toxenv}" HOSTNAME="rpmbuild" %{__python3} -I %{_rpmconfigdir}/redhat/pyproject_buildrequires.py --python3_pkgversion %{python3_pkgversion} %{?**}
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -32,19 +32,6 @@ URL: https://src.fedoraproject.org/rpms/pyproject-rpm-macros
|
||||
|
||||
BuildArch: noarch
|
||||
|
||||
Requires: python3-pip >= 19
|
||||
Requires: python3-devel
|
||||
|
||||
# We keep these here for now to avoid one loop of %%generate_buildrequires
|
||||
# But those are also always in the output of %%generate_buildrequires
|
||||
# in order to be removable in the future
|
||||
Requires: python3dist(packaging)
|
||||
Requires: python3dist(toml)
|
||||
|
||||
# This is not output from %%generate_buildrequires to work around:
|
||||
# https://github.com/rpm-software-management/mock/issues/336
|
||||
Requires: (python3dist(importlib-metadata) if python3 < 3.8)
|
||||
|
||||
%if %{with tests}
|
||||
BuildRequires: python3dist(pytest)
|
||||
BuildRequires: python3dist(pyyaml)
|
||||
|
@ -47,13 +47,16 @@ def hook_call():
|
||||
|
||||
class Requirements:
|
||||
"""Requirement printer"""
|
||||
def __init__(self, get_installed_version, extras=''):
|
||||
def __init__(self, get_installed_version, extras='',
|
||||
python3_pkgversion='3'):
|
||||
self.get_installed_version = get_installed_version
|
||||
|
||||
self.marker_env = {'extra': extras}
|
||||
|
||||
self.missing_requirements = False
|
||||
|
||||
self.python3_pkgversion = python3_pkgversion
|
||||
|
||||
def add(self, requirement_str, *, source=None):
|
||||
"""Output a Python-style requirement string as RPM dep"""
|
||||
print_err(f'Handling {requirement_str} from {source}')
|
||||
@ -96,15 +99,19 @@ class Requirements:
|
||||
+ '(This is probably a bug in pyproject-rpm-macros.)',
|
||||
)
|
||||
if specifier.operator == '!=':
|
||||
lower = python3dist(name, '<', version)
|
||||
higher = python3dist(name, '>', f'{version}.0')
|
||||
lower = python3dist(name, '<', version,
|
||||
self.python3_pkgversion)
|
||||
higher = python3dist(name, '>', f'{version}.0',
|
||||
self.python3_pkgversion)
|
||||
together.append(
|
||||
f'({lower} or {higher})'
|
||||
)
|
||||
else:
|
||||
together.append(python3dist(name, specifier.operator, version))
|
||||
together.append(python3dist(name, specifier.operator, version,
|
||||
self.python3_pkgversion))
|
||||
if len(together) == 0:
|
||||
print(python3dist(name))
|
||||
print(python3dist(name,
|
||||
python3_pkgversion=self.python3_pkgversion))
|
||||
elif len(together) == 1:
|
||||
print(together[0])
|
||||
else:
|
||||
@ -228,24 +235,30 @@ def generate_tox_requirements(toxenv, requirements):
|
||||
source=f'tox --print-deps-only: {toxenv}')
|
||||
|
||||
|
||||
def python3dist(name, op=None, version=None):
|
||||
def python3dist(name, op=None, version=None, python3_pkgversion="3"):
|
||||
prefix = f"python{python3_pkgversion}dist"
|
||||
|
||||
if op is None:
|
||||
if version is not None:
|
||||
raise AssertionError('op and version go together')
|
||||
return f'python3dist({name})'
|
||||
return f'{prefix}({name})'
|
||||
else:
|
||||
return f'python3dist({name}) {op} {version}'
|
||||
return f'{prefix}({name}) {op} {version}'
|
||||
|
||||
|
||||
def generate_requires(
|
||||
*, include_runtime=False, toxenv=None, extras='',
|
||||
get_installed_version=importlib_metadata.version, # for dep injection
|
||||
python3_pkgversion="3",
|
||||
):
|
||||
"""Generate the BuildRequires for the project in the current directory
|
||||
|
||||
This is the main Python entry point.
|
||||
"""
|
||||
requirements = Requirements(get_installed_version, extras=extras)
|
||||
requirements = Requirements(
|
||||
get_installed_version, extras=extras,
|
||||
python3_pkgversion=python3_pkgversion
|
||||
)
|
||||
|
||||
try:
|
||||
backend = get_backend(requirements)
|
||||
@ -285,6 +298,11 @@ def main(argv):
|
||||
# help='comma separated list of "extras" for runtime requirements '
|
||||
# + '(e.g. -x testing,feature-x)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-p', '--python3_pkgversion', metavar='PYTHON3_PKGVERSION',
|
||||
default="3", help=('Python version for pythonXdist()'
|
||||
'or pythonX.Ydist() requirements'),
|
||||
)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
@ -304,6 +322,7 @@ def main(argv):
|
||||
include_runtime=args.runtime,
|
||||
toxenv=args.toxenv,
|
||||
extras=args.extras,
|
||||
python3_pkgversion=args.python3_pkgversion,
|
||||
)
|
||||
except Exception:
|
||||
# Log the traceback explicitly (it's useful debug info)
|
||||
|
Loading…
Reference in New Issue
Block a user