Skip to content

Commit f4ab07c

Browse files
authored
Make requirements on codegen products optional. (pantsbuild#6357)
We declare product requirements in various places to force codegen to run before, e.g., dependency resolution. However currently these requirements are mandatory, so deregistering all codegen backends will cause the round engine to find no producers of these products, and fail. This commit changes these requirements to optional, so that if there are no codegen backends, we don't attempt to depend on their products. Also, minor unrelated documentation nits that weren't worth a separate pull request.
1 parent b0a2469 commit f4ab07c

File tree

7 files changed

+17
-7
lines changed

7 files changed

+17
-7
lines changed

src/python/pants/backend/jvm/tasks/coursier_resolve.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,10 @@ def product_types(cls):
661661
@classmethod
662662
def prepare(cls, options, round_manager):
663663
super(CoursierResolve, cls).prepare(options, round_manager)
664-
round_manager.require_data('java')
665-
round_manager.require_data('scala')
664+
# Codegen may inject extra resolvable deps, so make sure we have a product dependency
665+
# on relevant codegen tasks, if any.
666+
round_manager.optional_data('java')
667+
round_manager.optional_data('scala')
666668

667669
@classmethod
668670
def register_options(cls, register):

src/python/pants/backend/jvm/tasks/ivy_resolve.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ def product_types(cls):
6969
@classmethod
7070
def prepare(cls, options, round_manager):
7171
super(IvyResolve, cls).prepare(options, round_manager)
72-
round_manager.require_data('java')
73-
round_manager.require_data('scala')
72+
# Codegen may inject extra resolvable deps, so make sure we have a product dependency
73+
# on relevant codegen tasks, if any.
74+
round_manager.optional_data('java')
75+
round_manager.optional_data('scala')
7476

7577
def __init__(self, *args, **kwargs):
7678
super(IvyResolve, self).__init__(*args, **kwargs)

src/python/pants/backend/python/tasks/gather_sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def product_types(cls):
4040
@classmethod
4141
def prepare(cls, options, round_manager):
4242
round_manager.require_data(PythonInterpreter)
43-
round_manager.require_data('python') # For codegen.
43+
round_manager.optional_data('python') # For codegen.
4444

4545
def execute(self):
4646
targets = self._collect_source_targets()

src/python/pants/backend/python/tasks/python_binary_create.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def cache_target_dirs(self):
5151

5252
@classmethod
5353
def prepare(cls, options, round_manager):
54+
# See comment below for why we don't use the GatherSources.PYTHON_SOURCES product.
5455
round_manager.require_data(PythonInterpreter)
55-
round_manager.require_data('python') # For codegen.
56+
round_manager.optional_data('python') # For codegen.
5657
round_manager.optional_product(PythonRequirementLibrary) # For local dists.
5758

5859
@staticmethod

src/python/pants/backend/python/tasks/resolve_requirements_task_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def _python_native_code_settings(self):
4545
def prepare(cls, options, round_manager):
4646
round_manager.require_data(PythonInterpreter)
4747
round_manager.optional_product(PythonRequirementLibrary) # For local dists.
48+
# Codegen may inject extra resolvable deps, so make sure we have a product dependency
49+
# on relevant codegen tasks, if any.
50+
round_manager.optional_data('python')
4851

4952
def resolve_requirements(self, interpreter, req_libs):
5053
"""Requirements resolution for PEX files.

src/python/pants/goal/run_tracker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ def initialize(self):
163163
raise AssertionError('RunTracker.initialize must not be called multiple times.')
164164

165165
# Initialize the run.
166+
167+
# Select a globally unique ID for the run, that sorts by time.
166168
millis = int((self._run_timestamp * 1000) % 1000)
167169
run_id = 'pants_run_{}_{}_{}'.format(
168170
time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime(self._run_timestamp)),

src/python/pants/task/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def check_artifact_cache(self, vts):
535535
def do_check_artifact_cache(self, vts, post_process_cached_vts=None):
536536
"""Checks the artifact cache for the specified list of VersionedTargetSets.
537537
538-
Returns a pair (cached, uncached) of VersionedTargets that were
538+
Returns a tuple (cached, uncached, uncached_causes) of VersionedTargets that were
539539
satisfied/unsatisfied from the cache.
540540
"""
541541
if not vts:

0 commit comments

Comments
 (0)