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 pythondistdeps.parse_version = parse_version
def generate_bundled_provides(path, namespace): def generate_bundled_provides(paths, namespace):
provides = set() provides = set()
for line in path.read_text().splitlines(): for path in paths:
line, _, comment = line.partition('#') for line in path.read_text().splitlines():
if comment.startswith('egg='): line, _, comment = line.partition('#')
# not a real comment if comment.startswith('egg='):
# e.g. git+https://github.com/monty/spam.git@master#egg=spam&... # not a real comment
egg, *_ = comment.strip().partition(' ') # e.g. git+https://github.com/monty/spam.git@master#egg=spam&...
egg, *_ = egg.strip().partition('&') egg, *_ = comment.strip().partition(' ')
name = pythondistdeps.normalize_name(egg[4:]) egg, *_ = egg.strip().partition('&')
provides.add(f'Provides: bundled({namespace}({name}))') name = pythondistdeps.normalize_name(egg[4:])
continue provides.add(f'Provides: bundled({namespace}({name}))')
line = line.strip() continue
if line: line = line.strip()
name, _, version = line.partition('==') if line:
name = pythondistdeps.normalize_name(name) name, _, version = line.partition('==')
bundled_name = f"bundled({namespace}({name}))" name = pythondistdeps.normalize_name(name)
python_provide = pythondistdeps.convert(bundled_name, '==', version) bundled_name = f"bundled({namespace}({name}))"
provides.add(f'Provides: {python_provide}') python_provide = pythondistdeps.convert(bundled_name, '==', version)
provides.add(f'Provides: {python_provide}')
return provides return provides
@ -70,7 +71,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser(prog=sys.argv[0], parser = argparse.ArgumentParser(prog=sys.argv[0],
formatter_class=argparse.ArgumentDefaultsHelpFormatter) 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') help='Upstream information about vendored libraries')
parser.add_argument('-c', '--compare-with', action='store', parser.add_argument('-c', '--compare-with', action='store',
help='A string value to compare with and verify') 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') help='What namespace of provides will used', default='python3dist')
args = parser.parse_args() 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: if args.compare_with:
given = args.compare_with.splitlines() 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 return cp
projects = pytest.mark.parametrize('project', ('pkg_resources', 'pip', 'pipenv')) projects = pytest.mark.parametrize('project', ('pkg_resources', 'pip', 'pipenv', 'setuptools'))
@projects @projects
@ -97,3 +97,23 @@ def test_compare_with_unexpected(project):
cp = run_pythonbundles(TEST_DATA / f'{project}.in', '--compare-with', longer, success=False) cp = run_pythonbundles(TEST_DATA / f'{project}.in', '--compare-with', longer, success=False)
assert cp.stdout == '', cp.stdout assert cp.stdout == '', cp.stdout
assert cp.stderr == f'Redundant unexpected provides:\n + {unexpected}\n', cp.stderr 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