Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn when depending on
files
targets in a pex_binary
or `python_a…
…wslambda` # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust]
- Loading branch information
1 parent
3e7e97a
commit b8414af
Showing
6 changed files
with
276 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/python/pants/backend/python/goals/package_pex_binary_integration_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
from pants.backend.python import target_types_rules | ||
from pants.backend.python.goals import package_pex_binary | ||
from pants.backend.python.goals.package_pex_binary import PexBinaryFieldSet | ||
from pants.backend.python.target_types import PexBinary | ||
from pants.backend.python.util_rules import pex_from_targets | ||
from pants.build_graph.address import Address | ||
from pants.core.goals.package import BuiltPackage | ||
from pants.core.target_types import Files, RelocatedFiles, Resources | ||
from pants.core.target_types import rules as core_target_types_rules | ||
from pants.testutil.rule_runner import QueryRule, RuleRunner | ||
|
||
|
||
@pytest.fixture | ||
def rule_runner() -> RuleRunner: | ||
return RuleRunner( | ||
rules=[ | ||
*package_pex_binary.rules(), | ||
*pex_from_targets.rules(), | ||
*target_types_rules.rules(), | ||
*core_target_types_rules(), | ||
QueryRule(BuiltPackage, [PexBinaryFieldSet]), | ||
], | ||
target_types=[PexBinary, Files, RelocatedFiles, Resources], | ||
) | ||
|
||
|
||
def test_warn_files_targets(rule_runner: RuleRunner, caplog) -> None: | ||
rule_runner.set_options([], env_inherit={"PATH", "PYENV_ROOT", "HOME"}) | ||
rule_runner.create_file("assets/f.txt") | ||
rule_runner.add_to_build_file( | ||
"assets", | ||
dedent( | ||
"""\ | ||
files(name='files', sources=['f.txt']) | ||
relocated_files( | ||
name='relocated', | ||
files_targets=[':files'], | ||
src='assets', | ||
dest='new_assets', | ||
) | ||
# Resources are fine. | ||
resources(name='resources', sources=['f.txt']) | ||
""" | ||
), | ||
) | ||
rule_runner.create_file("src/py/project/__init__.py") | ||
rule_runner.create_file("src/py/project/app.py", "print('hello')") | ||
rule_runner.add_to_build_file( | ||
"src/py/project", | ||
dedent( | ||
"""\ | ||
pex_binary( | ||
dependencies=['assets:files', 'assets:relocated', 'assets:resources'], | ||
entry_point="none", | ||
) | ||
""" | ||
), | ||
) | ||
tgt = rule_runner.get_target(Address("src/py/project")) | ||
field_set = PexBinaryFieldSet.create(tgt) | ||
|
||
assert not caplog.records | ||
result = rule_runner.request(BuiltPackage, [field_set]) | ||
assert caplog.records | ||
assert f"The pex_binary target {tgt.address} transitively depends on" in caplog.text | ||
assert "assets/f.txt:files" in caplog.text | ||
assert "assets:relocated" in caplog.text | ||
assert "assets:resources" not in caplog.text | ||
|
||
assert len(result.artifacts) == 1 | ||
assert result.artifacts[0].relpath == "src.py.project/project.pex" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.