diff --git a/flit_core/flit_core/common.py b/flit_core/flit_core/common.py index 68d91bb9..e97cdc77 100644 --- a/flit_core/flit_core/common.py +++ b/flit_core/flit_core/common.py @@ -56,9 +56,15 @@ def __init__(self, name, directory=Path()): .format(name, ", ".join([str(p) for p in sorted(existing)])) ) elif not existing: - raise ValueError("No file/folder found for module {}".format(name)) - - self.source_dir = directory / self.prefix + if os.environ.get("FLIT_ALLOW_INVALID"): + log.warning( + "Allowing invalid data (FLIT_ALLOW_INVALID set). No file/folder found for module {}" + .format(name) + ) + else: + raise ValueError("No file/folder found for module {}".format(name)) + else: + self.source_dir = directory / self.prefix if '.' in name: self.namespace_package_name = name.rpartition('.')[0] diff --git a/flit_core/flit_core/config.py b/flit_core/flit_core/config.py index 12929561..a15586a9 100644 --- a/flit_core/flit_core/config.py +++ b/flit_core/flit_core/config.py @@ -281,6 +281,12 @@ def description_from_file(rel_path: str, proj_dir: Path, guess_mimetype=True): with desc_path.open('r', encoding='utf-8') as f: raw_desc = f.read() except IOError as e: + if os.environ.get('FLIT_ALLOW_INVALID'): + log.warning( + "Allowing invalid data (FLIT_ALLOW_INVALID set). Description file {} does not exist" + .format(desc_path) + ) + return None, None if e.errno == errno.ENOENT: raise ConfigError( "Description file {} does not exist".format(desc_path) diff --git a/tests/samples/missing-description-file.toml b/tests/samples/missing-description-file.toml index 00fae72f..fe924d48 100644 --- a/tests/samples/missing-description-file.toml +++ b/tests/samples/missing-description-file.toml @@ -7,3 +7,4 @@ author = "Sir Robin" author-email = "robin@camelot.uk" home-page = "http://github.com/sirrobin/missingdescriptionfile" description-file = "definitely-missing.rst" +requires = ["requests"] diff --git a/tests/samples/missing-module.toml b/tests/samples/missing-module.toml new file mode 100644 index 00000000..96f601dd --- /dev/null +++ b/tests/samples/missing-module.toml @@ -0,0 +1,10 @@ +[build-system] +requires = ["flit"] + +[tool.flit.metadata] +module = "definitelymissingmodule" +author = "Sir Robin" +author-email = "robin@camelot.uk" +home-page = "http://github.com/sirrobin/module1" +description-file = "EG_README.rst" +requires = ["requests"] diff --git a/tests/test_install.py b/tests/test_install.py index b4e9068e..65dd8415 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -13,6 +13,7 @@ from flit import install from flit.install import Installer, _requires_dist_to_pip_requirement, DependencyError +from flit_core.config import ConfigError import flit_core.tests samples_dir = pathlib.Path(__file__).parent / 'samples' @@ -278,6 +279,32 @@ def test_install_requires(self): assert len(calls) == 1 assert calls[0]['argv'][1:5] == ['-m', 'pip', 'install', '-r'] + def test_install_only_deps(self): + """Test if we can install using --only-deps with the pyproject.toml, and without the README or module folder""" + os.environ.setdefault('FLIT_ALLOW_INVALID', '1') + try: + ins = Installer.from_ini_path( + samples_dir / 'missing-description-file.toml', user=False, python='mock_python' + ) + + with MockCommand('mock_python') as mockpy: + ins.install_requirements() + calls = mockpy.get_calls() + assert len(calls) == 1 + assert calls[0]['argv'][1:5] == ['-m', 'pip', 'install', '-r'] + finally: + del os.environ['FLIT_ALLOW_INVALID'] + + def test_install_only_deps_fail(self): + with pytest.raises(ConfigError, match=r"Description file .* does not exist"): + Installer.from_ini_path( + samples_dir / 'missing-description-file.toml', user=False, python='mock_python' + ) + with pytest.raises(ValueError, match=r"No file/folder found for module definitelymissingmodule"): + Installer.from_ini_path( + samples_dir / 'missing-module.toml', user=False, python='mock_python' + ) + def test_install_reqs_my_python_if_needed_pep621(self): ins = Installer.from_ini_path( core_samples_dir / 'pep621_nodynamic' / 'pyproject.toml',