Skip to content

Commit 58461f4

Browse files
authored
feat(poly diff): allow diff with commit hashes (#265)
* feat(poly diff): allow diff from commit hash or tag name * bump PDM brick hook to 1.0.8 * bump PDM workspace hook to 1.0.8 * bump Poetry plugin to 1.29.0 * bump CLI to 1.17.0
1 parent 6cfab10 commit 58461f4

File tree

9 files changed

+18
-9
lines changed

9 files changed

+18
-9
lines changed

components/polylith/commands/diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ def print_views(root: Path, tag: str, options: dict) -> None:
9999
def run(tag_name: Union[str, None], options: dict):
100100
root = repo.get_workspace_root(Path.cwd())
101101

102-
tag = diff.collect.get_latest_tag(root, tag_name)
102+
tag = diff.collect.get_latest_tag(root, tag_name) or tag_name
103103

104104
if not tag:
105-
print("No tags found in repository.")
105+
print("No matching tags or commits found in repository.")
106106
return
107107

108108
print_views(root, tag, options)

components/polylith/configuration/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ def get_git_tag_pattern(toml: dict) -> str:
2929
return toml["tool"]["polylith"]["git_tag_pattern"]
3030

3131

32-
def get_tag_pattern_from_config(path: Path, key: Union[str, None]) -> str:
32+
def get_tag_pattern_from_config(path: Path, key: Union[str, None]) -> Union[str, None]:
3333
toml: dict = _load_workspace_config(path)
3434

3535
patterns = toml["tool"]["polylith"].get("tag", {}).get("patterns")
3636

37-
return patterns[key or "stable"] if patterns else get_git_tag_pattern(toml)
37+
if not key:
38+
return patterns["stable"] if patterns else get_git_tag_pattern(toml)
39+
40+
return patterns.get(key)
3841

3942

4043
def get_tag_sort_options_from_config(path: Path) -> List[str]:

components/polylith/diff/collect.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def get_changed_projects(changed_files: List[Path]) -> list:
5858

5959
def get_latest_tag(root: Path, key: Union[str, None]) -> Union[str, None]:
6060
tag_pattern = configuration.get_tag_pattern_from_config(root, key)
61+
62+
if not tag_pattern:
63+
return None
64+
6165
sorting_options = [
6266
f"--sort={option}"
6367
for option in configuration.get_tag_sort_options_from_config(root)

components/polylith/diff/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def print_projects_affected_by_changes(projects: Set[str], short: bool) -> None:
8686
def print_diff_summary(tag: str, bases: List[str], components: List[str]) -> None:
8787
console = Console(theme=theme.poly_theme)
8888

89-
console.print(Padding(f"[data]Diff: based on the {tag} tag[/]", (1, 0, 1, 0)))
89+
console.print(Padding(f"[data]Diff: based on {tag}[/]", (1, 0, 1, 0)))
9090

9191
if not bases and not components:
9292
console.print("[data]No brick changes found.[/]")

projects/pdm_polylith_bricks/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pdm-polylith-bricks"
3-
version = "1.0.7"
3+
version = "1.0.8"
44
description = "a PDM build hook for Polylith"
55
authors = ["David Vujic"]
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

projects/pdm_polylith_workspace/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pdm-polylith-workspace"
3-
version = "1.0.7"
3+
version = "1.0.8"
44
description = "a PDM build hook for a Polylith workspace"
55
homepage = "https://davidvujic.github.io/python-polylith-docs/"
66
repository = "https://github.com/davidvujic/python-polylith"

projects/poetry_polylith_plugin/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "poetry-polylith-plugin"
3-
version = "1.28.0"
3+
version = "1.29.0"
44
description = "A Poetry plugin that adds tooling support for the Polylith Architecture"
55
authors = ["David Vujic"]
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

projects/polylith_cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "polylith-cli"
3-
version = "1.16.0"
3+
version = "1.17.0"
44
description = "Python tooling support for the Polylith Architecture"
55
authors = ['David Vujic']
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

test/components/polylith/configuration/test_core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def test_get_tag_pattern(use_loose):
7474
assert stable == "stable-*"
7575
assert release == "v[0-9]*"
7676

77+
assert core.get_tag_pattern_from_config(fake_path, "non_existing_tag") is None
78+
7779

7880
def test_get_tag_sort_options_from_config(use_loose):
7981
options = core.get_tag_sort_options_from_config(fake_path)

0 commit comments

Comments
 (0)