Skip to content

Commit

Permalink
Add test that fails without using TransitiveTargetsWithoutTraversingP…
Browse files Browse the repository at this point in the history
…ackagesRequest

Next commit adds it to fix it.
  • Loading branch information
cognifloyd committed Jun 1, 2023
1 parent b225969 commit cf71d2f
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import pytest

from pants.backend.python import target_types_rules
from pants.backend.python.goals import package_pex_binary
from pants.backend.python.subsystems import setuptools
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.subsystems.setuptools import Setuptools
from pants.backend.python.target_types import (
EntryPoint,
PexLayout,
PexBinary,
PythonRequirementTarget,
PythonSourcesGeneratorTarget,
PythonSourceTarget,
Expand Down Expand Up @@ -71,6 +73,7 @@
def rule_runner() -> PythonRuleRunner:
return PythonRuleRunner(
rules=[
*package_pex_binary.rules(),
*pex_test_utils.rules(),
*pex_from_targets.rules(),
*target_types_rules.rules(),
Expand All @@ -82,6 +85,7 @@ def rule_runner() -> PythonRuleRunner:
QueryRule(Setuptools, []),
],
target_types=[
PexBinary,
PythonSourcesGeneratorTarget,
PythonRequirementTarget,
PythonSourceTarget,
Expand Down Expand Up @@ -761,6 +765,53 @@ def test_exclude_sources(include_sources: bool, rule_runner: PythonRuleRunner) -
assert len(snapshot.files) == (1 if include_sources else 0)


def test_include_sources_without_transitive_package_sources(rule_runner: PythonRuleRunner) -> None:
rule_runner.write_files(
{
"src/app/BUILD": dedent(
"""
python_sources(
name="app",
sources=["app.py"],
dependencies=["//src/dep:pkg"],
)
"""
),
"src/app/app.py": "",
"src/dep/BUILD": dedent(
# This test requires a package that has a standard dependencies field.
# 'pex_binary' has a dependencies field; 'archive' does not.
"""
pex_binary(name="pkg", dependencies=[":dep"])
python_sources(name="dep", sources=["dep.py"])
"""
),
"src/dep/dep.py": "",
}
)

rule_runner.set_options(
[
"--backend-packages=pants.backend.python",
"--python-repos-indexes=[]",
],
env_inherit={"PATH"},
)

request = PexFromTargetsRequest(
[Address("src/app", target_name="app")],
output_filename="demo.pex",
internal_only=True,
include_source_files=True,
)
pex_request = rule_runner.request(PexRequest, [request])
snapshot = rule_runner.request(Snapshot, [pex_request.sources])

# the packaged transitive dep is excluded
assert "dep/dep.py" not in snapshot.files
assert snapshot.files == ("app/app.py",)


@pytest.mark.parametrize("enable_resolves", [False, True])
def test_cross_platform_pex_disables_subsetting(
rule_runner: PythonRuleRunner, enable_resolves: bool
Expand Down

0 comments on commit cf71d2f

Please sign in to comment.