Support multiple vendor files in pythonbundles.py

Not bumping the release, will happily wait until it bubbles trough.
This commit is contained in:
Miro Hrončok 2021-06-21 11:35:48 +02:00 committed by churchyard
parent 04ae9b96f2
commit 9bd2a43a74
5 changed files with 53 additions and 21 deletions

View File

@ -22,26 +22,27 @@ import pythondistdeps
pythondistdeps.parse_version = parse_version
def generate_bundled_provides(path, namespace):
def generate_bundled_provides(paths, namespace):
provides = set()
for line in path.read_text().splitlines():
line, _, comment = line.partition('#')
if comment.startswith('egg='):
# not a real comment
# e.g. git+https://github.com/monty/spam.git@master#egg=spam&...
egg, *_ = comment.strip().partition(' ')
egg, *_ = egg.strip().partition('&')
name = pythondistdeps.normalize_name(egg[4:])
provides.add(f'Provides: bundled({namespace}({name}))')
continue
line = line.strip()
if line:
name, _, version = line.partition('==')
name = pythondistdeps.normalize_name(name)
bundled_name = f"bundled({namespace}({name}))"
python_provide = pythondistdeps.convert(bundled_name, '==', version)
provides.add(f'Provides: {python_provide}')
for path in paths:
for line in path.read_text().splitlines():
line, _, comment = line.partition('#')
if comment.startswith('egg='):
# not a real comment
# e.g. git+https://github.com/monty/spam.git@master#egg=spam&...
egg, *_ = comment.strip().partition(' ')
egg, *_ = egg.strip().partition('&')
name = pythondistdeps.normalize_name(egg[4:])
provides.add(f'Provides: bundled({namespace}({name}))')
continue
line = line.strip()
if line:
name, _, version = line.partition('==')
name = pythondistdeps.normalize_name(name)
bundled_name = f"bundled({namespace}({name}))"
python_provide = pythondistdeps.convert(bundled_name, '==', version)
provides.add(f'Provides: {python_provide}')
return provides
@ -70,7 +71,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser(prog=sys.argv[0],
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('vendored', metavar='VENDORED.TXT',
parser.add_argument('vendored', metavar='VENDORED.TXT', nargs='+', type=pathlib.Path,
help='Upstream information about vendored libraries')
parser.add_argument('-c', '--compare-with', action='store',
help='A string value to compare with and verify')
@ -78,7 +79,7 @@ if __name__ == '__main__':
help='What namespace of provides will used', default='python3dist')
args = parser.parse_args()
provides = generate_bundled_provides(pathlib.Path(args.vendored), args.namespace)
provides = generate_bundled_provides(args.vendored, args.namespace)
if args.compare_with:
given = args.compare_with.splitlines()

View File

@ -0,0 +1,5 @@
Provides: bundled(python3dist(appdirs)) = 1.4.3
Provides: bundled(python3dist(ordered-set)) = 3.1.1
Provides: bundled(python3dist(packaging)) = 16.8
Provides: bundled(python3dist(pyparsing)) = 2.2.1
Provides: bundled(python3dist(six)) = 1.10

View File

@ -0,0 +1,3 @@
packaging==16.8
pyparsing==2.2.1
ordered-set==3.1.1

View File

@ -0,0 +1,3 @@
Provides: bundled(python3dist(ordered-set)) = 3.1.1
Provides: bundled(python3dist(packaging)) = 16.8
Provides: bundled(python3dist(pyparsing)) = 2.2.1

View File

@ -34,7 +34,7 @@ def run_pythonbundles(*args, success=True):
return cp
projects = pytest.mark.parametrize('project', ('pkg_resources', 'pip', 'pipenv'))
projects = pytest.mark.parametrize('project', ('pkg_resources', 'pip', 'pipenv', 'setuptools'))
@projects
@ -97,3 +97,23 @@ def test_compare_with_unexpected(project):
cp = run_pythonbundles(TEST_DATA / f'{project}.in', '--compare-with', longer, success=False)
assert cp.stdout == '', cp.stdout
assert cp.stderr == f'Redundant unexpected provides:\n + {unexpected}\n', cp.stderr
combo_order = pytest.mark.parametrize('projects', ['pkg_resources-setuptools', 'setuptools-pkg_resources'])
@combo_order
def test_multiple_vendor_files_output(projects):
cp = run_pythonbundles(*(TEST_DATA / f'{p}.in' for p in projects.split('-')))
expected = (TEST_DATA / 'pkg_resources_setuptools.out').read_text()
assert cp.stdout == expected, cp.stdout
assert cp.stderr == '', cp.stderr
@combo_order
def test_multiple_vendor_files_compare_with(projects):
expected = (TEST_DATA / 'pkg_resources_setuptools.out').read_text()
cp = run_pythonbundles(*(TEST_DATA / f'{p}.in' for p in projects.split('-')),
'--compare-with', expected)
assert cp.stdout == '', cp.stdout
assert cp.stderr == '', cp.stderr