From 09f0f95811a533f914025b0d2f46beedb2ff9268 Mon Sep 17 00:00:00 2001 From: Brendan Abel <007brendan@gmail.com> Date: Sun, 14 Jun 2020 01:05:30 -0700 Subject: [PATCH 1/2] feat: add support for Requires-External metadata --- flit_core/flit_core/common.py | 3 +++ flit_core/flit_core/config.py | 6 +++++- tests/samples/requires-external/module1.py | 3 +++ tests/samples/requires-external/pyproject.toml | 12 ++++++++++++ tests/test_wheel.py | 10 ++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/samples/requires-external/module1.py create mode 100644 tests/samples/requires-external/pyproject.toml diff --git a/flit_core/flit_core/common.py b/flit_core/flit_core/common.py index 828b26b8..e327a9d6 100644 --- a/flit_core/flit_core/common.py +++ b/flit_core/flit_core/common.py @@ -341,6 +341,9 @@ def write_metadata_file(self, fp): for extra in self.provides_extra: fp.write(u'Provides-Extra: {}\n'.format(extra)) + for ext in self.requires_external: + fp.write(u'Requires-External: {}\n'.format(ext)) + if self.description is not None: fp.write(u'\n' + self.description + u'\n') diff --git a/flit_core/flit_core/config.py b/flit_core/flit_core/config.py index 0af9c00c..bb136063 100644 --- a/flit_core/flit_core/config.py +++ b/flit_core/flit_core/config.py @@ -15,7 +15,8 @@ class ConfigError(ValueError): metadata_list_fields = { 'classifiers', 'requires', - 'dev-requires' + 'dev-requires', + 'requires-external', } metadata_allowed_fields = { @@ -305,6 +306,9 @@ def _prep_metadata(md_sect, path): md_dict['provides_extra'] = sorted(res.reqs_by_extra.keys()) + if 'requires-external' in md_dict: + md_dict['requires_external'] = md_dict.pop('requires-external') + # For internal use, record the main requirements as a '.none' extra. res.reqs_by_extra['.none'] = reqs_noextra diff --git a/tests/samples/requires-external/module1.py b/tests/samples/requires-external/module1.py new file mode 100644 index 00000000..87f0370d --- /dev/null +++ b/tests/samples/requires-external/module1.py @@ -0,0 +1,3 @@ +"""Example module""" + +__version__ = '0.1' diff --git a/tests/samples/requires-external/pyproject.toml b/tests/samples/requires-external/pyproject.toml new file mode 100644 index 00000000..bd418918 --- /dev/null +++ b/tests/samples/requires-external/pyproject.toml @@ -0,0 +1,12 @@ +[build-system] +requires = ["flit"] + +[tool.flit.metadata] +module = "module1" +author = "Sir Robin" +author-email = "robin@camelot.uk" +home-page = "http://github.com/sirrobin/module1" +requires-external = [ + "git", + "ffmpeg", +] diff --git a/tests/test_wheel.py b/tests/test_wheel.py index 95572cda..47898b89 100644 --- a/tests/test_wheel.py +++ b/tests/test_wheel.py @@ -71,6 +71,16 @@ def test_entry_points(copy_sample): assert 'console_scripts' in cp.sections() assert 'myplugins' in cp.sections() +def test_requires_external(copy_sample): + td = copy_sample('requires-external') + make_wheel_in(td / 'pyproject.toml', td) + assert_isfile(td / 'module1-0.1-py2.py3-none-any.whl') + with unpack(td / 'module1-0.1-py2.py3-none-any.whl') as td_unpack: + with open(Path(td_unpack) / 'module1-0.1.dist-info' / 'METADATA') as f: + txt = f.read() + assert 'Requires-External: git' in txt + assert 'Requires-External: ffmpeg' in txt + def test_entry_points_conflict(copy_sample): td = copy_sample('entrypoints_conflict') with pytest.raises(EntryPointsConflict): From 6764c56e3fa8dd252cd62c58d6804b070ea5afe5 Mon Sep 17 00:00:00 2001 From: Brendan Abel <007brendan@gmail.com> Date: Sun, 14 Jun 2020 01:41:25 -0700 Subject: [PATCH 2/2] test: fix test for py35 --- tests/test_wheel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_wheel.py b/tests/test_wheel.py index 47898b89..39389d08 100644 --- a/tests/test_wheel.py +++ b/tests/test_wheel.py @@ -76,7 +76,7 @@ def test_requires_external(copy_sample): make_wheel_in(td / 'pyproject.toml', td) assert_isfile(td / 'module1-0.1-py2.py3-none-any.whl') with unpack(td / 'module1-0.1-py2.py3-none-any.whl') as td_unpack: - with open(Path(td_unpack) / 'module1-0.1.dist-info' / 'METADATA') as f: + with open(str(Path(td_unpack) / 'module1-0.1.dist-info' / 'METADATA')) as f: txt = f.read() assert 'Requires-External: git' in txt assert 'Requires-External: ffmpeg' in txt