diff --git a/poetry_multiproject_plugin/components/toml/generate.py b/poetry_multiproject_plugin/components/toml/generate.py index 500d3a9..b904d54 100644 --- a/poetry_multiproject_plugin/components/toml/generate.py +++ b/poetry_multiproject_plugin/components/toml/generate.py @@ -83,13 +83,18 @@ def generate_valid_dist_project_file( copy["tool"]["poetry"]["packages"].multiline(True) - scripts = copy["tool"]["poetry"].get("scripts", {}) + scripts_pep_621 = copy.get("project", {}).get("scripts", {}) + scripts_poetry = copy["tool"]["poetry"].get("scripts", {}) + scripts = scripts_pep_621 or scripts_poetry if top_ns and scripts: rewritten_scripts = { k: to_valid_entry(v, top_ns, data) for k, v in scripts.items() } - copy["tool"]["poetry"]["scripts"] = rewritten_scripts + if scripts_pep_621: + copy["project"]["scripts"] = rewritten_scripts + else: + copy["tool"]["poetry"]["scripts"] = rewritten_scripts return tomlkit.dumps(copy) diff --git a/poetry_multiproject_plugin/components/toml/read.py b/poetry_multiproject_plugin/components/toml/read.py index 4d55ce1..d9367ac 100644 --- a/poetry_multiproject_plugin/components/toml/read.py +++ b/poetry_multiproject_plugin/components/toml/read.py @@ -25,7 +25,9 @@ def package_paths(path: Path) -> List[Path]: def project_name(path: Path) -> str: data: dict = toml(path) - return data["tool"]["poetry"]["name"] + pep_621_name = data.get("project", {}).get("name") + + return pep_621_name or data["tool"]["poetry"]["name"] def parse_exclude_path(data: dict) -> Union[str, None]: diff --git a/pyproject.toml b/pyproject.toml index e9aadce..dc6589d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "poetry-multiproject-plugin" -version = "1.8.0" +version = "1.8.1" description = "A Poetry plugin that makes it possible to use relative package includes." authors = ["David Vujic"] license = "MIT" diff --git a/test/components/toml/test_generate.py b/test/components/toml/test_generate.py index 8c51e83..c353a45 100644 --- a/test/components/toml/test_generate.py +++ b/test/components/toml/test_generate.py @@ -21,6 +21,16 @@ my_cli = "hello.console.app:run" """ +pyproject_pep_621_cli = """\ +[tool.poetry] +packages = [ + {include = "hello", from = "../world"}, +] + +[project.scripts] +my_cli = "hello.console.app:run" +""" + pyproject_cli_with_local_modules = """\ [tool.poetry] packages = [ @@ -58,6 +68,12 @@ def test_generate_project_file_with_custom_namespace_in_script_entry_point(): assert data["tool"]["poetry"]["scripts"] == {"my_cli": "xyz.hello.console.app:run"} +def test_generate_project_file_with_custom_namespace_in_script_entry_point_for_pep_621_project(): + data = generate_toml(pyproject_pep_621_cli, "xyz") + + assert data["project"]["scripts"] == {"my_cli": "xyz.hello.console.app:run"} + + def test_generate_project_file_with_unchanged_script_entry_point(): data = generate_toml(pyproject_cli, "hello") diff --git a/test/components/toml/test_read.py b/test/components/toml/test_read.py index 0c40809..fd50625 100644 --- a/test/components/toml/test_read.py +++ b/test/components/toml/test_read.py @@ -1,9 +1,12 @@ +from pathlib import Path + import tomlkit from poetry_multiproject_plugin.components.toml import read pyproject = """\ [tool.poetry] +name = "unit test" """ pyproject_with_exclude_pattern = """\ @@ -21,6 +24,14 @@ exclude = [{"path" = "testing.json", "format" = "wheel"}] """ +pyproject_pep_621 = """\ +[tool.poetry] +packages = [] + +[project] +name = "unit test" +""" + def test_read_exclude_pattern_should_return_empty_result(): data = tomlkit.loads(pyproject) @@ -52,3 +63,19 @@ def test_read_complex_exclude_pattern_with_format_should_return_empty_result(): res = read.parse_exclude_patterns(data) assert res == {"testing.json"} + + +def test_get_project_name(monkeypatch): + monkeypatch.setattr(read, "toml", lambda _: tomlkit.loads(pyproject)) + + name = read.project_name(Path.cwd()) + + assert name == "unit test" + + +def test_get_project_name_for_pep_621_project(monkeypatch): + monkeypatch.setattr(read, "toml", lambda _: tomlkit.loads(pyproject_pep_621)) + + name = read.project_name(Path.cwd()) + + assert name == "unit test"