Skip to content

Commit

Permalink
Tweak V2 pytest's execute process description to get more cache hits (p…
Browse files Browse the repository at this point in the history
…antsbuild#7737)

Resolves pantsbuild#7732. The resolve requirements process is solely a function of the requirements it is fed and does not matter what target it is being used for.

As followups, we will likely want to:
1) No longer make `description` be a part of the cache key.
2) Improve visualization of V2 rules, both for the rule graph and for the UI.
  • Loading branch information
Eric-Arellano authored May 16, 2019
1 parent 155077e commit 27a3819
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/python/pants/backend/python/rules/python_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 59,18 @@ def run_python_test(test_target, pytest, python_setup, source_root_config):
all_targets = [t.adaptor for t in transitive_hydrated_targets.closure]

# Produce a pex containing pytest and all transitive 3rdparty requirements.
all_requirements = []
all_target_requirements = []
for maybe_python_req_lib in all_targets:
# This is a python_requirement()-like target.
if hasattr(maybe_python_req_lib, 'requirement'):
all_requirements.append(str(maybe_python_req_lib.requirement))
all_target_requirements.append(str(maybe_python_req_lib.requirement))
# This is a python_requirement_library()-like target.
if hasattr(maybe_python_req_lib, 'requirements'):
for py_req in maybe_python_req_lib.requirements:
all_requirements.append(str(py_req.requirement))
all_target_requirements.append(str(py_req.requirement))

# Sort all user requirement strings to increase the chance of cache hits across invocations.
all_requirements = sorted(all_target_requirements list(pytest.get_requirement_strings()))

# TODO(#7061): This str() can be removed after we drop py2!
python_binary = text_type(sys.executable)
Expand All @@ -85,17 88,13 @@ def run_python_test(test_target, pytest, python_setup, source_root_config):
'-o', output_pytest_requirements_pex_filename,
] interpreter_constraint_args [
# TODO(#7061): This text_type() wrapping can be removed after we drop py2!
text_type(req)
# Sort all user requirement strings to increase the chance of cache hits across invocations.
for req in sorted(
list(pytest.get_requirement_strings())
list(all_requirements))
text_type(req) for req in all_requirements
]
requirements_pex_request = ExecuteProcessRequest(
argv=tuple(requirements_pex_argv),
env={'PATH': text_type(os.pathsep.join(python_setup.interpreter_search_paths))},
input_files=pex_snapshot.directory_digest,
description='Resolve requirements for {}'.format(test_target.address.reference()),
description='Resolve requirements: {}'.format(", ".join(all_requirements)),
output_files=(output_pytest_requirements_pex_filename,),
)
requirements_pex_response = yield Get(
Expand Down

0 comments on commit 27a3819

Please sign in to comment.