Skip to content

Commit b51e631

Browse files
committed
fix(project): extract pyproject templates into a separate module.
1 parent 851a754 commit b51e631

File tree

3 files changed

+160
-83
lines changed

3 files changed

+160
-83
lines changed

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+
"""

test/components/polylith/project/test_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import tomlkit
3-
from polylith.project.get import (
3+
from polylith.project.templates import (
44
hatch_pyproject_template,
55
pdm_pyproject_template,
66
poetry_pyproject_template,

0 commit comments

Comments
 (0)