Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions components/polylith/project/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from polylith.project import interactive, templates
from polylith.project import interactive
from polylith.project.create import create_project
from polylith.project.get import (
get_packages_for_projects,
Expand All @@ -16,5 +16,4 @@
"get_toml",
"interactive",
"parse_package_paths",
"templates",
]
84 changes: 79 additions & 5 deletions components/polylith/project/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,81 @@

import tomlkit
from polylith import configuration, repo, toml
from polylith.project import templates

poetry_pyproject_template = """\
[tool.poetry]
name = "{name}"
version = "0.1.0"
{description}
{authors}
license = ""

packages = []

[tool.poetry.dependencies]
python = "{python_version}"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
"""

poetry_pep621_pyproject_template = """\
[tool.poetry]
packages = []

[project]
name = "{name}"
version = "0.1.0"
{description}
{authors}

requires-python = "{python_version}"

dependencies = []

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
"""

hatch_pyproject_template = """\
[build-system]
requires = ["hatchling", "hatch-polylith-bricks"]
build-backend = "hatchling.build"

[project]
name = "{name}"
version = "0.1.0"
{description}
{authors}

requires-python = "{python_version}"

dependencies = []

[tool.hatch.build.hooks.polylith-bricks]

[tool.polylith.bricks]
"""

pdm_pyproject_template = """\
[build-system]
requires = ["pdm-backend", "pdm-polylith-bricks"]
build-backend = "pdm.backend"

[project]
name = "{name}"
version = "0.1.0"
{description}
{authors}

requires-python = "{python_version}"

dependencies = []

[tool.polylith.bricks]
"""


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

def _get_poetry_template(pyproject: dict) -> str:
if repo.is_pep_621_ready(pyproject):
return templates.poetry_pep621_pyproject
return poetry_pep621_pyproject_template

return templates.poetry_pyproject
return poetry_pyproject_template


def guess_project_template(pyproject: dict) -> str:
if repo.is_poetry(pyproject):
template = _get_poetry_template(pyproject)
elif repo.is_hatch(pyproject):
template = templates.hatch_pyproject
template = hatch_pyproject_template
elif repo.is_pdm(pyproject):
template = templates.pdm_pyproject
template = pdm_pyproject_template
else:
raise ValueError("Failed to guess the type of Project")

Expand Down
74 changes: 0 additions & 74 deletions components/polylith/project/templates.py

This file was deleted.

2 changes: 1 addition & 1 deletion projects/poetry_polylith_plugin/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetry-polylith-plugin"
version = "1.42.0"
version = "1.42.1"
description = "A Poetry plugin that adds tooling support for the Polylith Architecture"
authors = ["David Vujic"]
homepage = "https://davidvujic.github.io/python-polylith-docs/"
Expand Down
2 changes: 1 addition & 1 deletion projects/polylith_cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "polylith-cli"
version = "1.35.0"
version = "1.35.1"
description = "Python tooling support for the Polylith Architecture"
authors = ['David Vujic']
homepage = "https://davidvujic.github.io/python-polylith-docs/"
Expand Down
16 changes: 10 additions & 6 deletions test/components/polylith/project/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import pytest
import tomlkit
from polylith.project import templates
from polylith.project.get import (
hatch_pyproject_template,
pdm_pyproject_template,
poetry_pyproject_template,
)

template_data = {
"name": "a project",
Expand Down Expand Up @@ -36,7 +40,7 @@ def to_toml(template: str, data: dict):


def test_poetry_template():
data = to_toml(templates.poetry_pyproject, template_data)
data = to_toml(poetry_pyproject_template, template_data)

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

data = to_toml(
templates.poetry_pyproject,
poetry_pyproject_template,
with_poetry_optionals(expected_description, expected_author),
)

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


def test_hatch_template():
data = to_toml(templates.hatch_pyproject, template_data)
data = to_toml(hatch_pyproject_template, template_data)

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


def test_pdm_template():
data = to_toml(templates.pdm_pyproject, template_data)
data = to_toml(pdm_pyproject_template, template_data)

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

template = {"hatch": templates.hatch_pyproject, "pdm": templates.pdm_pyproject}
template = {"hatch": hatch_pyproject_template, "pdm": pdm_pyproject_template}

data = to_toml(
template[name],
Expand Down