|
1 | 1 | from pathlib import Path |
2 | | -from typing import Union |
3 | 2 |
|
4 | 3 | import tomlkit |
5 | 4 | from polylith import repo |
6 | 5 | from polylith.dirs import create_dir |
7 | 6 | from polylith.repo import projects_dir |
8 | 7 |
|
9 | | -template = """\ |
10 | | -[tool.poetry] |
11 | | -name = "{name}" |
12 | | -version = "0.1.0" |
13 | | -description = "{description}" |
14 | | -authors = {authors} |
15 | | -license = "" |
16 | 8 |
|
17 | | -packages = [] |
18 | | -
|
19 | | -[tool.poetry.dependencies] |
20 | | -python = "{python_version}" |
21 | | -
|
22 | | -[tool.poetry.group.dev.dependencies] |
23 | | -
|
24 | | -[build-system] |
25 | | -requires = ["poetry-core>=1.0.0"] |
26 | | -build-backend = "poetry.core.masonry.api" |
27 | | -""" |
28 | | - |
29 | | - |
30 | | -def get_workspace_toml(path: Path) -> dict: |
31 | | - with open(str(path / repo.default_toml), "r", errors="ignore") as f: |
32 | | - data: dict = tomlkit.loads(f.read()) |
33 | | - |
34 | | - return data |
35 | | - |
36 | | - |
37 | | -def create_project_toml( |
38 | | - name: str, template: str, workspace_toml: dict, description: str |
39 | | -) -> tomlkit.TOMLDocument: |
40 | | - authors = workspace_toml["tool"]["poetry"]["authors"] |
41 | | - python_version = workspace_toml["tool"]["poetry"]["dependencies"]["python"] |
42 | | - |
43 | | - content = template.format( |
44 | | - name=name, |
45 | | - description=description, |
46 | | - authors=authors, |
47 | | - python_version=python_version, |
48 | | - ) |
| 9 | +def create_project_toml(template: str, template_data: dict) -> tomlkit.TOMLDocument: |
| 10 | + content = template.format(**template_data) |
49 | 11 |
|
50 | 12 | return tomlkit.loads(content) |
51 | 13 |
|
52 | 14 |
|
53 | | -def create_project( |
54 | | - path: Path, _namespace: str, name: str, description: Union[str, None] |
55 | | -) -> None: |
| 15 | +def create_project(path: Path, template: str, name: str, description: str) -> None: |
56 | 16 | d = create_dir(path, f"{projects_dir}/{name}") |
57 | 17 |
|
58 | | - workspace_toml = get_workspace_toml(path) |
| 18 | + authors = repo.get_authors(path) |
| 19 | + python_version = repo.get_python_version(path) |
| 20 | + |
59 | 21 | project_toml = create_project_toml( |
60 | | - name, template, workspace_toml, description or "" |
| 22 | + template, |
| 23 | + { |
| 24 | + "name": name, |
| 25 | + "description": description, |
| 26 | + "authors": authors, |
| 27 | + "python_version": python_version, |
| 28 | + }, |
61 | 29 | ) |
62 | 30 |
|
63 | 31 | fullpath = d / repo.default_toml |
|
0 commit comments