Skip to content

Commit

Permalink
Simplify a few lines, add check for ambiguous python dists, and fix c…
Browse files Browse the repository at this point in the history
…opyright date
  • Loading branch information
Chris Livingston committed Jan 30, 2018
1 parent aabf88f commit fe8dd55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def prepare(cls, options, round_manager):
super(PythonExecutionTaskBase, cls).prepare(options, round_manager)
round_manager.require_data(PythonInterpreter)
round_manager.require_data(ResolveRequirements.REQUIREMENTS_PEX)
round_manager.require_data(GatherSources.PythonSources)
round_manager.require_data(GatherSources.PYTHON_SOURCES)

def extra_requirements(self):
"""Override to provide extra requirements needed for execution.
Expand All @@ -103,7 +103,8 @@ def extra_requirements(self):
def create_pex(self, pex_info=None):
"""Returns a wrapped pex that "merges" the other pexes via PEX_PATH."""
relevant_targets = self.context.targets(
lambda tgt: isinstance(tgt, (PythonDistribution, PythonRequirementLibrary, PythonTarget, Files)))
lambda tgt: isinstance(tgt, (
PythonDistribution, PythonRequirementLibrary, PythonTarget, Files)))
with self.invalidated(relevant_targets) as invalidation_check:

# If there are no relevant targets, we still go through the motions of resolving
Expand All @@ -121,13 +122,11 @@ def create_pex(self, pex_info=None):

# Note that we check for the existence of the directory, instead of for invalid_vts,
# to cover the empty case.
local_python_dist_targets = self.context.targets(is_local_python_dist)
invalid_target_objs = [v.target for v in invalidation_check.invalid_vts]
context_has_invalid_python_dists = any([lpdt in invalid_target_objs for lpdt in local_python_dist_targets])
if not os.path.isdir(path) or context_has_invalid_python_dists:
source_pexes = self.context.products.get_data(GatherSources.PythonSources).all()
requirements_pex = self.context.products.get_data(ResolveRequirements.REQUIREMENTS_PEX)
pexes = [requirements_pex] + source_pexes
if not os.path.isdir(path):
pexes = [
self.context.products.get_data(ResolveRequirements.REQUIREMENTS_PEX),
self.context.products.get_data(GatherSources.PYTHON_SOURCES)
]

if self.extra_requirements():
extra_reqs = [PythonRequirement(req_str) for req_str in self.extra_requirements()]
Expand All @@ -136,8 +135,7 @@ def create_pex(self, pex_info=None):
addr, PythonRequirementLibrary, requirements=extra_reqs)
# Add the extra requirements first, so they take precedence over any colliding version
# in the target set's dependency closure.
pexes = [self.resolve_requirements([self.context.build_graph.get_target(addr)], local_python_dist_targets)] + pexes

pexes = [self.resolve_requirements([self.context.build_graph.get_target(addr)])] + pexes

extra_pex_paths = [pex.path() for pex in pexes if pex]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ def _get_whl_from_dir(self, install_dir):
dists = glob.glob(os.path.join(install_dir, '*.whl'))
if len(dists) == 0:
raise TaskError('No distributions were produced by python_create_distribution task.')
if len(dists) > 1:
raise TaskError('Ambiguous local python distributions found: %s' % (' '.join(dists)))
return dists[0]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2017 Pants project contributors (see CONTRIBUTORS.md).
# Copyright 2016 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
Expand Down

0 comments on commit fe8dd55

Please sign in to comment.