diff --git a/flit/common.py b/flit/common.py index a3ae12d5..19b8d171 100644 --- a/flit/common.py +++ b/flit/common.py @@ -247,7 +247,11 @@ def __init__(self, data): assert hasattr(self, k), "data does not have attribute '{}'".format(k) setattr(self, k, v) if extras_require: - self.requires_dist = self.requires_dist + ['{}; extra == "{}"'.format(d, e) for e, d in extras_require.items()] + self.requires_dist = list(self.requires_dist) + [ + '{}; extra == "{}"'.format(d, e) + for e, ds in extras_require.items() + for d in ds + ] def _normalise_name(self, n): return n.lower().replace('-', '_') diff --git a/tests/samples/extras.toml b/tests/samples/extras.toml index dbf296f8..c070986a 100644 --- a/tests/samples/extras.toml +++ b/tests/samples/extras.toml @@ -7,6 +7,7 @@ author = "Sir Robin" author-email = "robin@camelot.uk" home-page = "http://github.com/sirrobin/module1" description-file = "EG_README.rst" +requires = ["toml"] [tool.flit.metadata.extras-require] test = ["pytest"] diff --git a/tests/test_install.py b/tests/test_install.py index df1c9e88..2d588d11 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -117,6 +117,36 @@ def test_install_requires(self): assert len(calls) == 1 assert calls[0]['argv'][1:5] == ['-m', 'pip', 'install', '-r'] +@pytest.mark.parametrize(('deps', 'extras', 'installed'), [ + ('none', [], set()), + ('dev', [], {'pytest;'}), # TODO: why not also normal reqs, i.e. toml? + ('production', [], {'toml;'}), + ('all', [], {'toml;', 'pytest;', 'requests;'}), +]) +def test_install_requires_extras(deps, extras, installed, samples_dir): + it = InstallTests() + try: + it.setUp() + ins = Installer(samples_dir / 'extras.toml', python='mock_python', + user=False, deps=deps, extras=extras) + + cmd = MockCommand('mock_python') + get_reqs = ( + "#!{python}\n" + "import sys, pathlib\n" + "pathlib.Path({recording_file!r}).write_text(pathlib.Path(sys.argv[-1]).read_text())\n" + ).format(python=sys.executable, recording_file=cmd.recording_file) + cmd.content = get_reqs + + with cmd as mock_py: + ins.install_requirements() + str_deps = pathlib.Path(mock_py.recording_file).read_text() + deps = str_deps.split('\n') if str_deps else [] + + assert set(deps) == installed + finally: + it.tearDown() + def test_requires_dist_to_pip_requirement(): rd = 'pathlib2 (>=2.3); python_version == "2.7"' assert _requires_dist_to_pip_requirement(rd) == \ diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 8cab3349..f24b6f89 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -11,4 +11,9 @@ def test_extras(samples_dir): def test_extras_dev_conflict(samples_dir): info = read_pkg_ini(samples_dir / 'extras-dev-conflict.toml') with pytest.raises(ValueError, match=r'Ambiguity'): - Metadata(dict(name=info['module'], version='0.0', summary='', **info['metadata'])) \ No newline at end of file + Metadata(dict(name=info['module'], version='0.0', summary='', **info['metadata'])) + +def test_extra_conditions(samples_dir): + info = read_pkg_ini(samples_dir / 'extras.toml') + meta = Metadata(dict(name=info['module'], version='0.0', summary='', **info['metadata'])) + assert set(meta.requires_dist) == {'toml', 'pytest; extra == "test"', 'requests; extra == "custom"'}