Skip to content

Commit

Permalink
Fix __str__ for AddressLiteralSpec to include parameters (#15616)
Browse files Browse the repository at this point in the history
[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano authored May 24, 2022
1 parent 3c3b47a commit 672b64c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/python/pants/base/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class AddressLiteralSpec(Spec):
def __str__(self) -> str:
tgt = f":{self.target_component}" if self.target_component else ""
generated = f"#{self.generated_component}" if self.generated_component else ""
return f"{self.path_component}{tgt}{generated}"
params = ""
if self.parameters:
rhs = ",".join(f"{k}={v}" for k, v in self.parameters.items())
params = f"@{rhs}"
return f"{self.path_component}{tgt}{generated}{params}"

@property
def is_directory_shorthand(self) -> bool:
Expand Down
24 changes: 24 additions & 0 deletions src/python/pants/base/specs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,37 @@

from __future__ import annotations

import pytest

from pants.base.specs import (
AddressLiteralSpec,
AncestorGlobSpec,
DirGlobSpec,
DirLiteralSpec,
RecursiveGlobSpec,
SpecsWithoutFileOwners,
)
from pants.util.frozendict import FrozenDict


@pytest.mark.parametrize(
"spec,expected",
[
(AddressLiteralSpec("dir"), "dir"),
(AddressLiteralSpec("dir/f.txt"), "dir/f.txt"),
(AddressLiteralSpec("dir", "tgt"), "dir:tgt"),
(AddressLiteralSpec("dir", None, "gen"), "dir#gen"),
(AddressLiteralSpec("dir", "tgt", "gen"), "dir:tgt#gen"),
(
AddressLiteralSpec("dir", None, None, FrozenDict({"k1": "v1", "k2": "v2"})),
"dir@k1=v1,k2=v1",
),
(AddressLiteralSpec("dir", "tgt", None, FrozenDict({"k": "v"})), "dir:tgt@k=v"),
(AddressLiteralSpec("dir", "tgt", "gen", FrozenDict({"k": "v"})), "dir:tgt#gen@k=v"),
],
)
def address_literal_str(spec: AddressLiteralSpec, expected: str) -> None:
assert str(spec) == expected


def assert_build_file_globs(
Expand Down

0 comments on commit 672b64c

Please sign in to comment.