def version(dist, attr, value): """ Handle the ``version`` keyword to setuptools.setup() .. note:: This function is normally called by setuptools, it is advertised in the entry points of versiontools as setuptools extension. There is no need to call in manually. .. versionadded:: 1.3 """ # We need to look at dist.metadata.version to actually see the version # that was passed to setup. Something in between does not seem to like our # version string and we get 0 here, odd. if value == 0: value = dist.metadata.version if sys.version_info[:1] < (3, ): isstring = lambda string: isinstance(string, basestring) else: isstring = lambda string: isinstance(string, str) if not (isstring(value) and value.startswith(":versiontools:")): return # Peel away the magic tag value = value[len(":versiontools:"):] try: # Lookup the version object version = Version.from_expression(value) # Update distribution metadata dist.metadata.version = str(version) except ValueError: message = _get_exception_message(*sys.exc_info()) if message.startswith(": "): message = message[2:] raise DistutilsSetupError(message)
def version(dist, attr, value): """ Handle the ``version`` keyword to setuptools.setup() .. note:: This function is normally called by setuptools, it is advertised in the entry points of versiontools as setuptools extension. There is no need to call in manually. .. versionadded:: 1.3 """ # We need to look at dist.metadata.version to actually see the version # that was passed to setup. Something in between does not seem to like our # version string and we get 0 here, odd. if value == 0: value = dist.metadata.version if sys.version_info[:1] < (3,): isstring = lambda string: isinstance(string, basestring) else: isstring = lambda string: isinstance(string, str) if not (isstring(value) and value.startswith(":versiontools:")): return # Peel away the magic tag value = value[len(":versiontools:"):] try: # Lookup the version object version = Version.from_expression(value) # Update distribution metadata dist.metadata.version = str(version) except ValueError: message = _get_exception_message(*sys.exc_info()) if message.startswith(": "): message = message[2:] raise DistutilsSetupError(message)
def test_positional_accessors(self): version = Version(1, 2, 3, "dev", 4) self.assertEqual(version[0], 1) self.assertEqual(version[1], 2) self.assertEqual(version[2], 3) self.assertEqual(version[3], "dev") self.assertEqual(version[4], 4)
def test_accessors(self): version = Version(1, 2, 3, "dev", 4) self.assertEqual(version.major, 1) self.assertEqual(version.minor, 2) self.assertEqual(version.micro, 3) self.assertEqual(version.releaselevel, "dev") self.assertEqual(version.serial, 4)
def test_formatting_serial_used_for_alpha_beta_and_candidate(self): self.assertEqual(str(Version(1, 2, 3, "alpha", 4)), "1.2.3a4") self.assertEqual(str(Version(1, 2, 3, "beta", 4)), "1.2.3b4") self.assertEqual(str(Version(1, 2, 3, "candidate", 4)), "1.2.3c4")
def test_formatting_serial_not_used_for_final(self): self.assertEqual(str(Version(1, 2, 3, "final", 4)), "1.2.3")
def test_formatting_serial_not_used_for_development(self): self.assertEqual(str(Version(1, 2, 3, "dev", 4)), "1.2.3.dev")
def test_formatting_nonzero_micro_retained(self): self.assertEqual(str(Version(1, 0, 1)), "1.0.1")
def test_formatting_zero_micro_discarded(self): self.assertEqual(str(Version(1, 0)), "1.0") self.assertEqual(str(Version(1, 0, 0)), "1.0")
def test_serial_can_be_zero_for_certain_releaselevel(self): self.assertEqual(Version(1, 2, 3, "final", 0).serial, 0) self.assertEqual(Version(1, 2, 3, "dev", 0).serial, 0)
def test_defaults(self): self.assertEqual(Version(1, 0), (1, 0, 0, "final", 0))
def test_formatting_no_dev_suffix_for_alpha_beta_and_candidate(self): self.mock_vcs_revno(5) self.assertEqual(str(Version(1, 2, 3, "alpha", 4)), "1.2.3a4") self.assertEqual(str(Version(1, 2, 3, "beta", 4)), "1.2.3b4") self.assertEqual(str(Version(1, 2, 3, "candidate", 4)), "1.2.3c4")
def test_formatting_with_vcs_and_revno(self): self.mock_vcs_revno(5) version = Version(1, 2, 3, "dev", 4) self.assertEqual(str(version), "1.2.3.dev5")
def test_formatting_without_vcs(self): version = Version(1, 2, 3, "dev", 4) self.assertEqual(str(version), "1.2.3.dev")
# The encoding of source files. #source_encoding = 'utf-8' # The master toctree document. master_doc = 'index' # General information about the project. project = u'Version Tools' copyright = u'2010-2011, Linaro Limited' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # from versiontools import Version ver = Version.from_expression("versiontools") # The short X.Y version. version = "%d.%d" % (ver.major, ver.minor) # The full version, including alpha/beta/rc tags. release = str(ver) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y'