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

Simplify excluding the requirements.txt file generated from python_requirements() #9640

Merged
merged 2 commits into from
Apr 28, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pants.backend.python.rules.inject_init import InitInjectedSnapshot, InjectInitRequest
from pants.backend.python.rules.inject_init import rules as inject_init_rules
from pants.backend.python.target_types import PythonRequirementsFileSources, PythonSources
from pants.backend.python.target_types import PythonSources
from pants.core.target_types import FilesSources, ResourcesSources
from pants.core.util_rules import determine_source_files
from pants.core.util_rules.determine_source_files import AllSourceFilesRequest, SourceFiles
Expand Down Expand Up @@ -34,13 +34,8 @@ class ImportablePythonSources:
@rule
async def prepare_python_sources(targets: Targets) -> ImportablePythonSources:
def is_relevant(tgt: Target) -> bool:
# NB: PythonRequirementsFileSources is a subclass of FilesSources. We filter it out so that
# requirements.txt is not included. If the user intended for the file to be included, they
# should use a normal `files()` target rather than `python_requirements()`.
return (
tgt.has_field(PythonSources)
or tgt.has_field(ResourcesSources)
or (tgt.has_field(FilesSources) and not tgt.has_field(PythonRequirementsFileSources))
return any(
tgt.has_field(field) for field in (PythonSources, ResourcesSources, FilesSources)
)

stripped_sources = await Get[SourceFiles](
Expand Down
5 changes: 1 addition & 4 deletions src/python/pants/backend/python/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from pants.backend.python.python_artifact import PythonArtifact
from pants.backend.python.subsystems.pytest import PyTest
from pants.core.target_types import FilesSources
from pants.core.util_rules.determine_source_files import SourceFiles
from pants.engine.addresses import Address
from pants.engine.fs import Snapshot
Expand Down Expand Up @@ -414,9 +413,7 @@ class PythonRequirementLibrary(Target):
# -----------------------------------------------------------------------------------------------


# NB: This subclasses FilesSources to ensure that we still properly handle stripping source roots,
# but we still new type so that we can distinguish between normal FilesSources vs. this field.
class PythonRequirementsFileSources(FilesSources):
class PythonRequirementsFileSources(Sources):
pass


Expand Down