Skip to content

Commit

Permalink
Don't special-case python dists in resolve_requirements(). (#5483)
Browse files Browse the repository at this point in the history
Since we now synthesize PythonRequirementLibrary targets for
each local dist, there's no need to handle them specially.

Also ensures that we always create a requirements product, even
for an empty set of requirements, so that downstream tasks
don't have to check for this case.  Removes a test that actually
verified that the opposite was true, for some reason...
  • Loading branch information
benjyw authored Feb 20, 2018
1 parent c014e8d commit 71a33d6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
9 changes: 3 additions & 6 deletions src/python/pants/backend/python/tasks/resolve_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants.backend.python.tasks.pex_build_util import has_python_requirements, is_local_python_dist
from pants.backend.python.tasks.pex_build_util import has_python_requirements
from pants.backend.python.tasks.resolve_requirements_task_base import ResolveRequirementsTaskBase


Expand All @@ -18,8 +18,5 @@ def product_types(cls):
return [cls.REQUIREMENTS_PEX]

def execute(self):
req_libs = self.context.targets(has_python_requirements)
dist_tgts = self.context.targets(is_local_python_dist)
if req_libs or dist_tgts:
pex = self.resolve_requirements(req_libs, dist_tgts)
self.context.products.register_data(self.REQUIREMENTS_PEX, pex)
pex = self.resolve_requirements(self.context.targets(has_python_requirements))
self.context.products.register_data(self.REQUIREMENTS_PEX, pex)
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ def prepare(cls, options, round_manager):
round_manager.require_data(PythonInterpreter)
round_manager.optional_product(PythonRequirementLibrary) # For local dists.

def resolve_requirements(self, req_libs, local_dist_targets=None):
def resolve_requirements(self, req_libs):
"""Requirements resolution for PEX files.
:param req_libs: A list of :class:`PythonRequirementLibrary` targets to resolve.
:param local_dist_targets: A list of :class:`PythonDistribution` targets to resolve.
:returns: a PEX containing target requirements and any specified python dist targets.
"""
tgts = req_libs
if local_dist_targets:
tgts = req_libs + local_dist_targets
with self.invalidated(tgts) as invalidation_check:
with self.invalidated(req_libs) as invalidation_check:
# If there are no relevant targets, we still go through the motions of resolving
# an empty set of requirements, to prevent downstream tasks from having to check
# for this special case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ class ResolveRequirementsTest(TaskTestBase):
def task_type(cls):
return ResolveRequirements

def test_resolve_no_targets(self):
empty_tgt = self.make_target(spec=':empty')
pex = self._resolve_requirements([empty_tgt])
self.assertTrue(pex is None)

def test_resolve_simple_requirements(self):
noreqs_tgt = self._fake_target('noreqs', [])
ansicolors_tgt = self._fake_target('ansicolors', ['ansicolors==1.0.2'])
Expand Down

0 comments on commit 71a33d6

Please sign in to comment.