Skip to content

Commit

Permalink
feat(poly diff): allow diff with commit hashes (#265)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
DavidVujic authored Sep 10, 2024
1 parent 6cfab10 commit 58461f4
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions components/polylith/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ def print_views(root: Path, tag: str, options: dict) -> None:
def run(tag_name: Union[str, None], options: dict):
root = repo.get_workspace_root(Path.cwd())

tag = diff.collect.get_latest_tag(root, tag_name)
tag = diff.collect.get_latest_tag(root, tag_name) or tag_name

if not tag:
print("No tags found in repository.")
print("No matching tags or commits found in repository.")
return

print_views(root, tag, options)
7 changes: 5 additions & 2 deletions components/polylith/configuration/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ def get_git_tag_pattern(toml: dict) -> str:
return toml["tool"]["polylith"]["git_tag_pattern"]


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

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

return patterns[key or "stable"] if patterns else get_git_tag_pattern(toml)
if not key:
return patterns["stable"] if patterns else get_git_tag_pattern(toml)

return patterns.get(key)


def get_tag_sort_options_from_config(path: Path) -> List[str]:
Expand Down
4 changes: 4 additions & 0 deletions components/polylith/diff/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def get_changed_projects(changed_files: List[Path]) -> list:

def get_latest_tag(root: Path, key: Union[str, None]) -> Union[str, None]:
tag_pattern = configuration.get_tag_pattern_from_config(root, key)

if not tag_pattern:
return None

sorting_options = [
f"--sort={option}"
for option in configuration.get_tag_sort_options_from_config(root)
Expand Down
2 changes: 1 addition & 1 deletion components/polylith/diff/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def print_projects_affected_by_changes(projects: Set[str], short: bool) -> None:
def print_diff_summary(tag: str, bases: List[str], components: List[str]) -> None:
console = Console(theme=theme.poly_theme)

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

if not bases and not components:
console.print("[data]No brick changes found.[/]")
Expand Down
2 changes: 1 addition & 1 deletion projects/pdm_polylith_bricks/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pdm-polylith-bricks"
version = "1.0.7"
version = "1.0.8"
description = "a PDM build hook for Polylith"
authors = ["David Vujic"]
homepage = "https://davidvujic.github.io/python-polylith-docs/"
Expand Down
2 changes: 1 addition & 1 deletion projects/pdm_polylith_workspace/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pdm-polylith-workspace"
version = "1.0.7"
version = "1.0.8"
description = "a PDM build hook for a Polylith workspace"
homepage = "https://davidvujic.github.io/python-polylith-docs/"
repository = "https://github.com/davidvujic/python-polylith"
Expand Down
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.28.0"
version = "1.29.0"
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.16.0"
version = "1.17.0"
description = "Python tooling support for the Polylith Architecture"
authors = ['David Vujic']
homepage = "https://davidvujic.github.io/python-polylith-docs/"
Expand Down
2 changes: 2 additions & 0 deletions test/components/polylith/configuration/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def test_get_tag_pattern(use_loose):
assert stable == "stable-*"
assert release == "v[0-9]*"

assert core.get_tag_pattern_from_config(fake_path, "non_existing_tag") is None


def test_get_tag_sort_options_from_config(use_loose):
options = core.get_tag_sort_options_from_config(fake_path)
Expand Down

0 comments on commit 58461f4

Please sign in to comment.