diff --git a/bases/polylith/cli/create.py b/bases/polylith/cli/create.py index e686e1d..58e7117 100644 --- a/bases/polylith/cli/create.py +++ b/bases/polylith/cli/create.py @@ -1,6 +1,6 @@ from pathlib import Path -from polylith import project +from polylith import interactive, project from polylith.bricks import base, component from polylith.commands.create import create from polylith.workspace.create import create_workspace @@ -52,7 +52,7 @@ def project_command( """Creates a Polylith project.""" create(name, description, _create_project) - project.interactive.run(name) + interactive.project.run(name) @app.command("workspace") diff --git a/components/polylith/commands/sync.py b/components/polylith/commands/sync.py index c144caa..6a9e13d 100644 --- a/components/polylith/commands/sync.py +++ b/components/polylith/commands/sync.py @@ -1,7 +1,7 @@ from pathlib import Path from typing import Union -from polylith import info, project, sync +from polylith import info, interactive, sync 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]: if not possible_bases: return None - return project.interactive.choose_base_for_project( + return interactive.project.choose_base_for_project( root, ns, project_data["name"], possible_bases ) diff --git a/components/polylith/interactive/__init__.py b/components/polylith/interactive/__init__.py new file mode 100644 index 0000000..7047b7a --- /dev/null +++ b/components/polylith/interactive/__init__.py @@ -0,0 +1,3 @@ +from polylith.interactive import project + +__all__ = ["project"] diff --git a/components/polylith/project/interactive.py b/components/polylith/interactive/project.py similarity index 100% rename from components/polylith/project/interactive.py rename to components/polylith/interactive/project.py diff --git a/components/polylith/poetry/commands/create_project.py b/components/polylith/poetry/commands/create_project.py index 48f3d8e..4cfffd2 100644 --- a/components/polylith/poetry/commands/create_project.py +++ b/components/polylith/poetry/commands/create_project.py @@ -2,7 +2,7 @@ from cleo.helpers import option from poetry.console.commands.command import Command -from polylith import project +from polylith import interactive, project from polylith.commands.create import create command_name = "poly create project" @@ -37,6 +37,6 @@ def handle(self) -> int: create(name, description, create_project) - project.interactive.run(name) + interactive.project.run(name) return 0 diff --git a/components/polylith/project/__init__.py b/components/polylith/project/__init__.py index ca30164..94f75f7 100644 --- a/components/polylith/project/__init__.py +++ b/components/polylith/project/__init__.py @@ -1,4 +1,3 @@ -from polylith.project import interactive from polylith.project.create import create_project from polylith.project.get import ( get_packages_for_projects, @@ -14,6 +13,5 @@ "get_project_name", "get_project_template", "get_toml", - "interactive", "parse_package_paths", ] diff --git a/components/polylith/project/get.py b/components/polylith/project/get.py index d50feea..3465379 100644 --- a/components/polylith/project/get.py +++ b/components/polylith/project/get.py @@ -4,84 +4,7 @@ import tomlkit from polylith import configuration, repo, toml - -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.targets.wheel] -packages = ["{namespace}"] - -[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] -""" +from polylith.project import templates def get_project_name(toml_data) -> str: @@ -147,18 +70,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 poetry_pep621_pyproject_template + return templates.poetry_pep621_pyproject_template - return poetry_pyproject_template + return templates.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 = hatch_pyproject_template + template = templates.hatch_pyproject_template elif repo.is_pdm(pyproject): - template = pdm_pyproject_template + template = templates.pdm_pyproject_template else: raise ValueError("Failed to guess the type of Project") diff --git a/components/polylith/project/templates.py b/components/polylith/project/templates.py new file mode 100644 index 0000000..1d8f2f0 --- /dev/null +++ b/components/polylith/project/templates.py @@ -0,0 +1,154 @@ +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.targets.wheel] +packages = ["{namespace}"] + +[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] +""" +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.targets.wheel] +packages = ["{namespace}"] + +[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] +""" diff --git a/projects/poetry_polylith_plugin/pyproject.toml b/projects/poetry_polylith_plugin/pyproject.toml index 5284467..265a762 100644 --- a/projects/poetry_polylith_plugin/pyproject.toml +++ b/projects/poetry_polylith_plugin/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "poetry-polylith-plugin" -version = "1.45.1" +version = "1.45.2" description = "A Poetry plugin that adds tooling support for the Polylith Architecture" authors = ["David Vujic"] homepage = "https://davidvujic.github.io/python-polylith-docs/" @@ -23,6 +23,7 @@ packages = [ { include = "polylith/files", from = "../../components" }, { include = "polylith/imports", from = "../../components" }, { include = "polylith/info", from = "../../components" }, + { include = "polylith/interactive",from = "../../components" }, { include = "polylith/interface", from = "../../components" }, { include = "polylith/libs", from = "../../components" }, { include = "polylith/output", from = "../../components" }, diff --git a/projects/polylith_cli/pyproject.toml b/projects/polylith_cli/pyproject.toml index c3d788a..e73ebf6 100644 --- a/projects/polylith_cli/pyproject.toml +++ b/projects/polylith_cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polylith-cli" -version = "1.38.1" +version = "1.38.2" description = "Python tooling support for the Polylith Architecture" authors = ['David Vujic'] homepage = "https://davidvujic.github.io/python-polylith-docs/" @@ -24,6 +24,7 @@ packages = [ { include = "polylith/files", from = "../../components" }, { include = "polylith/imports", from = "../../components" }, { include = "polylith/info", from = "../../components" }, + { include = "polylith/interactive",from = "../../components" }, { include = "polylith/interface", from = "../../components" }, { include = "polylith/libs", from = "../../components" }, { include = "polylith/output", from = "../../components" }, diff --git a/pyproject.toml b/pyproject.toml index 6216820..1df142a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ packages = [ { include = "polylith/hatch", from = "components" }, { include = "polylith/imports", from = "components" }, { include = "polylith/info", from = "components" }, + { include = "polylith/interactive",from = "components" }, { include = "polylith/interface", from = "components" }, { include = "polylith/libs", from = "components" }, { include = "polylith/output", from = "components" }, diff --git a/test/components/polylith/project/test_templates.py b/test/components/polylith/project/test_templates.py index e7f024e..771add7 100644 --- a/test/components/polylith/project/test_templates.py +++ b/test/components/polylith/project/test_templates.py @@ -1,6 +1,6 @@ import pytest import tomlkit -from polylith.project.get import ( +from polylith.project.templates import ( hatch_pyproject_template, pdm_pyproject_template, poetry_pyproject_template,