Skip to content

Commit bf0dc35

Browse files
authored
fix(project) circular imports when importing the 'get' module (#379)
* fix(project): remove circular dependency in the 'get' module, causing failed REPL evaluations during development * bump CLI to 1.35.1 * bump Poetry plugin to 1.42.1
1 parent cdfc820 commit bf0dc35

File tree

6 files changed

+92
-89
lines changed

6 files changed

+92
-89
lines changed

components/polylith/project/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from polylith.project import interactive, templates
1+
from polylith.project import interactive
22
from polylith.project.create import create_project
33
from polylith.project.get import (
44
get_packages_for_projects,
@@ -16,5 +16,4 @@
1616
"get_toml",
1717
"interactive",
1818
"parse_package_paths",
19-
"templates",
2019
]

components/polylith/project/get.py

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,81 @@
44

55
import tomlkit
66
from polylith import configuration, repo, toml
7-
from polylith.project import templates
7+
8+
poetry_pyproject_template = """\
9+
[tool.poetry]
10+
name = "{name}"
11+
version = "0.1.0"
12+
{description}
13+
{authors}
14+
license = ""
15+
16+
packages = []
17+
18+
[tool.poetry.dependencies]
19+
python = "{python_version}"
20+
21+
[build-system]
22+
requires = ["poetry-core>=1.0.0"]
23+
build-backend = "poetry.core.masonry.api"
24+
"""
25+
26+
poetry_pep621_pyproject_template = """\
27+
[tool.poetry]
28+
packages = []
29+
30+
[project]
31+
name = "{name}"
32+
version = "0.1.0"
33+
{description}
34+
{authors}
35+
36+
requires-python = "{python_version}"
37+
38+
dependencies = []
39+
40+
[build-system]
41+
requires = ["poetry-core>=1.0.0"]
42+
build-backend = "poetry.core.masonry.api"
43+
"""
44+
45+
hatch_pyproject_template = """\
46+
[build-system]
47+
requires = ["hatchling", "hatch-polylith-bricks"]
48+
build-backend = "hatchling.build"
49+
50+
[project]
51+
name = "{name}"
52+
version = "0.1.0"
53+
{description}
54+
{authors}
55+
56+
requires-python = "{python_version}"
57+
58+
dependencies = []
59+
60+
[tool.hatch.build.hooks.polylith-bricks]
61+
62+
[tool.polylith.bricks]
63+
"""
64+
65+
pdm_pyproject_template = """\
66+
[build-system]
67+
requires = ["pdm-backend", "pdm-polylith-bricks"]
68+
build-backend = "pdm.backend"
69+
70+
[project]
71+
name = "{name}"
72+
version = "0.1.0"
73+
{description}
74+
{authors}
75+
76+
requires-python = "{python_version}"
77+
78+
dependencies = []
79+
80+
[tool.polylith.bricks]
81+
"""
882

983

1084
def get_project_name(toml_data) -> str:
@@ -69,18 +143,18 @@ def get_packages_for_projects(root: Path) -> List[dict]:
69143

70144
def _get_poetry_template(pyproject: dict) -> str:
71145
if repo.is_pep_621_ready(pyproject):
72-
return templates.poetry_pep621_pyproject
146+
return poetry_pep621_pyproject_template
73147

74-
return templates.poetry_pyproject
148+
return poetry_pyproject_template
75149

76150

77151
def guess_project_template(pyproject: dict) -> str:
78152
if repo.is_poetry(pyproject):
79153
template = _get_poetry_template(pyproject)
80154
elif repo.is_hatch(pyproject):
81-
template = templates.hatch_pyproject
155+
template = hatch_pyproject_template
82156
elif repo.is_pdm(pyproject):
83-
template = templates.pdm_pyproject
157+
template = pdm_pyproject_template
84158
else:
85159
raise ValueError("Failed to guess the type of Project")
86160

components/polylith/project/templates.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

projects/poetry_polylith_plugin/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "poetry-polylith-plugin"
3-
version = "1.42.0"
3+
version = "1.42.1"
44
description = "A Poetry plugin that adds tooling support for the Polylith Architecture"
55
authors = ["David Vujic"]
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

projects/polylith_cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "polylith-cli"
3-
version = "1.35.0"
3+
version = "1.35.1"
44
description = "Python tooling support for the Polylith Architecture"
55
authors = ['David Vujic']
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

test/components/polylith/project/test_templates.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pytest
22
import tomlkit
3-
from polylith.project import templates
3+
from polylith.project.get import (
4+
hatch_pyproject_template,
5+
pdm_pyproject_template,
6+
poetry_pyproject_template,
7+
)
48

59
template_data = {
610
"name": "a project",
@@ -36,7 +40,7 @@ def to_toml(template: str, data: dict):
3640

3741

3842
def test_poetry_template():
39-
data = to_toml(templates.poetry_pyproject, template_data)
43+
data = to_toml(poetry_pyproject_template, template_data)
4044

4145
assert data["tool"]["poetry"] is not None
4246
assert data["tool"]["poetry"].get("authors") is None
@@ -48,7 +52,7 @@ def test_poetry_template_with_optionals():
4852
expected_author = "Unit test"
4953

5054
data = to_toml(
51-
templates.poetry_pyproject,
55+
poetry_pyproject_template,
5256
with_poetry_optionals(expected_description, expected_author),
5357
)
5458

@@ -57,7 +61,7 @@ def test_poetry_template_with_optionals():
5761

5862

5963
def test_hatch_template():
60-
data = to_toml(templates.hatch_pyproject, template_data)
64+
data = to_toml(hatch_pyproject_template, template_data)
6165

6266
assert "hatch-polylith-bricks" in data["build-system"]["requires"]
6367
assert data["tool"]["hatch"]["build"]["hooks"]["polylith-bricks"] == {}
@@ -68,7 +72,7 @@ def test_hatch_template():
6872

6973

7074
def test_pdm_template():
71-
data = to_toml(templates.pdm_pyproject, template_data)
75+
data = to_toml(pdm_pyproject_template, template_data)
7276

7377
assert "pdm-polylith-bricks" in data["build-system"]["requires"]
7478
assert data["tool"]["polylith"]["bricks"] == {}
@@ -82,7 +86,7 @@ def test_pep621_template_with_optionals(name):
8286
expected_description = "Hello world"
8387
expected_author = "Unit Test"
8488

85-
template = {"hatch": templates.hatch_pyproject, "pdm": templates.pdm_pyproject}
89+
template = {"hatch": hatch_pyproject_template, "pdm": pdm_pyproject_template}
8690

8791
data = to_toml(
8892
template[name],

0 commit comments

Comments
 (0)