diff --git a/poetry/core/factory.py b/poetry/core/factory.py index f14aea7ba..d248dbb74 100644 --- a/poetry/core/factory.py +++ b/poetry/core/factory.py @@ -27,7 +27,9 @@ class Factory(object): Factory class to create various elements needed by Poetry. """ - def create_poetry(self, cwd=None): # type: (Optional[Path]) -> Poetry + def create_poetry( + self, cwd=None, with_dev=True + ): # type: (Optional[Path]. bool) -> Poetry poetry_file = self.locate(cwd) local_config = PyProjectTOML(path=poetry_file).poetry_config @@ -91,7 +93,7 @@ def create_poetry(self, cwd=None): # type: (Optional[Path]) -> Poetry self.create_dependency(name, constraint, root_dir=package.root_dir) ) - if "dev-dependencies" in local_config: + if with_dev and "dev-dependencies" in local_config: for name, constraint in local_config["dev-dependencies"].items(): if isinstance(constraint, list): for _constraint in constraint: diff --git a/poetry/core/masonry/api.py b/poetry/core/masonry/api.py index aae519789..4907e10d4 100644 --- a/poetry/core/masonry/api.py +++ b/poetry/core/masonry/api.py @@ -31,7 +31,7 @@ def get_requires_for_build_wheel(config_settings=None): def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None): - poetry = Factory().create_poetry(Path(".").resolve()) + poetry = Factory().create_poetry(Path(".").resolve(), with_dev=False) builder = WheelBuilder(poetry) dist_info = Path(metadata_directory, builder.dist_info) @@ -52,14 +52,14 @@ def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None): def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): """Builds a wheel, places it in wheel_directory""" - poetry = Factory().create_poetry(Path(".").resolve()) + poetry = Factory().create_poetry(Path(".").resolve(), with_dev=False) return unicode(WheelBuilder.make_in(poetry, Path(wheel_directory))) def build_sdist(sdist_directory, config_settings=None): """Builds an sdist, places it in sdist_directory""" - poetry = Factory().create_poetry(Path(".").resolve()) + poetry = Factory().create_poetry(Path(".").resolve(), with_dev=False) path = SdistBuilder(poetry).build(Path(sdist_directory)) diff --git a/tests/fixtures/project_with_invalid_dev_deps/pyproject.toml b/tests/fixtures/project_with_invalid_dev_deps/pyproject.toml new file mode 100644 index 000000000..1d0b5a846 --- /dev/null +++ b/tests/fixtures/project_with_invalid_dev_deps/pyproject.toml @@ -0,0 +1,13 @@ +[tool.poetry] +name = "my-package" +version = "1.2.3" +description = "Some description." +authors = ["Awesome Hacker "] +license = "MIT" + +[tool.poetry.dependencies] + +[tool.poetry.extras] + +[tool.poetry.dev-dependencies] +mylib = { path = "../mylib", develop = true} diff --git a/tests/masonry/builders/fixtures/with_bad_path_dep/pyproject.toml b/tests/masonry/builders/fixtures/with_bad_path_dep/pyproject.toml new file mode 100644 index 000000000..3c7edf13a --- /dev/null +++ b/tests/masonry/builders/fixtures/with_bad_path_dep/pyproject.toml @@ -0,0 +1,9 @@ +[tool.poetry] +name = "with_bad_path_dep" +version = "1.2.3" +description = "Some description." +authors = ["Awesome Hacker "] + +[tool.poetry.dependencies] +python = "^3.6" +bogus = { path = "../only/in/dev", develop = true } diff --git a/tests/masonry/builders/fixtures/with_bad_path_dep/with_bad_path_dep/__init__.py b/tests/masonry/builders/fixtures/with_bad_path_dep/with_bad_path_dep/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/with_bad_path_dev_dep/pyproject.toml b/tests/masonry/builders/fixtures/with_bad_path_dev_dep/pyproject.toml new file mode 100644 index 000000000..921d93af5 --- /dev/null +++ b/tests/masonry/builders/fixtures/with_bad_path_dev_dep/pyproject.toml @@ -0,0 +1,11 @@ +[tool.poetry] +name = "with_bad_path_dev_dep" +version = "1.2.3" +description = "Some description." +authors = ["Awesome Hacker "] + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry.dev-dependencies] +bogus = { path = "../only/in/dev", develop = true } diff --git a/tests/masonry/builders/fixtures/with_bad_path_dev_dep/with_bad_path_dev_dep/__init__.py b/tests/masonry/builders/fixtures/with_bad_path_dev_dep/with_bad_path_dev_dep/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/test_api.py b/tests/masonry/test_api.py index 9f8cfc95c..adbbddeba 100644 --- a/tests/masonry/test_api.py +++ b/tests/masonry/test_api.py @@ -65,6 +65,21 @@ def test_build_wheel_with_include(): ) +def test_build_wheel_with_bad_path_dev_dep_succeeds(): + with temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dev_dep") + ): + api.build_wheel(tmp_dir) + + +def test_build_wheel_with_bad_path_dep_fails(): + with pytest.raises(ValueError) as err, temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dep") + ): + api.build_wheel(tmp_dir) + assert "does not exist" in str(err.value) + + @pytest.mark.skipif( sys.platform == "win32" and sys.version_info <= (3, 6) @@ -101,6 +116,21 @@ def test_build_sdist_with_include(): ) +def test_build_sdist_with_bad_path_dev_dep_succeeds(): + with temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dev_dep") + ): + api.build_sdist(tmp_dir) + + +def test_build_sdist_with_bad_path_dep_fails(): + with pytest.raises(ValueError) as err, temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dep") + ): + api.build_sdist(tmp_dir) + assert "does not exist" in str(err.value) + + def test_prepare_metadata_for_build_wheel(): entry_points = """\ [console_scripts] @@ -170,3 +200,18 @@ def test_prepare_metadata_for_build_wheel(): with (dist_info / "METADATA").open(encoding="utf-8") as f: assert metadata == decode(f.read()) + + +def test_prepare_metadata_for_build_wheel_with_bad_path_dev_dep_succeeds(): + with temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dev_dep") + ): + api.prepare_metadata_for_build_wheel(tmp_dir) + + +def test_prepare_metadata_for_build_wheel_with_bad_path_dep_succeeds(): + with pytest.raises(ValueError) as err, temporary_directory() as tmp_dir, cwd( + os.path.join(fixtures, "with_bad_path_dep") + ): + api.prepare_metadata_for_build_wheel(tmp_dir) + assert "does not exist" in str(err.value) diff --git a/tests/test_factory.py b/tests/test_factory.py index 4c4e5da02..525fadb49 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -199,3 +199,21 @@ def test_create_poetry_fails_on_invalid_configuration(): - 'description' is a required property """ assert expected == str(e.value) + + +def test_create_poetry_omits_dev_dependencies_iff_with_dev_is_false(): + poetry = Factory().create_poetry(fixtures_dir / "sample_project", with_dev=False) + assert not any(r for r in poetry.package.dev_requires if "pytest" in str(r)) + + poetry = Factory().create_poetry(fixtures_dir / "sample_project") + assert any(r for r in poetry.package.dev_requires if "pytest" in str(r)) + + +def test_create_poetry_fails_with_invalid_dev_dependencies_iff_with_dev_is_true(): + with pytest.raises(ValueError) as err: + Factory().create_poetry(fixtures_dir / "project_with_invalid_dev_deps") + assert "does not exist" in str(err.value) + + Factory().create_poetry( + fixtures_dir / "project_with_invalid_dev_deps", with_dev=False + )