polylith-cli 1.2.0__tar.gz → 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/PKG-INFO +1 -1
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/bricks/brick.py +4 -4
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/bricks/component.py +2 -2
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/check/collect.py +3 -3
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/check/report.py +1 -1
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/cli/core.py +22 -12
- polylith_cli-1.3.0/polylith_cli/polylith/commands/__init__.py +2 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/commands/create.py +2 -2
- polylith_cli-1.3.0/polylith_cli/polylith/commands/deps.py +28 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/commands/diff.py +2 -2
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/commands/info.py +2 -2
- polylith_cli-1.3.0/polylith_cli/polylith/configuration/__init__.py +2 -0
- polylith_cli-1.3.0/polylith_cli/polylith/deps/__init__.py +3 -0
- polylith_cli-1.3.0/polylith_cli/polylith/deps/core.py +10 -0
- polylith_cli-1.3.0/polylith_cli/polylith/deps/report.py +57 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/diff/collect.py +2 -2
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/info/report.py +1 -1
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/libs/grouping.py +2 -2
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/project/get.py +2 -2
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/reporting/theme.py +2 -0
- polylith_cli-1.3.0/polylith_cli/polylith/sync/collect.py +18 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/sync/report.py +1 -1
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/sync/update.py +2 -2
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/test/tests.py +3 -3
- polylith_cli-1.3.0/polylith_cli/polylith/workspace/__init__.py +2 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/workspace/paths.py +2 -3
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/pyproject.toml +1 -1
- polylith_cli-1.2.0/polylith_cli/polylith/commands/__init__.py +0 -2
- polylith_cli-1.2.0/polylith_cli/polylith/sync/collect.py +0 -27
- polylith_cli-1.2.0/polylith_cli/polylith/workspace/__init__.py +0 -2
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/README.md +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/alias/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/alias/core.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/bricks/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/bricks/base.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/check/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/check/grouping.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/cli/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/cli/__main__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/cli/create.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/cli/options.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/commands/check.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/commands/libs.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/commands/sync.py +0 -0
- /polylith_cli-1.2.0/polylith_cli/polylith/workspace/parser.py → /polylith_cli-1.3.0/polylith_cli/polylith/configuration/core.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/development/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/development/development.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/diff/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/diff/report.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/dirs/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/dirs/dirs.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/distributions/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/distributions/collect.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/distributions/core.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/files/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/files/files.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/imports/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/imports/parser.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/info/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/info/collect.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/interface/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/interface/interfaces.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/libs/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/libs/report.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/libs/stdlib.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/project/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/project/create.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/project/parser.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/project/templates.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/readme/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/readme/readme.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/repo/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/repo/get.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/repo/repo.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/reporting/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/sync/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/test/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/toml/__init__.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/toml/core.py +0 -0
- {polylith_cli-1.2.0 → polylith_cli-1.3.0}/polylith_cli/polylith/workspace/create.py +0 -0
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
+
from polylith_cli.polylith import configuration
|
|
2
3
|
from polylith_cli.polylith.dirs import create_dir
|
|
3
4
|
from polylith_cli.polylith.files import create_file
|
|
4
5
|
from polylith_cli.polylith.interface import create_interface
|
|
5
6
|
from polylith_cli.polylith.readme import create_brick_readme
|
|
6
|
-
from polylith_cli.polylith.workspace import parser
|
|
7
7
|
|
|
8
8
|
def create_brick(root: Path, options: dict) -> None:
|
|
9
9
|
modulename = options['modulename']
|
|
10
10
|
path_kwargs = {k: v for k, v in options.items() if k in {'brick', 'namespace', 'package'}}
|
|
11
|
-
brick_structure =
|
|
12
|
-
resources_structure =
|
|
11
|
+
brick_structure = configuration.get_brick_structure_from_config(root)
|
|
12
|
+
resources_structure = configuration.get_resources_structure_from_config(root)
|
|
13
13
|
brick_path = brick_structure.format(**path_kwargs)
|
|
14
14
|
resources_path = resources_structure.format(**path_kwargs)
|
|
15
15
|
d = create_dir(root, brick_path)
|
|
16
16
|
create_file(d, f'{modulename}.py')
|
|
17
17
|
create_interface(d, options)
|
|
18
|
-
if
|
|
18
|
+
if configuration.is_readme_generation_enabled(root):
|
|
19
19
|
create_brick_readme(root / resources_path, options)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
from typing import List
|
|
3
|
-
from polylith_cli.polylith import
|
|
3
|
+
from polylith_cli.polylith import configuration
|
|
4
4
|
from polylith_cli.polylith.bricks.brick import create_brick
|
|
5
5
|
from polylith_cli.polylith.repo import components_dir
|
|
6
6
|
from polylith_cli.polylith.test import create_test
|
|
@@ -15,7 +15,7 @@ def is_brick_dir(p: Path) -> bool:
|
|
|
15
15
|
return p.is_dir() and p.name not in {'__pycache__', '.venv', '.mypy_cache'}
|
|
16
16
|
|
|
17
17
|
def get_component_dirs(root: Path, top_dir, ns) -> list:
|
|
18
|
-
theme =
|
|
18
|
+
theme = configuration.get_theme_from_config(root)
|
|
19
19
|
dirs = top_dir if theme == 'tdd' else f'{top_dir}/{ns}'
|
|
20
20
|
component_dir = root / dirs
|
|
21
21
|
if not component_dir.exists():
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Set
|
|
3
3
|
from polylith_cli.polylith import check, imports, workspace
|
|
4
4
|
|
|
5
5
|
def extract_bricks(paths: Set[Path], ns: str) -> dict:
|
|
@@ -19,11 +19,11 @@ def with_unknown_components(root: Path, ns: str, brick_imports: dict) -> dict:
|
|
|
19
19
|
collected = {**brick_imports, **extracted}
|
|
20
20
|
return with_unknown_components(root, ns, collected)
|
|
21
21
|
|
|
22
|
-
def diff(known_bricks: Set[str], bases:
|
|
22
|
+
def diff(known_bricks: Set[str], bases: Set[str], components: Set[str]) -> Set[str]:
|
|
23
23
|
bricks = set().union(bases, components)
|
|
24
24
|
return known_bricks.difference(bricks)
|
|
25
25
|
|
|
26
|
-
def imports_diff(brick_imports: dict, bases:
|
|
26
|
+
def imports_diff(brick_imports: dict, bases: Set[str], components: Set[str]) -> Set[str]:
|
|
27
27
|
flattened_bases = set().union(*brick_imports['bases'].values())
|
|
28
28
|
flattened_components = set().union(*brick_imports['components'].values())
|
|
29
29
|
flattened_imports = set().union(flattened_bases, flattened_components)
|
|
@@ -42,6 +42,6 @@ def create_report(project_data: dict, collected_imports: dict, third_party_libs:
|
|
|
42
42
|
components = {c for c in project_data.get('components', [])}
|
|
43
43
|
brick_imports = collected_imports['brick_imports']
|
|
44
44
|
third_party_imports = collected_imports['third_party_imports']
|
|
45
|
-
brick_diff = collect.imports_diff(brick_imports,
|
|
45
|
+
brick_diff = collect.imports_diff(brick_imports, bases, components)
|
|
46
46
|
libs_diff = libs.report.calculate_diff(third_party_imports, third_party_libs, is_strict)
|
|
47
47
|
return {'brick_imports': brick_imports, 'third_party_imports': third_party_imports, 'brick_diff': brick_diff, 'libs_diff': libs_diff}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
-
from
|
|
2
|
+
from typing import List, Union
|
|
3
|
+
from polylith_cli.polylith import commands, configuration, info, repo
|
|
3
4
|
from polylith_cli.polylith.cli import create, options
|
|
4
5
|
from typer import Exit, Option, Typer
|
|
5
6
|
from typing_extensions import Annotated
|
|
6
7
|
app = Typer()
|
|
7
8
|
app.add_typer(create.app, name='create', help='Commands for creating a workspace, bases, components and projects.')
|
|
8
9
|
|
|
10
|
+
def filtered_projects_data(projects_data: List[dict], directory: Union[str, None]) -> List[dict]:
|
|
11
|
+
dir_path = Path(directory).as_posix() if directory else Path.cwd().name
|
|
12
|
+
return [p for p in projects_data if dir_path in p['path'].as_posix()]
|
|
13
|
+
|
|
9
14
|
@app.command('info')
|
|
10
15
|
def info_command(short: Annotated[bool, options.short_workspace]=False):
|
|
11
16
|
"""Info about the Polylith workspace."""
|
|
@@ -15,12 +20,11 @@ def info_command(short: Annotated[bool, options.short_workspace]=False):
|
|
|
15
20
|
def check_command(strict: Annotated[bool, options.strict]=False, verbose: Annotated[bool, options.verbose]=False, quiet: Annotated[bool, options.quiet]=False, directory: Annotated[str, options.directory]='', alias: Annotated[str, options.alias]=''):
|
|
16
21
|
"""Validates the Polylith workspace."""
|
|
17
22
|
root = repo.get_workspace_root(Path.cwd())
|
|
18
|
-
ns =
|
|
23
|
+
ns = configuration.get_namespace_from_config(root)
|
|
19
24
|
all_projects_data = info.get_projects_data(root, ns)
|
|
20
25
|
only_projects_data = [p for p in all_projects_data if info.is_project(p)]
|
|
21
26
|
cli_options = {'verbose': verbose, 'quiet': quiet, 'strict': strict, 'alias': str.split(alias, ',') if alias else []}
|
|
22
|
-
|
|
23
|
-
projects_data = [p for p in only_projects_data if dir_path in p['path'].as_posix()]
|
|
27
|
+
projects_data = filtered_projects_data(only_projects_data, directory)
|
|
24
28
|
results = {commands.check.run(root, ns, p, cli_options) for p in projects_data}
|
|
25
29
|
if not all(results):
|
|
26
30
|
raise Exit(code=1)
|
|
@@ -34,11 +38,10 @@ def diff_command(since: Annotated[str, Option(help='Changed since a specific tag
|
|
|
34
38
|
def libs_command(strict: Annotated[bool, options.strict]=False, directory: Annotated[str, options.directory]='', alias: Annotated[str, options.alias]=''):
|
|
35
39
|
"""Show third-party libraries used in the workspace."""
|
|
36
40
|
root = repo.get_workspace_root(Path.cwd())
|
|
37
|
-
ns =
|
|
38
|
-
|
|
41
|
+
ns = configuration.get_namespace_from_config(root)
|
|
42
|
+
all_projects_data = info.get_projects_data(root, ns)
|
|
39
43
|
cli_options = {'strict': strict, 'alias': str.split(alias, ',') if alias else []}
|
|
40
|
-
|
|
41
|
-
projects_data = [p for p in projects_data if dir_path in p['path'].as_posix()]
|
|
44
|
+
projects_data = filtered_projects_data(all_projects_data, directory)
|
|
42
45
|
results = {commands.libs.run(root, ns, p, cli_options) for p in projects_data}
|
|
43
46
|
if not all(results):
|
|
44
47
|
raise Exit(code=1)
|
|
@@ -47,12 +50,19 @@ def libs_command(strict: Annotated[bool, options.strict]=False, directory: Annot
|
|
|
47
50
|
def sync_command(strict: Annotated[bool, options.strict]=False, quiet: Annotated[bool, options.quiet]=False, directory: Annotated[str, options.directory]='', verbose: Annotated[str, options.verbose]=''):
|
|
48
51
|
"""Update pyproject.toml with missing bricks."""
|
|
49
52
|
root = repo.get_workspace_root(Path.cwd())
|
|
50
|
-
ns =
|
|
51
|
-
|
|
53
|
+
ns = configuration.get_namespace_from_config(root)
|
|
54
|
+
all_projects_data = info.get_projects_data(root, ns)
|
|
52
55
|
cli_options = {'strict': strict, 'quiet': quiet, 'verbose': verbose}
|
|
53
|
-
|
|
54
|
-
projects_data = [p for p in projects_data if dir_path in p['path'].as_posix()]
|
|
56
|
+
projects_data = filtered_projects_data(all_projects_data, directory)
|
|
55
57
|
for p in projects_data:
|
|
56
58
|
commands.sync.run(root, ns, p, cli_options)
|
|
59
|
+
|
|
60
|
+
@app.command('deps')
|
|
61
|
+
def deps_command(directory: Annotated[str, options.directory]=''):
|
|
62
|
+
"""Visualize the dependencies between bricks."""
|
|
63
|
+
root = repo.get_workspace_root(Path.cwd())
|
|
64
|
+
ns = configuration.get_namespace_from_config(root)
|
|
65
|
+
dir_path = Path(directory).as_posix() if directory else None
|
|
66
|
+
commands.deps.run(root, ns, dir_path)
|
|
57
67
|
if __name__ == '__main__':
|
|
58
68
|
app()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
from typing import Union
|
|
3
|
-
from polylith_cli.polylith import
|
|
3
|
+
from polylith_cli.polylith import configuration, repo
|
|
4
4
|
|
|
5
5
|
def create(name: Union[str, None], description: Union[str, None], fn):
|
|
6
6
|
root = repo.get_workspace_root(Path.cwd())
|
|
7
|
-
namespace =
|
|
7
|
+
namespace = configuration.get_namespace_from_config(root)
|
|
8
8
|
if not name:
|
|
9
9
|
raise ValueError('Please add a name by using --name')
|
|
10
10
|
if not namespace:
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import List, Set, Union
|
|
3
|
+
from polylith_cli.polylith import bricks, deps, info
|
|
4
|
+
|
|
5
|
+
def print_report(root: Path, ns: str, bases: Set[str], components: Set[str]):
|
|
6
|
+
brick_imports = deps.get_brick_imports(root, ns, bases, components)
|
|
7
|
+
flattened = {**brick_imports['bases'], **brick_imports['components']}
|
|
8
|
+
deps.print_deps(bases, components, flattened)
|
|
9
|
+
|
|
10
|
+
def pick_name(data: List[dict]) -> Set[str]:
|
|
11
|
+
return {b['name'] for b in data}
|
|
12
|
+
|
|
13
|
+
def get_bases(root: Path, ns: str, project_data: dict) -> Set[str]:
|
|
14
|
+
if project_data:
|
|
15
|
+
return set(project_data.get('bases', []))
|
|
16
|
+
return pick_name(bricks.get_bases_data(root, ns))
|
|
17
|
+
|
|
18
|
+
def get_components(root: Path, ns: str, project_data: dict) -> Set[str]:
|
|
19
|
+
if project_data:
|
|
20
|
+
return set(project_data.get('components', []))
|
|
21
|
+
return pick_name(bricks.get_components_data(root, ns))
|
|
22
|
+
|
|
23
|
+
def run(root: Path, ns: str, directory: Union[str, None]):
|
|
24
|
+
projects_data = info.get_projects_data(root, ns) if directory else []
|
|
25
|
+
project = next((p for p in projects_data if directory in p['path'].as_posix()), {})
|
|
26
|
+
bases = get_bases(root, ns, project)
|
|
27
|
+
components = get_components(root, ns, project)
|
|
28
|
+
print_report(root, ns, bases, components)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
from typing import Union
|
|
3
|
-
from polylith_cli.polylith import diff, info, repo
|
|
3
|
+
from polylith_cli.polylith import configuration, diff, info, repo
|
|
4
4
|
|
|
5
5
|
def print_views(root: Path, tag: str, short: bool, only_bricks: bool) -> None:
|
|
6
|
-
ns =
|
|
6
|
+
ns = configuration.get_namespace_from_config(root)
|
|
7
7
|
files = diff.collect.get_files(tag)
|
|
8
8
|
bases = diff.collect.get_changed_bases(files, ns)
|
|
9
9
|
components = diff.collect.get_changed_components(files, ns)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
-
from polylith_cli.polylith import info, repo
|
|
2
|
+
from polylith_cli.polylith import configuration, info, repo
|
|
3
3
|
|
|
4
4
|
def run(short: bool):
|
|
5
5
|
root = repo.get_workspace_root(Path.cwd())
|
|
6
|
-
ns =
|
|
6
|
+
ns = configuration.get_namespace_from_config(root)
|
|
7
7
|
bases = info.get_bases(root, ns)
|
|
8
8
|
components = info.get_components(root, ns)
|
|
9
9
|
projects_data = info.get_bricks_in_projects(root, components, bases, ns)
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
from polylith_cli.polylith.configuration.core import get_brick_structure_from_config, get_namespace_from_config, get_resources_structure_from_config, get_tag_pattern_from_config, get_tests_structure_from_config, get_theme_from_config, is_readme_generation_enabled, is_test_generation_enabled
|
|
2
|
+
__all__ = ['get_brick_structure_from_config', 'get_namespace_from_config', 'get_resources_structure_from_config', 'get_tag_pattern_from_config', 'get_tests_structure_from_config', 'get_theme_from_config', 'is_readme_generation_enabled', 'is_test_generation_enabled']
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Set
|
|
3
|
+
from polylith_cli.polylith import check, workspace
|
|
4
|
+
|
|
5
|
+
def get_brick_imports(root: Path, ns: str, bases: Set[str], components: Set[str]) -> dict:
|
|
6
|
+
bases_paths = workspace.paths.collect_bases_paths(root, ns, bases)
|
|
7
|
+
comp_paths = workspace.paths.collect_components_paths(root, ns, components)
|
|
8
|
+
brick_imports_in_bases = check.collect.extract_bricks(bases_paths, ns)
|
|
9
|
+
brick_imports_in_components = check.collect.extract_bricks(comp_paths, ns)
|
|
10
|
+
return {'bases': check.collect.with_unknown_components(root, ns, brick_imports_in_bases), 'components': check.collect.with_unknown_components(root, ns, brick_imports_in_components)}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from functools import reduce
|
|
2
|
+
from typing import List, Set, Tuple
|
|
3
|
+
from polylith_cli.polylith.reporting import theme
|
|
4
|
+
from rich import box
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
from rich.table import Table
|
|
7
|
+
|
|
8
|
+
def calculate_tag(brick: str, project_data: dict) -> str:
|
|
9
|
+
return 'base' if brick in project_data.get('bases', []) else 'comp'
|
|
10
|
+
|
|
11
|
+
def to_col(brick: str, tag: str) -> str:
|
|
12
|
+
name = '\n'.join(brick)
|
|
13
|
+
return f'[{tag}]{name}[/]'
|
|
14
|
+
|
|
15
|
+
def brick_status(bricks: List[str], brick_name: str, imported: str) -> str:
|
|
16
|
+
status = theme.check_emoji if imported in bricks and imported != brick_name else '-'
|
|
17
|
+
return f'[data]{status}[/]'
|
|
18
|
+
|
|
19
|
+
def to_row(name: str, tag: str, brick_imports: dict, imported: List[str]) -> List[str]:
|
|
20
|
+
bricks = brick_imports[name]
|
|
21
|
+
statuses = [brick_status(bricks, name, i) for i in imported]
|
|
22
|
+
return [f'[{tag}]{name}[/]'] + statuses
|
|
23
|
+
|
|
24
|
+
def flatten_import(acc: Set[str], kv: Tuple[str, Set[str]]) -> set:
|
|
25
|
+
key = kv[0]
|
|
26
|
+
values = kv[1]
|
|
27
|
+
return set().union(acc, values.difference({key}))
|
|
28
|
+
|
|
29
|
+
def flatten_imports(brick_imports: dict) -> Set[str]:
|
|
30
|
+
"""Flatten the dict into a set of imports, with the actual brick filtered away when existing as an import"""
|
|
31
|
+
return reduce(flatten_import, brick_imports.items(), set())
|
|
32
|
+
|
|
33
|
+
def create_columns(imported_bases: List[str], imported_components: List[str]) -> List[str]:
|
|
34
|
+
base_cols = [to_col(brick, 'base') for brick in imported_bases]
|
|
35
|
+
comp_cols = [to_col(brick, 'comp') for brick in imported_components]
|
|
36
|
+
return comp_cols + base_cols
|
|
37
|
+
|
|
38
|
+
def create_rows(bases: Set[str], components: Set[str], import_data: dict, imported: List[str]) -> List[List[str]]:
|
|
39
|
+
base_rows = [to_row(b, 'base', import_data, imported) for b in sorted(bases)]
|
|
40
|
+
comp_rows = [to_row(c, 'comp', import_data, imported) for c in sorted(components)]
|
|
41
|
+
return comp_rows + base_rows
|
|
42
|
+
|
|
43
|
+
def print_deps(bases: Set[str], components: Set[str], import_data: dict):
|
|
44
|
+
flattened = flatten_imports(import_data)
|
|
45
|
+
imported_bases = sorted({b for b in flattened if b in bases})
|
|
46
|
+
imported_components = sorted({c for c in flattened if c in components})
|
|
47
|
+
imported_bricks = imported_components + imported_bases
|
|
48
|
+
table = Table(box=box.SIMPLE_HEAD)
|
|
49
|
+
table.add_column('[data]brick[/]')
|
|
50
|
+
cols = create_columns(imported_bases, imported_components)
|
|
51
|
+
rows = create_rows(bases, components, import_data, imported_bricks)
|
|
52
|
+
for col in cols:
|
|
53
|
+
table.add_column(col, justify='center')
|
|
54
|
+
for row in rows:
|
|
55
|
+
table.add_row(*row)
|
|
56
|
+
console = Console(theme=theme.poly_theme)
|
|
57
|
+
console.print(table, overflow='ellipsis')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import subprocess
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
from typing import List, Set, Union
|
|
4
|
-
from polylith_cli.polylith import
|
|
4
|
+
from polylith_cli.polylith import configuration, repo
|
|
5
5
|
|
|
6
6
|
def _parse_folder_parts(folder: str, changed_file: Path) -> str:
|
|
7
7
|
file_path = Path(changed_file.as_posix().replace(folder, ''))
|
|
@@ -26,7 +26,7 @@ def get_changed_projects(changed_files: List[Path]) -> list:
|
|
|
26
26
|
return sorted(filtered)
|
|
27
27
|
|
|
28
28
|
def get_latest_tag(root: Path, key: Union[str, None]) -> Union[str, None]:
|
|
29
|
-
tag_pattern =
|
|
29
|
+
tag_pattern = configuration.get_tag_pattern_from_config(root, key)
|
|
30
30
|
res = subprocess.run(['git', 'tag', '-l', '--sort=-committerdate', f'{tag_pattern}'], capture_output=True)
|
|
31
31
|
return next((tag for tag in res.stdout.decode('utf-8').split()), None)
|
|
32
32
|
|
|
@@ -6,7 +6,7 @@ from rich.padding import Padding
|
|
|
6
6
|
from rich.table import Table
|
|
7
7
|
|
|
8
8
|
def brick_status(brick, bricks, command: str) -> str:
|
|
9
|
-
emoji =
|
|
9
|
+
emoji = theme.check_emoji if command == 'info' else ':gear:'
|
|
10
10
|
status = emoji if brick in bricks else '-'
|
|
11
11
|
return f'[data]{status}[/]'
|
|
12
12
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
from typing import Set
|
|
4
|
-
from polylith_cli.polylith import
|
|
4
|
+
from polylith_cli.polylith import configuration
|
|
5
5
|
from polylith_cli.polylith.imports import extract_top_ns, fetch_all_imports
|
|
6
6
|
from polylith_cli.polylith.libs.stdlib import standard_libs
|
|
7
7
|
|
|
@@ -30,6 +30,6 @@ def extract_third_party_imports(all_imports: dict, top_ns: str) -> dict:
|
|
|
30
30
|
return exclude_empty(with_third_party)
|
|
31
31
|
|
|
32
32
|
def get_third_party_imports(root: Path, paths: Set[Path]) -> dict:
|
|
33
|
-
top_ns =
|
|
33
|
+
top_ns = configuration.get_namespace_from_config(root)
|
|
34
34
|
all_imports = fetch_all_imports(paths)
|
|
35
35
|
return extract_third_party_imports(all_imports, top_ns)
|
|
@@ -2,7 +2,7 @@ from functools import lru_cache
|
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
from typing import List
|
|
4
4
|
import tomlkit
|
|
5
|
-
from polylith_cli.polylith import repo, toml
|
|
5
|
+
from polylith_cli.polylith import configuration, repo, toml
|
|
6
6
|
|
|
7
7
|
def get_project_name(data) -> str:
|
|
8
8
|
if repo.is_pep_621_ready(data):
|
|
@@ -31,5 +31,5 @@ def get_toml_files(root: Path) -> List[dict]:
|
|
|
31
31
|
|
|
32
32
|
def get_packages_for_projects(root: Path) -> List[dict]:
|
|
33
33
|
toml_files = get_toml_files(root)
|
|
34
|
-
namespace =
|
|
34
|
+
namespace = configuration.get_namespace_from_config(root)
|
|
35
35
|
return [{'name': get_project_name(d['toml']), 'packages': toml.get_project_package_includes(namespace, d['toml']), 'path': d['path'], 'type': d['type'], 'deps': toml.get_project_dependencies(d['toml'])} for d in toml_files]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from polylith_cli.polylith import check, deps, info
|
|
3
|
+
|
|
4
|
+
def calculate_diff(root: Path, namespace: str, project_data: dict, workspace_data: dict) -> dict:
|
|
5
|
+
bases = set(project_data['bases'])
|
|
6
|
+
components = set(project_data['components'])
|
|
7
|
+
all_bases = workspace_data['bases']
|
|
8
|
+
all_components = workspace_data['components']
|
|
9
|
+
brick_imports = deps.get_brick_imports(root, namespace, bases, components)
|
|
10
|
+
is_project = info.is_project(project_data)
|
|
11
|
+
if is_project:
|
|
12
|
+
brick_diff = check.collect.imports_diff(brick_imports, bases, components)
|
|
13
|
+
else:
|
|
14
|
+
all_bricks = set().union(all_bases, all_components)
|
|
15
|
+
brick_diff = check.collect.diff(all_bricks, bases, components)
|
|
16
|
+
bases_diff = {b for b in brick_diff if b in all_bases}
|
|
17
|
+
components_diff = {b for b in brick_diff if b in all_components}
|
|
18
|
+
return {'name': project_data['name'], 'path': project_data['path'], 'is_project': is_project, 'bases': bases_diff, 'components': components_diff, 'brick_imports': brick_imports}
|
|
@@ -13,7 +13,7 @@ def print_summary(diff: dict) -> None:
|
|
|
13
13
|
bases = diff['bases']
|
|
14
14
|
components = diff['components']
|
|
15
15
|
anything_to_sync = bases or components
|
|
16
|
-
emoji = ':point_right:' if anything_to_sync else
|
|
16
|
+
emoji = ':point_right:' if anything_to_sync else theme.check_emoji
|
|
17
17
|
printable_name = f'[proj]{name}[/]' if is_project else f'[data]{name}[/]'
|
|
18
18
|
console.print(f'{emoji} {printable_name}')
|
|
19
19
|
for b in bases:
|
|
@@ -2,7 +2,7 @@ from functools import reduce
|
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
from typing import List, Union
|
|
4
4
|
import tomlkit
|
|
5
|
-
from polylith_cli.polylith import project, repo
|
|
5
|
+
from polylith_cli.polylith import configuration, project, repo
|
|
6
6
|
from tomlkit.toml_document import TOMLDocument
|
|
7
7
|
|
|
8
8
|
def to_package(namespace: str, brick: str, brick_path: str, theme: str) -> dict:
|
|
@@ -66,7 +66,7 @@ def generate_updated_project(data: TOMLDocument, packages: List[dict]) -> Union[
|
|
|
66
66
|
return None
|
|
67
67
|
|
|
68
68
|
def to_packages(root: Path, namespace: str, diff: dict) -> List[dict]:
|
|
69
|
-
theme =
|
|
69
|
+
theme = configuration.get_theme_from_config(root)
|
|
70
70
|
is_project = diff['is_project']
|
|
71
71
|
bases_path = '../../bases' if is_project else 'bases'
|
|
72
72
|
components_path = '../../components' if is_project else 'components'
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
from polylith_cli.polylith.dirs import create_dir
|
|
3
3
|
from polylith_cli.polylith.files import create_file
|
|
4
|
-
from polylith_cli.polylith
|
|
4
|
+
from polylith_cli.polylith import configuration
|
|
5
5
|
template = 'from {namespace}.{package} import {modulename}\n\n\ndef test_sample():\n assert {modulename} is not None\n'
|
|
6
6
|
|
|
7
7
|
def create_test(root: Path, options: dict) -> None:
|
|
8
|
-
if not
|
|
8
|
+
if not configuration.is_test_generation_enabled(root):
|
|
9
9
|
return
|
|
10
10
|
brick = options['brick']
|
|
11
11
|
namespace = options['namespace']
|
|
12
12
|
package = options['package']
|
|
13
13
|
modulename = options['modulename']
|
|
14
|
-
dirs_structure =
|
|
14
|
+
dirs_structure = configuration.get_tests_structure_from_config(root)
|
|
15
15
|
dirs = dirs_structure.format(brick=brick, namespace=namespace, package=package)
|
|
16
16
|
d = create_dir(root, dirs)
|
|
17
17
|
create_file(d, '__init__.py')
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
from typing import Set
|
|
3
|
-
from polylith_cli.polylith import repo
|
|
4
|
-
from polylith_cli.polylith.workspace import parser
|
|
3
|
+
from polylith_cli.polylith import configuration, repo
|
|
5
4
|
|
|
6
5
|
def get_path(structure: str, brick: str, ns: str, package: str) -> str:
|
|
7
6
|
return structure.format(brick=brick, namespace=ns, package=package)
|
|
@@ -10,7 +9,7 @@ def get_paths(structure: str, brick: str, ns: str, packages: Set[str]) -> Set[st
|
|
|
10
9
|
return {get_path(structure, brick, ns, p) for p in packages}
|
|
11
10
|
|
|
12
11
|
def collect_paths(root: Path, ns: str, brick: str, packages: Set[str]) -> Set[Path]:
|
|
13
|
-
structure =
|
|
12
|
+
structure = configuration.get_brick_structure_from_config(root)
|
|
14
13
|
paths = get_paths(structure, brick, ns, packages)
|
|
15
14
|
return {Path(root / p) for p in paths}
|
|
16
15
|
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
from polylith_cli.polylith import check, info, workspace
|
|
3
|
-
|
|
4
|
-
def get_brick_imports(root: Path, ns: str, project_data: dict) -> dict:
|
|
5
|
-
bases = {b for b in project_data.get('bases', [])}
|
|
6
|
-
components = {c for c in project_data.get('components', [])}
|
|
7
|
-
bases_paths = workspace.paths.collect_bases_paths(root, ns, bases)
|
|
8
|
-
components_paths = workspace.paths.collect_components_paths(root, ns, components)
|
|
9
|
-
brick_imports_in_bases = check.collect.extract_bricks(bases_paths, ns)
|
|
10
|
-
brick_imports_in_components = check.collect.extract_bricks(components_paths, ns)
|
|
11
|
-
return {'bases': check.collect.with_unknown_components(root, ns, brick_imports_in_bases), 'components': check.collect.with_unknown_components(root, ns, brick_imports_in_components)}
|
|
12
|
-
|
|
13
|
-
def calculate_diff(root: Path, namespace: str, project_data: dict, workspace_data: dict) -> dict:
|
|
14
|
-
brick_imports = get_brick_imports(root, namespace, project_data)
|
|
15
|
-
all_bases = workspace_data['bases']
|
|
16
|
-
all_components = workspace_data['components']
|
|
17
|
-
bases = project_data['bases']
|
|
18
|
-
components = project_data['components']
|
|
19
|
-
is_project = info.is_project(project_data)
|
|
20
|
-
if is_project:
|
|
21
|
-
brick_diff = check.collect.imports_diff(brick_imports, bases, components)
|
|
22
|
-
else:
|
|
23
|
-
all_bricks = set().union(all_bases, all_components)
|
|
24
|
-
brick_diff = check.collect.diff(all_bricks, bases, components)
|
|
25
|
-
bases_diff = {b for b in brick_diff if b in all_bases}
|
|
26
|
-
components_diff = {b for b in brick_diff if b in all_components}
|
|
27
|
-
return {'name': project_data['name'], 'path': project_data['path'], 'is_project': is_project, 'bases': bases_diff, 'components': components_diff, 'brick_imports': brick_imports}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|