diff --git a/pythonbundles.py b/pythonbundles.py index 96e817e..6242e20 100755 --- a/pythonbundles.py +++ b/pythonbundles.py @@ -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() diff --git a/tests/data/scripts_pythonbundles/pkg_resources_setuptools.out b/tests/data/scripts_pythonbundles/pkg_resources_setuptools.out new file mode 100644 index 0000000..cc2d710 --- /dev/null +++ b/tests/data/scripts_pythonbundles/pkg_resources_setuptools.out @@ -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 diff --git a/tests/data/scripts_pythonbundles/setuptools.in b/tests/data/scripts_pythonbundles/setuptools.in new file mode 100644 index 0000000..d7d2beb --- /dev/null +++ b/tests/data/scripts_pythonbundles/setuptools.in @@ -0,0 +1,3 @@ +packaging==16.8 +pyparsing==2.2.1 +ordered-set==3.1.1 diff --git a/tests/data/scripts_pythonbundles/setuptools.out b/tests/data/scripts_pythonbundles/setuptools.out new file mode 100644 index 0000000..0acb887 --- /dev/null +++ b/tests/data/scripts_pythonbundles/setuptools.out @@ -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 diff --git a/tests/test_scripts_pythonbundles.py b/tests/test_scripts_pythonbundles.py index c04230e..2926713 100644 --- a/tests/test_scripts_pythonbundles.py +++ b/tests/test_scripts_pythonbundles.py @@ -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