Skip to content

Commit

Permalink
fix the version string checking for local dist creation to add the no…
Browse files Browse the repository at this point in the history
…rmalized snapshot version
  • Loading branch information
cosmicexplorer committed Jul 3, 2018
1 parent 0de459d commit 7fbc9f1
Showing 1 changed file with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import re
from textwrap import dedent

from pants.backend.native.register import rules as native_backend_rules
from pants.backend.python.register import rules as python_backend_rules
from pants.backend.python.targets.python_distribution import PythonDistribution
from pants.backend.python.tasks.build_local_python_distributions import \
BuildLocalPythonDistributions
from pants.util.collections import assert_single_element
from pants_test.backend.python.tasks.python_task_test_base import (PythonTaskTestBase,
check_wheel_platform_matches_host,
name_and_platform)
Expand Down Expand Up @@ -115,6 +117,26 @@ def _retrieve_single_product_at_target_base(self, product_mapping, target):
single_product = all_products[0]
return single_product

# TODO: This snapshot version tagging is only performed for python_dist() targets, but the
# setup.py invocation command line is generated in SetupPyRunner in setup_py.py. Could this
# testing be done in test_setup_py.py?
def _get_dist_snapshot_version(self, task, python_dist_target):
"""Local python_dist() builds are tagged with the versioned target's fingerprint using the
--tag-build option in the egg_info command. This fingerprint string is slightly modified by
distutils to ensure a valid version string, and this method finds what that modified version
string is so we can verify that the produced local dist is being tagged with the correct
snapshot version.
"""
with task.invalidated([python_dist_target], invalidate_dependents=True) as invalidation_check:
versioned_dist_target = assert_single_element(invalidation_check.all_vts)

versioned_target_fingerprint = versioned_dist_target.cache_key.hash

# This performs the normalization that distutils performs to the version string passed to the
# --tag-build option. The argument we pass to that option begins with a +, which is
# unchanged. See https://www.python.org/dev/peps/pep-0440/ for further information.
return re.sub(r'[^a-zA-Z0-9]', '.', versioned_target_fingerprint.lower())

def _create_distribution_synthetic_target(self, python_dist_target):
context = self._scheduling_context(
target_roots=[python_dist_target],
Expand All @@ -126,12 +148,16 @@ def _create_distribution_synthetic_target(self, python_dist_target):
self.assertEquals(1, len(synthetic_tgts))
synthetic_target = next(iter(synthetic_tgts))

return context, synthetic_target
snapshot_version = self._get_dist_snapshot_version(
python_create_distributions_task, python_dist_target)

return context, synthetic_target, snapshot_version

def test_python_create_universal_distribution(self):
universal_dist = self.target_dict['universal']
context, synthetic_target = self._create_distribution_synthetic_target(universal_dist)
self.assertEquals(['universal_dist==0.0.0'],
context, synthetic_target, snapshot_version = self._create_distribution_synthetic_target(
universal_dist)
self.assertEquals(['universal_dist==0.0.0+{}'.format(snapshot_version)],
[str(x.requirement) for x in synthetic_target.requirements.value])

local_wheel_products = context.products.get('local_wheels')
Expand All @@ -141,8 +167,9 @@ def test_python_create_universal_distribution(self):

def test_python_create_platform_specific_distribution(self):
platform_specific_dist = self.target_dict['platform_specific']
context, synthetic_target = self._create_distribution_synthetic_target(platform_specific_dist)
self.assertEquals(['platform_specific_dist==0.0.0'],
context, synthetic_target, snapshot_version = self._create_distribution_synthetic_target(
platform_specific_dist)
self.assertEquals(['platform_specific_dist==0.0.0+{}'.format(snapshot_version)],
[str(x.requirement) for x in synthetic_target.requirements.value])

local_wheel_products = context.products.get('local_wheels')
Expand Down

0 comments on commit 7fbc9f1

Please sign in to comment.