Skip to content

Commit

Permalink
Remove deprecated Address.parse() and Address.reference() (pantsb…
Browse files Browse the repository at this point in the history
…uild#10981)

`Address.parse()` is not safe because it cannot accommodate file addresses.

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano authored Oct 16, 2020
1 parent ac8561b commit 79e2b09
Show file tree
Hide file tree
Showing 26 changed files with 231 additions and 207 deletions.
6 changes: 3 additions & 3 deletions src/python/pants/backend/awslambda/python/rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def rule_runner() -> RuleRunner:
)


def create_python_awslambda(rule_runner: RuleRunner, addr: str) -> Tuple[str, bytes]:
def create_python_awslambda(rule_runner: RuleRunner, addr: Address) -> Tuple[str, bytes]:
rule_runner.set_options(
[
"--backend-packages=pants.backend.awslambda.python",
"--source-root-patterns=src/python",
"--pants-distdir-legacy-paths=false",
]
)
target = rule_runner.get_target(Address.parse(addr))
target = rule_runner.get_target(addr)
created_awslambda = rule_runner.request(
CreatedAWSLambda, [PythonAwsLambdaFieldSet.create(target)]
)
Expand Down Expand Up @@ -88,7 +88,7 @@ def handler(event, context):
)

zip_file_relpath, content = create_python_awslambda(
rule_runner, "src/python/foo/bar:hello_world_lambda"
rule_runner, Address("src/python/foo/bar", target_name="hello_world_lambda")
)
assert "src.python.foo.bar/hello_world_lambda.zip" == zip_file_relpath
zipfile = ZipFile(BytesIO(content))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
)
def test_to_interpreter_version(runtime, expected_major, expected_minor):
assert (expected_major, expected_minor) == PythonAwsLambdaRuntime(
raw_value=runtime, address=Address.parse("foo/bar:baz")
raw_value=runtime, address=Address("foo/bar", target_name="baz")
).to_interpreter_version()


@pytest.mark.parametrize(["invalid_runtime"], (["python88.99"], ["fooobar"]))
def test_runtime_validation(invalid_runtime):
with pytest.raises(InvalidFieldException):
PythonAwsLambdaRuntime(raw_value=invalid_runtime, address=Address.parse("foo/bar:baz"))
PythonAwsLambdaRuntime(
raw_value=invalid_runtime, address=Address("foo/bar", target_name="baz")
)
24 changes: 15 additions & 9 deletions src/python/pants/backend/project_info/filter_targets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def run_goal(

def test_no_filters_provided() -> None:
# `filter` behaves like `list` when there are no specified filters.
targets = [MockTarget({}, address=Address.parse(addr)) for addr in (":t3", ":t2", ":t1")]
targets = [MockTarget({}, address=Address("", target_name=name)) for name in ("t3", "t2", "t1")]
assert run_goal(targets) == dedent(
"""\
//:t1
Expand All @@ -79,8 +79,10 @@ class Smalltalk(Target):
alias = "smalltalk"
core_fields = ()

fortran_targets = [Fortran({}, address=Address.parse(addr)) for addr in (":f1", ":f2")]
smalltalk_targets = [Smalltalk({}, address=Address.parse(addr)) for addr in (":s1", ":s2")]
fortran_targets = [Fortran({}, address=Address("", target_name=name)) for name in ("f1", "f2")]
smalltalk_targets = [
Smalltalk({}, address=Address("", target_name=name)) for name in ("s1", "s2")
]
targets = [*fortran_targets, *smalltalk_targets]

assert run_goal(targets, target_type=["fortran"]).strip() == "//:f1\n//:f2"
Expand All @@ -105,8 +107,12 @@ class Smalltalk(Target):

def test_filter_by_address_regex() -> None:
targets = [
MockTarget({}, address=Address.parse(addr))
for addr in ("dir1:lib", "dir2:lib", "common:tests")
MockTarget({}, address=addr)
for addr in (
Address("dir1", target_name="lib"),
Address("dir2", target_name="lib"),
Address("common", target_name="tests"),
)
]
assert run_goal(targets, address_regex=[r"^dir"]).strip() == "dir1:lib\ndir2:lib"
assert run_goal(targets, address_regex=[r"+dir1:lib$"]).strip() == "dir1:lib"
Expand All @@ -123,10 +129,10 @@ def test_filter_by_address_regex() -> None:

def test_filter_by_tag_regex() -> None:
targets = [
MockTarget({"tags": ["tag1"]}, address=Address.parse(":t1")),
MockTarget({"tags": ["tag2"]}, address=Address.parse(":t2")),
MockTarget({"tags": ["tag1", "tag2"]}, address=Address.parse(":both")),
MockTarget({}, address=Address.parse(":no_tags")),
MockTarget({"tags": ["tag1"]}, address=Address("", target_name="t1")),
MockTarget({"tags": ["tag2"]}, address=Address("", target_name="t2")),
MockTarget({"tags": ["tag1", "tag2"]}, address=Address("", target_name="both")),
MockTarget({}, address=Address("", target_name="no_tags")),
]
assert run_goal(targets, tag_regex=[r"t.?g2$"]).strip() == "//:both\n//:t2"
assert run_goal(targets, tag_regex=["+tag1"]).strip() == "//:both\n//:t1"
Expand Down
16 changes: 10 additions & 6 deletions src/python/pants/backend/project_info/list_targets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ def run_goal(

def test_list_normal() -> None:
# Note that these are unsorted.
addresses = (":t3", ":t2", ":t1")
stdout, _ = run_goal([MockTarget({}, address=Address.parse(addr)) for addr in addresses])
target_names = ("t3", "t2", "t1")
stdout, _ = run_goal(
[MockTarget({}, address=Address("", target_name=name)) for name in target_names]
)
assert stdout == dedent(
"""\
//:t1
Expand All @@ -73,9 +75,9 @@ def test_list_documented() -> None:
[
MockTarget(
{DescriptionField.alias: "Description of a target.\n\tThis target is the best."},
address=Address.parse(":described"),
address=Address("", target_name="described"),
),
MockTarget({}, address=Address.parse(":not_described")),
MockTarget({}, address=Address("", target_name="not_described")),
],
show_documented=True,
)
Expand All @@ -91,8 +93,10 @@ def test_list_documented() -> None:
def test_list_provides() -> None:
sample_artifact = PythonArtifact(name="project.demo")
targets = [
MockTarget({ProvidesField.alias: sample_artifact}, address=Address.parse(":provided")),
MockTarget({}, address=Address.parse(":not_provided")),
MockTarget(
{ProvidesField.alias: sample_artifact}, address=Address("", target_name="provided")
),
MockTarget({}, address=Address("", target_name="not_provided")),
]
stdout, _ = run_goal(targets, show_provides=True)
assert stdout.strip() == f"//:provided {sample_artifact}"
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def test_first_party_modules_mapping() -> None:


def test_third_party_modules_mapping() -> None:
colors_addr = Address.parse("//:ansicolors")
pants_addr = Address.parse("//:pantsbuild")
colors_addr = Address("", target_name="ansicolors")
pants_addr = Address("", target_name="pantsbuild")
mapping = ThirdPartyModuleToAddressMapping(
FrozenDict({"colors": colors_addr, "pants": pants_addr})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def run_dep_inference(address: Address) -> InferredDependencies:
[InferInitDependencies(target[PythonSources])],
)

assert run_dep_inference(Address.parse("src/python/root/mid/leaf")) == InferredDependencies(
assert run_dep_inference(Address("src/python/root/mid/leaf")) == InferredDependencies(
[
Address("src/python/root", relative_file_path="__init__.py", target_name="root"),
Address("src/python/root/mid", relative_file_path="__init__.py", target_name="mid"),
Expand Down Expand Up @@ -200,7 +200,7 @@ def run_dep_inference(address: Address) -> InferredDependencies:
[InferConftestDependencies(target[PythonSources])],
)

assert run_dep_inference(Address.parse("src/python/root/mid/leaf")) == InferredDependencies(
assert run_dep_inference(Address("src/python/root/mid/leaf")) == InferredDependencies(
[
Address("src/python/root", relative_file_path="conftest.py", target_name="root"),
Address("src/python/root/mid", relative_file_path="conftest.py", target_name="mid"),
Expand Down
Loading

0 comments on commit 79e2b09

Please sign in to comment.