Skip to content

Commit cd16954

Browse files
authored
fix: extract the 'project.interactive' module to a separate component (#393)
* fix: extract the 'interactive' module into a separate component, to avoid circular dependencies * fix(project): extract pyproject templates into a separate module. * bump Poetry plugin to 1.45.2 * bump CLI to 1.38.2
1 parent b3acdee commit cd16954

File tree

12 files changed

+174
-93
lines changed

12 files changed

+174
-93
lines changed

bases/polylith/cli/create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pathlib import Path
22

3-
from polylith import project
3+
from polylith import interactive, project
44
from polylith.bricks import base, component
55
from polylith.commands.create import create
66
from polylith.workspace.create import create_workspace
@@ -52,7 +52,7 @@ def project_command(
5252
"""Creates a Polylith project."""
5353
create(name, description, _create_project)
5454

55-
project.interactive.run(name)
55+
interactive.project.run(name)
5656

5757

5858
@app.command("workspace")

components/polylith/commands/sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22
from typing import Union
33

4-
from polylith import info, project, sync
4+
from polylith import info, interactive, sync
55

66

77
def is_project_without_bricks(project_data: dict) -> bool:
@@ -17,7 +17,7 @@ def choose_base(root: Path, ns: str, project_data: dict) -> Union[str, None]:
1717
if not possible_bases:
1818
return None
1919

20-
return project.interactive.choose_base_for_project(
20+
return interactive.project.choose_base_for_project(
2121
root, ns, project_data["name"], possible_bases
2222
)
2323

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from polylith.interactive import project
2+
3+
__all__ = ["project"]

components/polylith/poetry/commands/create_project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from cleo.helpers import option
44
from poetry.console.commands.command import Command
5-
from polylith import project
5+
from polylith import interactive, project
66
from polylith.commands.create import create
77

88
command_name = "poly create project"
@@ -37,6 +37,6 @@ def handle(self) -> int:
3737

3838
create(name, description, create_project)
3939

40-
project.interactive.run(name)
40+
interactive.project.run(name)
4141

4242
return 0

components/polylith/project/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from polylith.project import interactive
21
from polylith.project.create import create_project
32
from polylith.project.get import (
43
get_packages_for_projects,
@@ -14,6 +13,5 @@
1413
"get_project_name",
1514
"get_project_template",
1615
"get_toml",
17-
"interactive",
1816
"parse_package_paths",
1917
]

components/polylith/project/get.py

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

55
import tomlkit
66
from polylith import configuration, repo, toml
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.targets.wheel]
61-
packages = ["{namespace}"]
62-
63-
[tool.hatch.build.hooks.polylith-bricks]
64-
65-
[tool.polylith.bricks]
66-
"""
67-
68-
pdm_pyproject_template = """\
69-
[build-system]
70-
requires = ["pdm-backend", "pdm-polylith-bricks"]
71-
build-backend = "pdm.backend"
72-
73-
[project]
74-
name = "{name}"
75-
version = "0.1.0"
76-
{description}
77-
{authors}
78-
79-
requires-python = "{python_version}"
80-
81-
dependencies = []
82-
83-
[tool.polylith.bricks]
84-
"""
7+
from polylith.project import templates
858

869

8710
def get_project_name(toml_data) -> str:
@@ -147,18 +70,18 @@ def get_packages_for_projects(root: Path) -> List[dict]:
14770

14871
def _get_poetry_template(pyproject: dict) -> str:
14972
if repo.is_pep_621_ready(pyproject):
150-
return poetry_pep621_pyproject_template
73+
return templates.poetry_pep621_pyproject_template
15174

152-
return poetry_pyproject_template
75+
return templates.poetry_pyproject_template
15376

15477

15578
def guess_project_template(pyproject: dict) -> str:
15679
if repo.is_poetry(pyproject):
15780
template = _get_poetry_template(pyproject)
15881
elif repo.is_hatch(pyproject):
159-
template = hatch_pyproject_template
82+
template = templates.hatch_pyproject_template
16083
elif repo.is_pdm(pyproject):
161-
template = pdm_pyproject_template
84+
template = templates.pdm_pyproject_template
16285
else:
16386
raise ValueError("Failed to guess the type of Project")
16487

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
poetry_pyproject_template = """\
2+
[tool.poetry]
3+
name = "{name}"
4+
version = "0.1.0"
5+
{description}
6+
{authors}
7+
license = ""
8+
9+
packages = []
10+
11+
[tool.poetry.dependencies]
12+
python = "{python_version}"
13+
14+
[build-system]
15+
requires = ["poetry-core>=1.0.0"]
16+
build-backend = "poetry.core.masonry.api"
17+
"""
18+
19+
poetry_pep621_pyproject_template = """\
20+
[tool.poetry]
21+
packages = []
22+
23+
[project]
24+
name = "{name}"
25+
version = "0.1.0"
26+
{description}
27+
{authors}
28+
29+
requires-python = "{python_version}"
30+
31+
dependencies = []
32+
33+
[build-system]
34+
requires = ["poetry-core>=1.0.0"]
35+
build-backend = "poetry.core.masonry.api"
36+
"""
37+
38+
hatch_pyproject_template = """\
39+
[build-system]
40+
requires = ["hatchling", "hatch-polylith-bricks"]
41+
build-backend = "hatchling.build"
42+
43+
[project]
44+
name = "{name}"
45+
version = "0.1.0"
46+
{description}
47+
{authors}
48+
49+
requires-python = "{python_version}"
50+
51+
dependencies = []
52+
53+
[tool.hatch.build.targets.wheel]
54+
packages = ["{namespace}"]
55+
56+
[tool.hatch.build.hooks.polylith-bricks]
57+
58+
[tool.polylith.bricks]
59+
"""
60+
61+
pdm_pyproject_template = """\
62+
[build-system]
63+
requires = ["pdm-backend", "pdm-polylith-bricks"]
64+
build-backend = "pdm.backend"
65+
66+
[project]
67+
name = "{name}"
68+
version = "0.1.0"
69+
{description}
70+
{authors}
71+
72+
requires-python = "{python_version}"
73+
74+
dependencies = []
75+
76+
[tool.polylith.bricks]
77+
"""
78+
poetry_pyproject_template = """\
79+
[tool.poetry]
80+
name = "{name}"
81+
version = "0.1.0"
82+
{description}
83+
{authors}
84+
license = ""
85+
86+
packages = []
87+
88+
[tool.poetry.dependencies]
89+
python = "{python_version}"
90+
91+
[build-system]
92+
requires = ["poetry-core>=1.0.0"]
93+
build-backend = "poetry.core.masonry.api"
94+
"""
95+
96+
poetry_pep621_pyproject_template = """\
97+
[tool.poetry]
98+
packages = []
99+
100+
[project]
101+
name = "{name}"
102+
version = "0.1.0"
103+
{description}
104+
{authors}
105+
106+
requires-python = "{python_version}"
107+
108+
dependencies = []
109+
110+
[build-system]
111+
requires = ["poetry-core>=1.0.0"]
112+
build-backend = "poetry.core.masonry.api"
113+
"""
114+
115+
hatch_pyproject_template = """\
116+
[build-system]
117+
requires = ["hatchling", "hatch-polylith-bricks"]
118+
build-backend = "hatchling.build"
119+
120+
[project]
121+
name = "{name}"
122+
version = "0.1.0"
123+
{description}
124+
{authors}
125+
126+
requires-python = "{python_version}"
127+
128+
dependencies = []
129+
130+
[tool.hatch.build.targets.wheel]
131+
packages = ["{namespace}"]
132+
133+
[tool.hatch.build.hooks.polylith-bricks]
134+
135+
[tool.polylith.bricks]
136+
"""
137+
138+
pdm_pyproject_template = """\
139+
[build-system]
140+
requires = ["pdm-backend", "pdm-polylith-bricks"]
141+
build-backend = "pdm.backend"
142+
143+
[project]
144+
name = "{name}"
145+
version = "0.1.0"
146+
{description}
147+
{authors}
148+
149+
requires-python = "{python_version}"
150+
151+
dependencies = []
152+
153+
[tool.polylith.bricks]
154+
"""

projects/poetry_polylith_plugin/pyproject.toml

Lines changed: 2 additions & 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.45.1"
3+
version = "1.45.2"
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/"
@@ -23,6 +23,7 @@ packages = [
2323
{ include = "polylith/files", from = "../../components" },
2424
{ include = "polylith/imports", from = "../../components" },
2525
{ include = "polylith/info", from = "../../components" },
26+
{ include = "polylith/interactive",from = "../../components" },
2627
{ include = "polylith/interface", from = "../../components" },
2728
{ include = "polylith/libs", from = "../../components" },
2829
{ include = "polylith/output", from = "../../components" },

projects/polylith_cli/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "polylith-cli"
3-
version = "1.38.1"
3+
version = "1.38.2"
44
description = "Python tooling support for the Polylith Architecture"
55
authors = ['David Vujic']
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"
@@ -24,6 +24,7 @@ packages = [
2424
{ include = "polylith/files", from = "../../components" },
2525
{ include = "polylith/imports", from = "../../components" },
2626
{ include = "polylith/info", from = "../../components" },
27+
{ include = "polylith/interactive",from = "../../components" },
2728
{ include = "polylith/interface", from = "../../components" },
2829
{ include = "polylith/libs", from = "../../components" },
2930
{ include = "polylith/output", from = "../../components" },

0 commit comments

Comments
 (0)