From fe8dd55f5f580aa1252ba4bd95ccbf78186eb8ff Mon Sep 17 00:00:00 2001 From: Chris Livingston Date: Thu, 11 Jan 2018 22:36:45 -0800 Subject: [PATCH] Simplify a few lines, add check for ambiguous python dists, and fix copyright date --- .../tasks/python_execution_task_base.py | 20 +++++++++---------- .../build_local_python_distributions.py | 2 ++ .../python/tasks/test_python_binary_create.py | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/python/pants/backend/python/tasks/python_execution_task_base.py b/src/python/pants/backend/python/tasks/python_execution_task_base.py index 44a357e6c2c..0eb39554d98 100644 --- a/src/python/pants/backend/python/tasks/python_execution_task_base.py +++ b/src/python/pants/backend/python/tasks/python_execution_task_base.py @@ -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. @@ -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 @@ -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()] @@ -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] diff --git a/src/python/pants/backend/python/tasks2/build_local_python_distributions.py b/src/python/pants/backend/python/tasks2/build_local_python_distributions.py index 1bfef68bbcc..7d09671bf7f 100644 --- a/src/python/pants/backend/python/tasks2/build_local_python_distributions.py +++ b/src/python/pants/backend/python/tasks2/build_local_python_distributions.py @@ -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] diff --git a/tests/python/pants_test/backend/python/tasks/test_python_binary_create.py b/tests/python/pants_test/backend/python/tasks/test_python_binary_create.py index f7be557bd1c..f1838f897f0 100644 --- a/tests/python/pants_test/backend/python/tasks/test_python_binary_create.py +++ b/tests/python/pants_test/backend/python/tasks/test_python_binary_create.py @@ -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,