Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependency inference handling of dependencies on self #10373

Merged
merged 1 commit into from Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -45,7 +45,10 @@ async def infer_python_dependencies(request: InferPythonDependencies) -> Inferre
return InferredDependencies(
owner.address
for owner in owner_per_import
if owner.address and owner.address != request.sources_field.address
if (
owner.address
and owner.address.maybe_convert_to_base_target() != request.sources_field.address
)
)


Expand Down
29 changes: 19 additions & 10 deletions src/python/pants/backend/python/dependency_inference/rules_test.py
Expand Up @@ -86,17 +86,26 @@ def test_infer_python_dependencies(self) -> None:
)
self.add_to_build_file("src/python", "python_library()")

tgt = self.request_single_product(WrappedTarget, Address.parse("src/python")).target
result = self.request_single_product(
InferredDependencies,
Params(InferPythonDependencies(tgt[PythonSources]), options_bootstrapper),
)
# NB: `src/python:f2.py` does not show up because it is not a dependency of any file in
# `src/python:python`.
assert result == InferredDependencies(
def run_dep_inference(address: Address) -> InferredDependencies:
target = self.request_single_product(WrappedTarget, address).target
return self.request_single_product(
InferredDependencies,
Params(InferPythonDependencies(target[PythonSources]), options_bootstrapper),
)

# NB: We do not infer `src/python/app.py`, even though it's used by `src/python/f2.py`,
# because it is part of the requested address.
normal_address = Address("src/python", "python")
assert run_dep_inference(normal_address) == InferredDependencies(
[
Address.parse("3rdparty/python:Django"),
Address("src/python", target_name="app.py", generated_base_target_name="python"),
Address("3rdparty/python", "Django"),
Address("src/python/util", target_name="dep.py", generated_base_target_name="util"),
]
)

generated_subtarget_address = Address(
"src/python", target_name="f2.py", generated_base_target_name="python"
)
assert run_dep_inference(generated_subtarget_address) == InferredDependencies(
[Address("src/python", target_name="app.py", generated_base_target_name="python")]
)