2019-08-13 12:42:21 +00:00
|
|
|
import os
|
2019-07-02 14:53:05 +00:00
|
|
|
import sys
|
2019-07-17 10:29:05 +00:00
|
|
|
import importlib
|
2019-07-17 13:44:22 +00:00
|
|
|
import argparse
|
|
|
|
import functools
|
|
|
|
import traceback
|
|
|
|
import contextlib
|
|
|
|
from io import StringIO
|
|
|
|
import subprocess
|
|
|
|
import re
|
2019-08-12 15:29:26 +00:00
|
|
|
import tempfile
|
2019-07-17 16:16:16 +00:00
|
|
|
import email.parser
|
2019-07-17 13:44:22 +00:00
|
|
|
|
|
|
|
print_err = functools.partial(print, file=sys.stderr)
|
|
|
|
|
|
|
|
# Some valid Python version specifiers are not supported.
|
|
|
|
# Whitelist characters we can handle.
|
|
|
|
VERSION_RE = re.compile('[a-zA-Z0-9.-]+')
|
|
|
|
|
2019-10-25 15:07:29 +00:00
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
class EndPass(Exception):
|
|
|
|
"""End current pass of generating requirements"""
|
2019-07-02 14:53:05 +00:00
|
|
|
|
2019-10-25 15:07:29 +00:00
|
|
|
|
2019-07-02 14:53:05 +00:00
|
|
|
try:
|
|
|
|
from packaging.requirements import Requirement, InvalidRequirement
|
|
|
|
from packaging.utils import canonicalize_name, canonicalize_version
|
2019-08-10 12:34:24 +00:00
|
|
|
try:
|
|
|
|
import importlib.metadata as importlib_metadata
|
|
|
|
except ImportError:
|
|
|
|
import importlib_metadata
|
2019-07-17 13:44:22 +00:00
|
|
|
except ImportError as e:
|
|
|
|
print_err('Import error:', e)
|
2019-07-02 14:53:05 +00:00
|
|
|
# already echoed by the %pyproject_buildrequires macro
|
|
|
|
sys.exit(0)
|
|
|
|
|
2020-09-09 04:47:51 +00:00
|
|
|
# uses packaging, needs to be imported after packaging is verified to be present
|
|
|
|
from pyproject_convert import convert
|
|
|
|
|
2019-07-02 14:53:05 +00:00
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def hook_call():
|
|
|
|
captured_out = StringIO()
|
|
|
|
with contextlib.redirect_stdout(captured_out):
|
|
|
|
yield
|
|
|
|
for line in captured_out.getvalue().splitlines():
|
|
|
|
print_err('HOOK STDOUT:', line)
|
|
|
|
|
|
|
|
|
|
|
|
class Requirements:
|
|
|
|
"""Requirement printer"""
|
2020-09-30 20:31:07 +00:00
|
|
|
def __init__(self, get_installed_version, extras=None,
|
2020-08-14 12:57:40 +00:00
|
|
|
generate_extras=False, python3_pkgversion='3'):
|
2019-08-10 12:34:24 +00:00
|
|
|
self.get_installed_version = get_installed_version
|
2020-09-30 20:12:03 +00:00
|
|
|
self.extras = set()
|
2019-07-17 13:44:22 +00:00
|
|
|
|
2020-08-11 13:22:05 +00:00
|
|
|
if extras:
|
2020-09-30 20:31:07 +00:00
|
|
|
for extra in extras:
|
|
|
|
self.add_extras(*extra.split(','))
|
2019-07-18 08:50:13 +00:00
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
self.missing_requirements = False
|
|
|
|
|
2020-08-14 12:57:40 +00:00
|
|
|
self.generate_extras = generate_extras
|
2020-07-22 16:13:50 +00:00
|
|
|
self.python3_pkgversion = python3_pkgversion
|
|
|
|
|
2020-09-30 20:12:03 +00:00
|
|
|
def add_extras(self, *extras):
|
|
|
|
self.extras |= set(e.strip() for e in extras)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def marker_envs(self):
|
|
|
|
if self.extras:
|
|
|
|
return [{'extra': e} for e in sorted(self.extras)]
|
|
|
|
return [{'extra': ''}]
|
|
|
|
|
2020-08-11 13:22:05 +00:00
|
|
|
def evaluate_all_environamnets(self, requirement):
|
|
|
|
for marker_env in self.marker_envs:
|
|
|
|
if requirement.marker.evaluate(environment=marker_env):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
def add(self, requirement_str, *, source=None):
|
|
|
|
"""Output a Python-style requirement string as RPM dep"""
|
|
|
|
print_err(f'Handling {requirement_str} from {source}')
|
2019-07-02 14:53:05 +00:00
|
|
|
|
|
|
|
try:
|
2019-07-17 13:44:22 +00:00
|
|
|
requirement = Requirement(requirement_str)
|
|
|
|
except InvalidRequirement as e:
|
|
|
|
print_err(
|
2019-10-25 15:07:29 +00:00
|
|
|
f'WARNING: Skipping invalid requirement: {requirement_str}\n'
|
2019-07-17 13:44:22 +00:00
|
|
|
+ f' {e}',
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
name = canonicalize_name(requirement.name)
|
2019-10-25 15:07:29 +00:00
|
|
|
if (requirement.marker is not None and
|
2020-08-11 13:22:05 +00:00
|
|
|
not self.evaluate_all_environamnets(requirement)):
|
2019-07-17 13:44:22 +00:00
|
|
|
print_err(f'Ignoring alien requirement:', requirement_str)
|
|
|
|
return
|
|
|
|
|
2019-08-10 12:34:24 +00:00
|
|
|
try:
|
2020-08-14 12:57:40 +00:00
|
|
|
# TODO: check if requirements with extras are satisfied
|
2019-08-10 12:34:24 +00:00
|
|
|
installed = self.get_installed_version(requirement.name)
|
|
|
|
except importlib_metadata.PackageNotFoundError:
|
|
|
|
print_err(f'Requirement not satisfied: {requirement_str}')
|
|
|
|
installed = None
|
2019-07-17 13:44:22 +00:00
|
|
|
if installed and installed in requirement.specifier:
|
|
|
|
print_err(f'Requirement satisfied: {requirement_str}')
|
|
|
|
print_err(f' (installed: {requirement.name} {installed})')
|
2020-08-14 12:57:40 +00:00
|
|
|
if requirement.extras:
|
|
|
|
print_err(f' (extras are currently not checked)')
|
2019-07-17 13:44:22 +00:00
|
|
|
else:
|
|
|
|
self.missing_requirements = True
|
|
|
|
|
2020-08-14 12:57:40 +00:00
|
|
|
if self.generate_extras:
|
|
|
|
extra_names = [f'{name}[{extra}]' for extra in sorted(requirement.extras)]
|
2019-07-17 13:44:22 +00:00
|
|
|
else:
|
2020-08-14 12:57:40 +00:00
|
|
|
extra_names = []
|
|
|
|
|
|
|
|
for name in [name] + extra_names:
|
|
|
|
together = []
|
|
|
|
for specifier in sorted(
|
|
|
|
requirement.specifier,
|
|
|
|
key=lambda s: (s.operator, s.version),
|
|
|
|
):
|
|
|
|
version = canonicalize_version(specifier.version)
|
|
|
|
if not VERSION_RE.fullmatch(str(specifier.version)):
|
|
|
|
raise ValueError(
|
|
|
|
f'Unknown character in version: {specifier.version}. '
|
|
|
|
+ '(This is probably a bug in pyproject-rpm-macros.)',
|
|
|
|
)
|
2020-09-09 04:47:51 +00:00
|
|
|
together.append(convert(python3dist(name, python3_pkgversion=self.python3_pkgversion),
|
|
|
|
specifier.operator, version))
|
2020-08-14 12:57:40 +00:00
|
|
|
if len(together) == 0:
|
|
|
|
print(python3dist(name,
|
|
|
|
python3_pkgversion=self.python3_pkgversion))
|
|
|
|
elif len(together) == 1:
|
|
|
|
print(together[0])
|
|
|
|
else:
|
2020-09-09 04:47:51 +00:00
|
|
|
print(f"({' with '.join(together)})")
|
2019-07-17 13:44:22 +00:00
|
|
|
|
|
|
|
def check(self, *, source=None):
|
|
|
|
"""End current pass if any unsatisfied dependencies were output"""
|
|
|
|
if self.missing_requirements:
|
|
|
|
print_err(f'Exiting dependency generation pass: {source}')
|
|
|
|
raise EndPass(source)
|
|
|
|
|
|
|
|
def extend(self, requirement_strs, *, source=None):
|
|
|
|
"""add() several requirements"""
|
|
|
|
for req_str in requirement_strs:
|
|
|
|
self.add(req_str, source=source)
|
2019-07-02 14:53:05 +00:00
|
|
|
|
2019-10-25 15:07:29 +00:00
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
def get_backend(requirements):
|
|
|
|
try:
|
|
|
|
f = open('pyproject.toml')
|
|
|
|
except FileNotFoundError:
|
|
|
|
pyproject_data = {}
|
2019-07-17 10:29:05 +00:00
|
|
|
else:
|
2020-09-04 09:49:36 +00:00
|
|
|
# lazy import toml here, not needed without pyproject.toml
|
|
|
|
requirements.add('toml', source='parsing pyproject.toml')
|
|
|
|
requirements.check(source='parsing pyproject.toml')
|
|
|
|
import toml
|
2019-07-17 13:44:22 +00:00
|
|
|
with f:
|
2020-06-19 19:49:54 +00:00
|
|
|
pyproject_data = toml.load(f)
|
2019-07-17 13:44:22 +00:00
|
|
|
|
2019-10-25 15:07:29 +00:00
|
|
|
buildsystem_data = pyproject_data.get('build-system', {})
|
2019-07-17 13:44:22 +00:00
|
|
|
requirements.extend(
|
2019-10-25 15:07:29 +00:00
|
|
|
buildsystem_data.get('requires', ()),
|
2019-07-17 13:44:22 +00:00
|
|
|
source='build-system.requires',
|
|
|
|
)
|
|
|
|
|
|
|
|
backend_name = buildsystem_data.get('build-backend')
|
|
|
|
if not backend_name:
|
Handle backends with colon, fallback to setuptools.build_meta:__legacy__
Falling back to setuptools.build_meta:__legacy__ is the standard behavior,
not setuptools.build_meta. See PEP 517:
https://www.python.org/dev/peps/pep-0517/
> If the pyproject.toml file is absent, or the build-backend key is missing,
> the source tree is not using this specification, and tools should revert
> to the legacy behaviour of running setup.py (either directly, or by
> implicitly invoking the setuptools.build_meta:__legacy__ backend).
Falling back to setuptools.build_meta had very similar results so far.,
but the behavior might change in the feature.
While working on this, I have uncovered a problem in our code.
It was not able to handle backends with ":". Looking at PEP 517 again:
> build-backend is a string naming a Python object that will be used to
> perform the build. This is formatted following the same module:object syntax
> as a setuptools entry point. For instance, if the string is "flit.api:main",
> this object would be looked up by executing the equivalent of:
>
> import flit.api
> backend = flit.api.main
>
> It's also legal to leave out the :object part, e.g.
>
> build-backend = "flit.api"
>
> which acts like:
>
> import flit.api
> backend = flit.api
We now handle such cases properly. Witch the change of the default backend,
we also test a backend with colon in our tests.
2020-02-05 12:10:51 +00:00
|
|
|
# https://www.python.org/dev/peps/pep-0517/:
|
|
|
|
# If the pyproject.toml file is absent, or the build-backend key is
|
|
|
|
# missing, the source tree is not using this specification, and tools
|
|
|
|
# should revert to the legacy behaviour of running setup.py
|
|
|
|
# (either directly, or by implicitly invoking the [following] backend).
|
|
|
|
backend_name = 'setuptools.build_meta:__legacy__'
|
|
|
|
|
2019-10-25 15:07:29 +00:00
|
|
|
requirements.add('setuptools >= 40.8', source='default build backend')
|
|
|
|
requirements.add('wheel', source='default build backend')
|
2019-07-17 13:44:22 +00:00
|
|
|
|
|
|
|
requirements.check(source='build backend')
|
|
|
|
|
|
|
|
backend_path = buildsystem_data.get('backend-path')
|
|
|
|
if backend_path:
|
2020-10-05 22:30:45 +00:00
|
|
|
# PEP 517 example shows the path as a list, but some projects don't follow that
|
|
|
|
if isinstance(backend_path, str):
|
|
|
|
backend_path = [backend_path]
|
|
|
|
sys.path = backend_path + sys.path
|
2019-07-17 13:44:22 +00:00
|
|
|
|
Handle backends with colon, fallback to setuptools.build_meta:__legacy__
Falling back to setuptools.build_meta:__legacy__ is the standard behavior,
not setuptools.build_meta. See PEP 517:
https://www.python.org/dev/peps/pep-0517/
> If the pyproject.toml file is absent, or the build-backend key is missing,
> the source tree is not using this specification, and tools should revert
> to the legacy behaviour of running setup.py (either directly, or by
> implicitly invoking the setuptools.build_meta:__legacy__ backend).
Falling back to setuptools.build_meta had very similar results so far.,
but the behavior might change in the feature.
While working on this, I have uncovered a problem in our code.
It was not able to handle backends with ":". Looking at PEP 517 again:
> build-backend is a string naming a Python object that will be used to
> perform the build. This is formatted following the same module:object syntax
> as a setuptools entry point. For instance, if the string is "flit.api:main",
> this object would be looked up by executing the equivalent of:
>
> import flit.api
> backend = flit.api.main
>
> It's also legal to leave out the :object part, e.g.
>
> build-backend = "flit.api"
>
> which acts like:
>
> import flit.api
> backend = flit.api
We now handle such cases properly. Witch the change of the default backend,
we also test a backend with colon in our tests.
2020-02-05 12:10:51 +00:00
|
|
|
module_name, _, object_name = backend_name.partition(":")
|
|
|
|
backend_module = importlib.import_module(module_name)
|
|
|
|
|
|
|
|
if object_name:
|
|
|
|
return getattr(backend_module, object_name)
|
|
|
|
|
|
|
|
return backend_module
|
2019-07-02 14:53:05 +00:00
|
|
|
|
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
def generate_build_requirements(backend, requirements):
|
2019-10-25 15:07:29 +00:00
|
|
|
get_requires = getattr(backend, 'get_requires_for_build_wheel', None)
|
2019-07-17 13:44:22 +00:00
|
|
|
if get_requires:
|
|
|
|
with hook_call():
|
|
|
|
new_reqs = get_requires()
|
|
|
|
requirements.extend(new_reqs, source='get_requires_for_build_wheel')
|
2020-09-23 09:10:30 +00:00
|
|
|
requirements.check(source='get_requires_for_build_wheel')
|
2019-07-02 14:53:05 +00:00
|
|
|
|
|
|
|
|
2019-07-17 16:16:16 +00:00
|
|
|
def generate_run_requirements(backend, requirements):
|
2019-10-25 15:07:29 +00:00
|
|
|
hook_name = 'prepare_metadata_for_build_wheel'
|
|
|
|
prepare_metadata = getattr(backend, hook_name, None)
|
2019-07-17 16:16:16 +00:00
|
|
|
if not prepare_metadata:
|
|
|
|
raise ValueError(
|
|
|
|
'build backend cannot provide build metadata '
|
|
|
|
+ '(incl. runtime requirements) before buld'
|
|
|
|
)
|
|
|
|
with hook_call():
|
|
|
|
dir_basename = prepare_metadata('.')
|
|
|
|
with open(dir_basename + '/METADATA') as f:
|
|
|
|
message = email.parser.Parser().parse(f, headersonly=True)
|
|
|
|
for key in 'Requires', 'Requires-Dist':
|
|
|
|
requires = message.get_all(key, ())
|
|
|
|
requirements.extend(requires, source=f'wheel metadata: {key}')
|
|
|
|
|
|
|
|
|
2020-03-02 10:56:15 +00:00
|
|
|
def parse_tox_requires_lines(lines):
|
|
|
|
packages = []
|
|
|
|
for line in lines:
|
|
|
|
line = line.strip()
|
|
|
|
if line.startswith('-r'):
|
|
|
|
path = line[2:]
|
|
|
|
with open(path) as f:
|
|
|
|
packages.extend(parse_tox_requires_lines(f.read().splitlines()))
|
|
|
|
elif line.startswith('-'):
|
|
|
|
print_err(
|
|
|
|
f'WARNING: Skipping dependency line: {line}\n'
|
|
|
|
+ f' tox deps options other than -r are not supported (yet).',
|
|
|
|
)
|
2020-09-30 21:25:03 +00:00
|
|
|
elif line:
|
2020-03-02 10:56:15 +00:00
|
|
|
packages.append(line)
|
|
|
|
return packages
|
|
|
|
|
|
|
|
|
2019-07-26 12:34:21 +00:00
|
|
|
def generate_tox_requirements(toxenv, requirements):
|
2020-11-03 10:29:50 +00:00
|
|
|
toxenv = ','.join(toxenv)
|
2020-09-30 20:12:03 +00:00
|
|
|
requirements.add('tox-current-env >= 0.0.3', source='tox itself')
|
2019-08-13 12:42:21 +00:00
|
|
|
requirements.check(source='tox itself')
|
2020-09-30 20:12:03 +00:00
|
|
|
with tempfile.NamedTemporaryFile('r') as deps, tempfile.NamedTemporaryFile('r') as extras:
|
2019-08-13 12:42:21 +00:00
|
|
|
r = subprocess.run(
|
2020-09-30 20:12:03 +00:00
|
|
|
[sys.executable, '-m', 'tox',
|
|
|
|
'--print-deps-to', deps.name,
|
|
|
|
'--print-extras-to', extras.name,
|
|
|
|
'-qre', toxenv],
|
When tox fails, print tox output before failing
Previously, it wasn't possible to see why tox failed:
...
Requirement satisfied: tox-current-env >= 0.0.2
(installed: tox-current-env 0.0.2)
Traceback (most recent call last):
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 269, in main
generate_requires(
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 221, in generate_requires
generate_tox_requirements(toxenv, requirements)
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 184, in generate_tox_requirements
r = subprocess.run(
File "/usr/lib64/python3.8/subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['tox', '--print-deps-to-file', '/tmp/tmp96smu4rv', '-qre', 'py38']' returned non-zero exit status 1.
Now it is:
...
Requirement satisfied: tox-current-env >= 0.0.2
(installed: tox-current-env 0.0.2)
ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found
Traceback (most recent call last):
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 270, in main
generate_requires(
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 222, in generate_requires
generate_tox_requirements(toxenv, requirements)
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 193, in generate_tox_requirements
r.check_returncode()
File "/usr/lib64/python3.8/subprocess.py", line 444, in check_returncode
raise CalledProcessError(self.returncode, self.args, self.stdout,
subprocess.CalledProcessError: Command '['tox', '--print-deps-to-file', '/tmp/tmpwp8sffv1', '-qre', 'py38']' returned non-zero exit status 1.
Inspired by https://src.fedoraproject.org/rpms/python-chaospy/pull-request/1#comment-32750
2019-10-25 14:51:01 +00:00
|
|
|
check=False,
|
2019-08-13 12:42:21 +00:00
|
|
|
encoding='utf-8',
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
)
|
|
|
|
if r.stdout:
|
When tox fails, print tox output before failing
Previously, it wasn't possible to see why tox failed:
...
Requirement satisfied: tox-current-env >= 0.0.2
(installed: tox-current-env 0.0.2)
Traceback (most recent call last):
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 269, in main
generate_requires(
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 221, in generate_requires
generate_tox_requirements(toxenv, requirements)
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 184, in generate_tox_requirements
r = subprocess.run(
File "/usr/lib64/python3.8/subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['tox', '--print-deps-to-file', '/tmp/tmp96smu4rv', '-qre', 'py38']' returned non-zero exit status 1.
Now it is:
...
Requirement satisfied: tox-current-env >= 0.0.2
(installed: tox-current-env 0.0.2)
ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found
Traceback (most recent call last):
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 270, in main
generate_requires(
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 222, in generate_requires
generate_tox_requirements(toxenv, requirements)
File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 193, in generate_tox_requirements
r.check_returncode()
File "/usr/lib64/python3.8/subprocess.py", line 444, in check_returncode
raise CalledProcessError(self.returncode, self.args, self.stdout,
subprocess.CalledProcessError: Command '['tox', '--print-deps-to-file', '/tmp/tmpwp8sffv1', '-qre', 'py38']' returned non-zero exit status 1.
Inspired by https://src.fedoraproject.org/rpms/python-chaospy/pull-request/1#comment-32750
2019-10-25 14:51:01 +00:00
|
|
|
print_err(r.stdout, end='')
|
|
|
|
r.check_returncode()
|
2020-03-02 10:56:15 +00:00
|
|
|
|
2020-09-30 20:12:03 +00:00
|
|
|
deplines = deps.read().splitlines()
|
2020-03-02 10:56:15 +00:00
|
|
|
packages = parse_tox_requires_lines(deplines)
|
2020-09-30 20:12:03 +00:00
|
|
|
requirements.add_extras(*extras.read().splitlines())
|
2020-03-02 10:56:15 +00:00
|
|
|
requirements.extend(packages,
|
2019-08-12 15:29:26 +00:00
|
|
|
source=f'tox --print-deps-only: {toxenv}')
|
2019-07-26 12:34:21 +00:00
|
|
|
|
|
|
|
|
2020-07-22 16:13:50 +00:00
|
|
|
def python3dist(name, op=None, version=None, python3_pkgversion="3"):
|
|
|
|
prefix = f"python{python3_pkgversion}dist"
|
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
if op is None:
|
|
|
|
if version is not None:
|
|
|
|
raise AssertionError('op and version go together')
|
2020-07-22 16:13:50 +00:00
|
|
|
return f'{prefix}({name})'
|
2019-07-17 13:44:22 +00:00
|
|
|
else:
|
2020-07-22 16:13:50 +00:00
|
|
|
return f'{prefix}({name}) {op} {version}'
|
2019-07-17 13:44:22 +00:00
|
|
|
|
|
|
|
|
2019-07-18 08:50:13 +00:00
|
|
|
def generate_requires(
|
2020-09-30 20:31:07 +00:00
|
|
|
*, include_runtime=False, toxenv=None, extras=None,
|
2019-08-10 12:34:24 +00:00
|
|
|
get_installed_version=importlib_metadata.version, # for dep injection
|
2020-08-14 12:57:40 +00:00
|
|
|
generate_extras=False, python3_pkgversion="3",
|
2019-07-18 08:50:13 +00:00
|
|
|
):
|
2019-08-10 12:34:24 +00:00
|
|
|
"""Generate the BuildRequires for the project in the current directory
|
|
|
|
|
|
|
|
This is the main Python entry point.
|
|
|
|
"""
|
2020-07-22 16:13:50 +00:00
|
|
|
requirements = Requirements(
|
2020-09-30 20:31:07 +00:00
|
|
|
get_installed_version, extras=extras or [],
|
2020-08-14 12:57:40 +00:00
|
|
|
generate_extras=generate_extras,
|
2020-07-22 16:13:50 +00:00
|
|
|
python3_pkgversion=python3_pkgversion
|
|
|
|
)
|
2019-07-17 13:44:22 +00:00
|
|
|
|
2019-07-02 14:53:05 +00:00
|
|
|
try:
|
2019-07-17 13:44:22 +00:00
|
|
|
backend = get_backend(requirements)
|
|
|
|
generate_build_requirements(backend, requirements)
|
2020-11-03 10:29:50 +00:00
|
|
|
if toxenv:
|
2019-07-26 12:34:21 +00:00
|
|
|
include_runtime = True
|
|
|
|
generate_tox_requirements(toxenv, requirements)
|
2019-07-17 16:16:16 +00:00
|
|
|
if include_runtime:
|
|
|
|
generate_run_requirements(backend, requirements)
|
2019-07-17 13:44:22 +00:00
|
|
|
except EndPass:
|
2019-07-17 14:25:20 +00:00
|
|
|
return
|
2019-07-17 13:44:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Generate BuildRequires for a Python project.'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2019-07-17 16:16:16 +00:00
|
|
|
'-r', '--runtime', action='store_true',
|
2019-07-18 07:24:02 +00:00
|
|
|
help='Generate run-time requirements',
|
2019-07-17 13:44:22 +00:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
2020-11-03 10:29:50 +00:00
|
|
|
'-e', '--toxenv', metavar='TOXENVS', action='append',
|
|
|
|
help=('specify tox environments (comma separated and/or repeated)'
|
2019-08-13 12:42:21 +00:00
|
|
|
'(implies --tox)'),
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-t', '--tox', action='store_true',
|
2019-07-26 12:34:21 +00:00
|
|
|
help=('generate test tequirements from tox environment '
|
|
|
|
'(implies --runtime)'),
|
2019-07-17 13:44:22 +00:00
|
|
|
)
|
2019-07-18 08:50:13 +00:00
|
|
|
parser.add_argument(
|
2020-09-30 20:31:07 +00:00
|
|
|
'-x', '--extras', metavar='EXTRAS', action='append',
|
2020-08-11 13:22:05 +00:00
|
|
|
help='comma separated list of "extras" for runtime requirements '
|
2020-09-30 20:31:07 +00:00
|
|
|
'(e.g. -x testing,feature-x) (implies --runtime, can be repeated)',
|
2019-07-18 08:50:13 +00:00
|
|
|
)
|
2020-08-14 12:57:40 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--generate-extras', action='store_true',
|
|
|
|
help='Generate build requirements on Python Extras',
|
|
|
|
)
|
2020-07-22 16:13:50 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-p', '--python3_pkgversion', metavar='PYTHON3_PKGVERSION',
|
|
|
|
default="3", help=('Python version for pythonXdist()'
|
|
|
|
'or pythonX.Ydist() requirements'),
|
|
|
|
)
|
2019-07-17 13:44:22 +00:00
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
2019-08-13 12:42:21 +00:00
|
|
|
|
2019-08-13 12:05:14 +00:00
|
|
|
if args.toxenv:
|
2019-08-13 12:42:21 +00:00
|
|
|
args.tox = True
|
|
|
|
|
|
|
|
if args.tox:
|
2019-08-13 12:05:14 +00:00
|
|
|
args.runtime = True
|
2020-11-03 10:29:50 +00:00
|
|
|
if not args.toxenv:
|
|
|
|
_default = f'py{sys.version_info.major}{sys.version_info.minor}'
|
|
|
|
args.toxenv = [os.getenv('RPM_TOXENV', _default)]
|
2019-08-13 12:42:21 +00:00
|
|
|
|
2020-07-16 11:35:02 +00:00
|
|
|
if args.extras:
|
|
|
|
args.runtime = True
|
2019-07-17 13:44:22 +00:00
|
|
|
|
|
|
|
try:
|
2019-07-18 08:50:13 +00:00
|
|
|
generate_requires(
|
|
|
|
include_runtime=args.runtime,
|
2019-07-26 12:34:21 +00:00
|
|
|
toxenv=args.toxenv,
|
2019-07-18 08:50:13 +00:00
|
|
|
extras=args.extras,
|
2020-08-14 12:57:40 +00:00
|
|
|
generate_extras=args.generate_extras,
|
2020-07-22 16:13:50 +00:00
|
|
|
python3_pkgversion=args.python3_pkgversion,
|
2019-07-18 08:50:13 +00:00
|
|
|
)
|
2019-08-13 12:42:21 +00:00
|
|
|
except Exception:
|
2019-07-17 13:44:22 +00:00
|
|
|
# Log the traceback explicitly (it's useful debug info)
|
|
|
|
traceback.print_exc()
|
|
|
|
exit(1)
|
2019-07-02 14:53:05 +00:00
|
|
|
|
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main(sys.argv[1:])
|