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

Change the PathGlobs, SnapshotSubset, and UrlToFetch intrinsics to return Digest #10449

Merged
merged 10 commits into from Jul 27, 2020
14 changes: 6 additions & 8 deletions src/python/pants/backend/python/lint/bandit/rules.py
Expand Up @@ -22,7 +22,7 @@
SourceFiles,
SpecifiedSourceFilesRequest,
)
from pants.engine.fs import Digest, MergeDigests, PathGlobs, Snapshot
from pants.engine.fs import Digest, MergeDigests, PathGlobs
from pants.engine.process import FallibleProcessResult, Process
from pants.engine.rules import SubsystemRule, rule
from pants.engine.selectors import Get, MultiGet
Expand Down Expand Up @@ -81,8 +81,8 @@ async def bandit_lint_partition(
)

config_path: Optional[str] = bandit.options.config
config_snapshot_request = Get(
Snapshot,
config_digest_request = Get(
Digest,
PathGlobs(
globs=[config_path] if config_path else [],
glob_match_error_behavior=GlobMatchErrorBehavior.error,
Expand All @@ -100,18 +100,16 @@ async def bandit_lint_partition(
),
)

requirements_pex, config_snapshot, all_source_files, specified_source_files = await MultiGet(
requirements_pex, config_digest, all_source_files, specified_source_files = await MultiGet(
requirements_pex_request,
config_snapshot_request,
config_digest_request,
all_source_files_request,
specified_source_files_request,
)

input_digest = await Get(
Digest,
MergeDigests(
(all_source_files.snapshot.digest, requirements_pex.digest, config_snapshot.digest)
),
MergeDigests((all_source_files.snapshot.digest, requirements_pex.digest, config_digest)),
)

address_references = ", ".join(
Expand Down
14 changes: 6 additions & 8 deletions src/python/pants/backend/python/lint/black/rules.py
Expand Up @@ -26,7 +26,7 @@
SourceFiles,
SpecifiedSourceFilesRequest,
)
from pants.engine.fs import EMPTY_SNAPSHOT, Digest, MergeDigests, PathGlobs, Snapshot
from pants.engine.fs import EMPTY_SNAPSHOT, Digest, MergeDigests, PathGlobs
from pants.engine.process import FallibleProcessResult, Process, ProcessResult
from pants.engine.rules import SubsystemRule, rule
from pants.engine.selectors import Get, MultiGet
Expand Down Expand Up @@ -99,8 +99,8 @@ async def setup(
)

config_path: Optional[str] = black.options.config
config_snapshot_request = Get(
Snapshot,
config_digest_request = Get(
Digest,
PathGlobs(
globs=[config_path] if config_path else [],
glob_match_error_behavior=GlobMatchErrorBehavior.error,
Expand All @@ -119,8 +119,8 @@ async def setup(
),
)

requests = requirements_pex_request, config_snapshot_request, specified_source_files_request
all_source_files, requirements_pex, config_snapshot, specified_source_files = (
requests = requirements_pex_request, config_digest_request, specified_source_files_request
all_source_files, requirements_pex, config_digest, specified_source_files = (
await MultiGet(all_source_files_request, *requests)
if setup_request.request.prior_formatter_result is None
else (SourceFiles(EMPTY_SNAPSHOT), *await MultiGet(*requests))
Expand All @@ -133,9 +133,7 @@ async def setup(

input_digest = await Get(
Digest,
MergeDigests(
(all_source_files_snapshot.digest, requirements_pex.digest, config_snapshot.digest)
),
MergeDigests((all_source_files_snapshot.digest, requirements_pex.digest, config_digest)),
)

address_references = ", ".join(
Expand Down
20 changes: 9 additions & 11 deletions src/python/pants/backend/python/lint/flake8/rules.py
Expand Up @@ -28,7 +28,7 @@
SourceFiles,
SpecifiedSourceFilesRequest,
)
from pants.engine.fs import Digest, MergeDigests, PathGlobs, Snapshot, SnapshotSubset
from pants.engine.fs import Digest, DigestSubset, MergeDigests, PathGlobs, Snapshot
from pants.engine.process import FallibleProcessResult, Process
from pants.engine.rules import SubsystemRule, rule
from pants.engine.selectors import Get, MultiGet
Expand Down Expand Up @@ -92,8 +92,8 @@ async def flake8_lint_partition(
)

config_path: Optional[str] = flake8.options.config
config_snapshot_request = Get(
Snapshot,
config_digest_request = Get(
Digest,
PathGlobs(
globs=[config_path] if config_path else [],
glob_match_error_behavior=GlobMatchErrorBehavior.error,
Expand All @@ -111,18 +111,16 @@ async def flake8_lint_partition(
),
)

requirements_pex, config_snapshot, all_source_files, specified_source_files = await MultiGet(
requirements_pex, config_digest, all_source_files, specified_source_files = await MultiGet(
requirements_pex_request,
config_snapshot_request,
config_digest_request,
all_source_files_request,
specified_source_files_request,
)

input_digest = await Get(
Digest,
MergeDigests(
(all_source_files.snapshot.digest, requirements_pex.digest, config_snapshot.digest)
),
MergeDigests((all_source_files.snapshot.digest, requirements_pex.digest, config_digest)),
)

address_references = ", ".join(
Expand Down Expand Up @@ -152,10 +150,10 @@ async def flake8_lint_partition(
results_file = None
if report_path:
report_file_snapshot = await Get(
Snapshot, SnapshotSubset(result.output_digest, PathGlobs([report_path.name]))
Snapshot, DigestSubset(result.output_digest, PathGlobs([report_path.name]))
)
if report_file_snapshot.is_empty or len(report_file_snapshot.files) != 1:
raise Exception(f"Unexpected report file snapshot: {report_file_snapshot}")
if len(report_file_snapshot.files) != 1:
raise Exception(f"Unexpected report file snapshot: {report_file_snapshot.files}")
results_file = LintResultFile(output_path=report_path, digest=report_file_snapshot.digest)

return LintResult.from_fallible_process_result(
Expand Down
14 changes: 6 additions & 8 deletions src/python/pants/backend/python/lint/isort/rules.py
Expand Up @@ -24,7 +24,7 @@
SourceFiles,
SpecifiedSourceFilesRequest,
)
from pants.engine.fs import EMPTY_SNAPSHOT, Digest, MergeDigests, PathGlobs, Snapshot
from pants.engine.fs import EMPTY_SNAPSHOT, Digest, MergeDigests, PathGlobs
from pants.engine.process import FallibleProcessResult, Process, ProcessResult
from pants.engine.rules import SubsystemRule, rule
from pants.engine.selectors import Get, MultiGet
Expand Down Expand Up @@ -92,8 +92,8 @@ async def setup(
)

config_path: Optional[List[str]] = isort.options.config
config_snapshot_request = Get(
Snapshot,
config_digest_request = Get(
Digest,
PathGlobs(
globs=config_path or (),
glob_match_error_behavior=GlobMatchErrorBehavior.error,
Expand All @@ -115,10 +115,10 @@ async def setup(

requests = (
requirements_pex_request,
config_snapshot_request,
config_digest_request,
specified_source_files_request,
)
all_source_files, requirements_pex, config_snapshot, specified_source_files = (
all_source_files, requirements_pex, config_digest, specified_source_files = (
await MultiGet(all_source_files_request, *requests)
if setup_request.request.prior_formatter_result is None
else (SourceFiles(EMPTY_SNAPSHOT), *await MultiGet(*requests))
Expand All @@ -131,9 +131,7 @@ async def setup(

input_digest = await Get(
Digest,
MergeDigests(
(all_source_files_snapshot.digest, requirements_pex.digest, config_snapshot.digest)
),
MergeDigests((all_source_files_snapshot.digest, requirements_pex.digest, config_digest)),
)

address_references = ", ".join(
Expand Down
12 changes: 6 additions & 6 deletions src/python/pants/backend/python/lint/pylint/rules.py
Expand Up @@ -31,7 +31,7 @@
from pants.core.util_rules import determine_source_files, strip_source_roots
from pants.core.util_rules.determine_source_files import SourceFiles, SpecifiedSourceFilesRequest
from pants.engine.addresses import Address, Addresses
from pants.engine.fs import EMPTY_DIGEST, AddPrefix, Digest, MergeDigests, PathGlobs, Snapshot
from pants.engine.fs import EMPTY_DIGEST, AddPrefix, Digest, MergeDigests, PathGlobs
from pants.engine.process import FallibleProcessResult, Process
from pants.engine.rules import SubsystemRule, rule
from pants.engine.selectors import Get, MultiGet
Expand Down Expand Up @@ -152,8 +152,8 @@ async def pylint_lint_partition(
),
)

config_snapshot_request = Get(
Snapshot,
config_digest_request = Get(
Digest,
PathGlobs(
globs=[pylint.config] if pylint.config else [],
glob_match_error_behavior=GlobMatchErrorBehavior.error,
Expand All @@ -179,15 +179,15 @@ async def pylint_lint_partition(
pylint_pex,
requirements_pex,
pylint_runner_pex,
config_snapshot,
config_digest,
prepared_plugin_sources,
prepared_python_sources,
specified_source_files,
) = await MultiGet(
pylint_pex_request,
requirements_pex_request,
pylint_runner_pex_request,
config_snapshot_request,
config_digest_request,
prepare_plugin_sources_request,
prepare_python_sources_request,
specified_source_files_request,
Expand Down Expand Up @@ -215,7 +215,7 @@ async def pylint_lint_partition(
pylint_pex.digest,
requirements_pex.digest,
pylint_runner_pex.digest,
config_snapshot.digest,
config_digest,
prefixed_plugin_sources,
prepared_python_sources.snapshot.digest,
)
Expand Down
6 changes: 2 additions & 4 deletions src/python/pants/backend/python/rules/coverage.py
Expand Up @@ -37,7 +37,6 @@
FileContent,
MergeDigests,
PathGlobs,
Snapshot,
)
from pants.engine.process import Process, ProcessResult
from pants.engine.rules import SubsystemRule, rule
Expand Down Expand Up @@ -168,15 +167,14 @@ async def create_coverage_config(coverage: CoverageSubsystem) -> CoverageConfig:
config_path: Optional[str] = coverage.options.config
coverage_config = configparser.ConfigParser()
if config_path:
config_snapshot = await Get(
Snapshot,
config_contents = await Get(
DigestContents,
PathGlobs(
globs=config_path,
glob_match_error_behavior=GlobMatchErrorBehavior.error,
description_of_origin=f"the option `--{coverage.options_scope}-config`",
),
)
config_contents = await Get(DigestContents, Digest, config_snapshot.digest)
coverage_config.read_string(config_contents[0].content.decode())
_validate_and_update_config(coverage_config, config_path)
config_stream = StringIO()
Expand Down
25 changes: 10 additions & 15 deletions src/python/pants/backend/python/rules/coverage_test.py
Expand Up @@ -7,7 +7,7 @@
import pytest

from pants.backend.python.rules.coverage import CoverageSubsystem, create_coverage_config
from pants.engine.fs import CreateDigest, Digest, DigestContents, FileContent, PathGlobs, Snapshot
from pants.engine.fs import CreateDigest, Digest, DigestContents, FileContent, PathGlobs
from pants.testutil.engine.util import MockGet, create_subsystem, run_rule
from pants.testutil.test_base import TestBase

Expand All @@ -19,28 +19,23 @@ def run_create_coverage_config_rule(self, coverage_config: Optional[str]) -> str
)
resolved_config: List[str] = []

def fake_handle_config(fcs):
assert len(fcs) == 1
assert fcs[0].path == ".coveragerc"
assert fcs[0].is_executable is False
resolved_config.append(fcs[0].content.decode())
def mock_handle_config(request: CreateDigest) -> Digest:
assert len(request) == 1
assert request[0].path == ".coveragerc"
assert request[0].is_executable is False
resolved_config.append(request[0].content.decode())
return Digest("jerry", 30)

def fake_read_config(digest):
# fake_read_config shouldn't get called if no config file provided
def mock_read_config(_: PathGlobs) -> DigestContents:
# This shouldn't be called if no config file provided.
assert coverage_config is not None
return DigestContents(
[FileContent(path="/dev/null/prelude", content=coverage_config.encode())]
)

mock_gets = [
MockGet(
product_type=Snapshot,
subject_type=PathGlobs,
mock=lambda _: Snapshot(Digest("bosco", 30), ("/dev/null/someconfig",), ()),
),
MockGet(product_type=DigestContents, subject_type=Digest, mock=fake_read_config,),
MockGet(product_type=Digest, subject_type=CreateDigest, mock=fake_handle_config),
MockGet(product_type=DigestContents, subject_type=PathGlobs, mock=mock_read_config),
MockGet(product_type=Digest, subject_type=CreateDigest, mock=mock_handle_config),
]

result = run_rule(create_coverage_config, rule_args=[coverage], mock_gets=mock_gets)
Expand Down
10 changes: 4 additions & 6 deletions src/python/pants/backend/python/rules/pex.py
Expand Up @@ -32,14 +32,12 @@
from pants.engine.collection import DeduplicatedCollection
from pants.engine.fs import (
EMPTY_DIGEST,
EMPTY_SNAPSHOT,
AddPrefix,
Digest,
GlobExpansionConjunction,
GlobMatchErrorBehavior,
MergeDigests,
PathGlobs,
Snapshot,
)
from pants.engine.platform import Platform, PlatformConstraint
from pants.engine.process import MultiPlatformProcess, ProcessResult
Expand Down Expand Up @@ -363,10 +361,10 @@ async def create_pex(

argv.extend(request.requirements)

constraint_file_snapshot = EMPTY_SNAPSHOT
constraint_file_digest = EMPTY_DIGEST
if python_setup.requirement_constraints is not None:
constraint_file_snapshot = await Get(
Snapshot,
constraint_file_digest = await Get(
Digest,
PathGlobs(
[python_setup.requirement_constraints],
glob_match_error_behavior=GlobMatchErrorBehavior.error,
Expand All @@ -387,7 +385,7 @@ async def create_pex(
pex_bin.digest,
sources_digest_as_subdir,
additional_inputs_digest,
constraint_file_snapshot.digest,
constraint_file_digest,
)
),
)
Expand Down
9 changes: 3 additions & 6 deletions src/python/pants/backend/python/rules/pex_from_targets.py
Expand Up @@ -24,7 +24,7 @@
PythonRequirementsField,
)
from pants.engine.addresses import Address, Addresses
from pants.engine.fs import Digest, DigestContents, MergeDigests, PathGlobs, Snapshot
from pants.engine.fs import Digest, DigestContents, MergeDigests, PathGlobs
from pants.engine.rules import RootRule, rule
from pants.engine.selectors import Get
from pants.engine.target import TransitiveTargets
Expand Down Expand Up @@ -132,18 +132,15 @@ async def pex_from_targets(request: PexFromTargetsRequest, python_setup: PythonS

if python_setup.requirement_constraints:
exact_req_projects = {Requirement.parse(req).project_name for req in exact_reqs}
constraint_file_snapshot = await Get(
Snapshot,
constraints_file_contents = await Get(
DigestContents,
PathGlobs(
[python_setup.requirement_constraints],
glob_match_error_behavior=GlobMatchErrorBehavior.error,
conjunction=GlobExpansionConjunction.all_match,
description_of_origin="the option `--python-setup-requirement-constraints`",
),
)
constraints_file_contents = await Get(
DigestContents, Digest, constraint_file_snapshot.digest
)
constraints_file_reqs = set(
parse_requirements(next(iter(constraints_file_contents)).content.decode())
)
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/backend/python/rules/pytest_runner.py
Expand Up @@ -35,7 +35,7 @@
from pants.core.goals.test import TestDebugRequest, TestFieldSet, TestResult, TestSubsystem
from pants.core.util_rules.determine_source_files import SourceFiles, SpecifiedSourceFilesRequest
from pants.engine.addresses import Addresses
from pants.engine.fs import AddPrefix, Digest, MergeDigests, PathGlobs, Snapshot, SnapshotSubset
from pants.engine.fs import AddPrefix, Digest, DigestSubset, MergeDigests, PathGlobs, Snapshot
from pants.engine.interactive_process import InteractiveProcess
from pants.engine.internals.uuid import UUIDRequest
from pants.engine.process import FallibleProcessResult, Process
Expand Down Expand Up @@ -274,7 +274,7 @@ async def run_python_test(
coverage_data = None
if test_subsystem.use_coverage:
coverage_snapshot = await Get(
Snapshot, SnapshotSubset(result.output_digest, PathGlobs([".coverage"]))
Snapshot, DigestSubset(result.output_digest, PathGlobs([".coverage"]))
)
if coverage_snapshot.files == (".coverage",):
coverage_data = PytestCoverageData(field_set.address, coverage_snapshot.digest)
Expand All @@ -284,7 +284,7 @@ async def run_python_test(
xml_results_digest = None
if test_results_file:
xml_results_snapshot = await Get(
Snapshot, SnapshotSubset(result.output_digest, PathGlobs([test_results_file]))
Snapshot, DigestSubset(result.output_digest, PathGlobs([test_results_file]))
)
if xml_results_snapshot.files == (test_results_file,):
xml_results_digest = await Get(
Expand Down