def test_simple3_bump_errors(self): """bad bump commands""" v1 = Version('1.2.3', scheme=Simple3VersionScheme) assert (not v1.bump('')) assert (str(v1) == '1.2.3') assert (not v1.bump('foo')) assert (str(v1) == '1.2.3')
def test_perl_version_comparisons(self): """test comparison operators on PerlVersionScheme""" # load versions with increasing version numbers versions = [Version(vstr, scheme=PerlVersionScheme) for vstr in [ '0.00', '0.01', '0.20', '0.90', '3.00', '3.04', '3.50', '4.00', '4.09', '10.00', '10.18', '999.999' ]] # check each adjacent version numbers for index, version in enumerate(versions[0:-1]): assert versions[index] < versions[index + 1], \ "{v1} < {v2}".format(v1=versions[index], v2=versions[index + 1]) assert versions[index + 1] > versions[index], \ "{v1} > {v2}".format(v1=versions[index + 1], v2=versions[index]) assert versions[index] <= versions[index + 1], \ "{v1} <= {v2}".format(v1=versions[index], v2=versions[index + 1]) assert versions[index + 1] >= versions[index], \ "{v1} >= {v2}".format(v1=versions[index + 1], v2=versions[index]) assert versions[index] != versions[index + 1], \ "{v1} != {v2}".format(v1=versions[index], v2=versions[index + 1]) assert Version(str(versions[index]), scheme=PerlVersionScheme) == versions[index], \ "{v1} == {v2}".format(v1=Version(str(versions[index])), v2=versions[index])
def test_four_part(): string = "1.7.1.3" print(string) Version.supported_version_schemes = [Pep440VersionScheme, Simple4VersionScheme] version = Version(string, scheme=Simple4VersionScheme) version.bump() # _ = Version(str(next_version), scheme=Simple4VersionScheme) print( Version(string, scheme=Simple4VersionScheme), version, "simple-4 part (versio)" )
def test_pep440_bump_subfields(self): """PEP 440 subfield bumps""" v1 = Version('1.2.3.4', scheme=Pep440VersionScheme) v1.bump('Tiny2') assert (str(v1) == '1.2.3.5') v1.bump('Tiny') assert (str(v1) == '1.2.4.0') v1.bump('Minor') assert (str(v1) == '1.3.0.0') v1.bump('Major') assert (str(v1) == '2.0.0.0')
def test_simple4_version_comparisons(self): """test comparison operators on Simple4VersionScheme""" # load versions with increasing version numbers versions = [Version(vstr, scheme=Simple4VersionScheme) for vstr in [ '0.0.0.0', '0.0.0.1', '0.0.0.2', '0.0.0.9', '0.0.3.0', '0.0.3.4', '0.0.3.5', '0.0.4.0', '0.0.4.9', '0.1.0.0', '0.1.0.1', '0.1.10.0', '0.2.0.0', '0.2.0.11', '0.2.3.0', '0.10.0.0', '0.10.0.18', '0.10.22.0', '1.0.0.0', '1.0.0.1', '1.0.1.0', '1.1.0.0', '1.10.0.0', '1.10.10.0', '1.10.10.10', '10.10.10.10', '999.999.999.999' ]] # check each adjacent version numbers for index, version in enumerate(versions[0:-1]): assert versions[index] < versions[index + 1], \ "{v1} < {v2}".format(v1=versions[index], v2=versions[index + 1]) assert versions[index + 1] > versions[index], \ "{v1} > {v2}".format(v1=versions[index + 1], v2=versions[index]) assert versions[index] <= versions[index + 1], \ "{v1} <= {v2}".format(v1=versions[index], v2=versions[index + 1]) assert versions[index + 1] >= versions[index], \ "{v1} >= {v2}".format(v1=versions[index + 1], v2=versions[index]) assert versions[index] != versions[index + 1], \ "{v1} != {v2}".format(v1=versions[index], v2=versions[index + 1]) assert Version(str(versions[index]), scheme=Simple4VersionScheme) == versions[index], \ "{v1} == {v2}".format(v1=Version(str(versions[index])), v2=versions[index])
def bump_field(field): """ Increment the given field by one. :param field: the field name (ex: 'Minor'). :type field: str :return: the new version :rtype: str """ original_version_str = get_project_version(project_package=Project.package) ver = Version(original_version_str) info('ver before bump: %s' % str(ver)) ver.bump(field) info('ver after bump: %s' % str(ver)) set_project_version(str(ver), project_package=Project.package) Project.version = get_project_version(project_package=Project.package) info("Bumped version from %s to %s" % (original_version_str, Project.version)) return str(ver)
def do(self, ver): Debug("do(%s) self.bump: %s" % (ver, self.bump)) # If bump is a list of bumps to perform, create a new class instance # and set its bump, do the bump, then return result if isinstance(self.bump, list): for item in self.bump: classn = self.__class__ Debug("Creating v2 classn(%s)" % item) v2 = classn(item) Debug("Running v2.do(%s)" % ver) ver = v2.do(str(ver)) Debug("v2.do() result: %s" % ver) return str(ver) myver = Version(ver, scheme=self.scheme) myver.bump(self.bump) Debug("ForceSemanticVer(%s) bump '%s': %s" % (ver, self.bump, myver)) # Make sure we return a string, not a Version() object return str(myver)
def test_simple3_bump(self): """version bumps""" v1 = Version('1.2.3', scheme=Simple3VersionScheme) assert (v1.bump()) assert (str(v1) == '1.2.4') assert (v1.bump('Minor')) assert (str(v1) == '1.3.0') assert (v1.bump('minor')) assert (str(v1) == '1.4.0') assert (v1.bump('Tiny')) assert (str(v1) == '1.4.1') assert (v1.bump('tiny')) assert (str(v1) == '1.4.2') assert (v1.bump('Major')) assert (str(v1) == '2.0.0')
def test_pep440_bump_sequences(self): """PEP 440 sequence bumps""" v1 = Version('1.2.3a4.post5.dev6', scheme=Pep440VersionScheme) assert (not v1.bump('dev', 0)) assert (str(v1) == '1.2.3a4.post5.dev6') assert (not v1.bump('post', 0)) assert (str(v1) == '1.2.3a4.post5.dev6') assert (v1.bump('pre', 0)) assert (str(v1) == '1.2.3b1') assert (v1.bump('pre', 0)) assert (str(v1) == '1.2.3c1') assert (v1.bump('pre', 0)) assert (str(v1) == '1.2.3rc1') assert (not v1.bump('pre', 0)) assert (str(v1) == '1.2.3rc1')
def test_simple4_bump(self): """version bumps""" v1 = Version('1.2.3.4', scheme=Simple4VersionScheme) assert (v1.bump()) assert (str(v1) == '1.2.3.5') assert (v1.bump('Minor')) assert (str(v1) == '1.3.0.0') assert (v1.bump('Tiny')) assert (str(v1) == '1.3.1.0') assert (v1.bump('Tiny2')) assert (str(v1) == '1.3.1.1') assert (v1.bump('Major')) assert (str(v1) == '2.0.0.0')
def test_pep440_bump_pre(self): """PEP 440 field bumps that start new version parts""" v1 = Version('1.2.3', scheme=Pep440VersionScheme) assert (v1.bump('pre', 0), str(v1)) assert (str(v1) == '1.2.3a1') assert (v1.bump('pre', 1), str(v1)) assert (str(v1) == '1.2.3a2') assert (v1.bump('post', 0), str(v1)) assert (str(v1) == '1.2.3a2.post1') assert (v1.bump('dev', 0), str(v1)) assert (str(v1) == '1.2.3a2.post1.dev1')
def test_simple5_bump(self): """version bumps""" v1 = Version('1.2.3.4.5', scheme=Simple5VersionScheme) assert (v1.bump()) assert (str(v1) == '1.2.3.4.6') assert (v1.bump('Minor')) assert (str(v1) == '1.3.0.0.0') assert (v1.bump('Tiny')) assert (str(v1) == '1.3.1.0.0') assert (v1.bump('Build')) assert (str(v1) == '1.3.1.1.0') assert (v1.bump('Patch')) assert (str(v1) == '1.3.1.1.1') assert (v1.bump('Major')) assert (str(v1) == '2.0.0.0.0')
def _shorten_version(version): v = Version(str(version)) v.parts = [v.parts[0]] + [None] * 4 return v
def collect_info(): release_version = opts.get('release_version') dev_version = opts.get('dev_version') setup_py = require_setup_py() try: if release_version is None: # try extracting version info try: release_version = find_assign(setup_py, 'version') except ValueError as e: issues.error( e, 'There was an issue extracting the version number from ' 'setup.py. Please make sure there is only a single ' 'version= assignment in that file.') log.debug('Release version automatically determined from setup.py') else: log.debug('Release version given on commandline.') # parse release version string release_version = _shorten_version(release_version) if dev_version is None: # if we're given no dev version, we try to create one by # incrementing the release version dev_version = Version(str(release_version)) dev_version.bump('release') dev_version.bump('dev') else: # parse dev version string dev_version = Version(dev_version) except TypeError as e: issues.error( 'Bad version number: {}'.format(e), 'The version number "{}" is not a version number that can be ' 'understood by distutils.\n\n' 'Please correct the different version number and try again.' .format(e)) # get package name try: pkg_name = find_assign(setup_py, 'name') except ValueError as e: issues.error( e, 'Could not extract package name from setup.py. Please make sure ' 'there is only a single name= expression in that file.') info['pkg_name'] = pkg_name info['release_version'] = str(release_version) info['dev_version'] = str(dev_version) # create the short versions info['release_version_short'] = str(_shorten_version(release_version)) info['dev_version_short'] = str(_shorten_version(dev_version)) # use provided package dirs or auto-detected one from setup.py pkg_paths = set(opts['package_dir']) if not pkg_paths: pkg_paths = set([info['pkg_name'], info['pkg_name'].replace('-', '_')]) log.debug('Package paths: {}'.format(pkg_paths)) init_files = [path + '/__init__.py' for path in pkg_paths] init_files = filter(commit.path_exists, init_files) if not init_files: issues.warn( 'No __init__.py files found for packages.', 'While looking for package __init__.py files to update version ' 'information in, none were found. This most often happens if your ' 'package contains only modules or is not named after its primary ' 'Python package.') info['init_files'] = init_files
def test_pep440_bump_errors(self): """PEP 440 bump errors""" v1 = Version('1.2.3a4.post5.dev6', scheme=Pep440VersionScheme) assert (not v1.bump('release', 3)) assert (str(v1) == '1.2.3a4.post5.dev6')
# coding=utf-8 """ py.test unit tests for Versio. """ from _pytest.python import raises from versio.version import Version from versio.version_scheme import Pep440VersionScheme, Simple3VersionScheme, Simple4VersionScheme, PerlVersionScheme Version.set_supported_version_schemes((Simple3VersionScheme, Simple4VersionScheme, Pep440VersionScheme,)) # noinspection PyProtectedMember,PyDocstring,PyMethodMayBeStatic class TestVersion(object): def _check_parsing(self, version, release, pre=None, post=None, dev=None, local=None): """helper for checking the parsing""" scheme = Pep440VersionScheme return (scheme._is_match(version) and scheme._release(version) == release and scheme._pre(version) == pre and scheme._post(version) == post and scheme._dev(version) == dev and scheme._local(version) == local) def test_pep440_parse(self): """check basic parsing capability""" assert (self._check_parsing(version='1', release='1')) assert (self._check_parsing(version='1.2', release='1.2')) assert (self._check_parsing(version='1.2.3a4', release='1.2.3', pre='a4')) assert (self._check_parsing(version='1.2.3b4', release='1.2.3', pre='b4')) assert (self._check_parsing(version='1.2.3c4', release='1.2.3', pre='c4'))
from versio.version_scheme import (Pep440VersionScheme, PerlVersionScheme, Simple3VersionScheme, Simple4VersionScheme) from localshop.utils import enqueue from localshop.apps.packages import forms, models from localshop.apps.packages.mixins import RepositoryMixin from localshop.apps.packages.pypi import get_search_names from localshop.apps.packages.tasks import fetch_package from localshop.apps.packages.utils import (get_versio_versioning_scheme, parse_distutils_request) from localshop.apps.permissions.mixins import RepositoryAccessMixin logger = logging.getLogger(__name__) Version.set_supported_version_schemes(( Simple3VersionScheme, Simple4VersionScheme, Pep440VersionScheme, )) class SimpleIndex(CsrfExemptMixin, RepositoryMixin, RepositoryAccessMixin, generic.ListView): """Index view with all available packages used by /simple url This page is used by pip/easy_install to find packages. """ context_object_name = 'packages' http_method_names = ['get', 'post'] template_name = 'packages/simple_package_list.html'
def test_variable_dotted_bump(self): """version bumps""" v1 = Version('1', scheme=VariableDottedIntegerVersionScheme) v2 = Version('1.2', scheme=VariableDottedIntegerVersionScheme) v3 = Version('1.2.3', scheme=VariableDottedIntegerVersionScheme) v4 = Version('1.2.3.4', scheme=VariableDottedIntegerVersionScheme) v5 = Version('1.2.3.4.5', scheme=VariableDottedIntegerVersionScheme) assert (v1.bump()) assert (str(v1) == '2') assert (v2.bump()) assert (str(v2) == '1.3') assert (v3.bump()) assert (str(v3) == '1.2.4') assert (v4.bump()) assert (str(v4) == '1.2.3.5') assert (v5.bump()) assert (str(v5) == '1.2.3.4.6') assert (v3.bump(sequence=2)) assert (str(v3) == '1.2.5') assert (v3.bump(sequence=1)) assert (str(v3) == '1.3.0') assert (v3.bump(sequence=0)) assert (str(v3) == '2.0.0') assert (v3.bump(sequence=3)) assert (str(v3) == '2.0.0.1') assert (v1.bump(sequence=3)) assert (str(v1) == '2.0.0.1') assert (v2.bump(sequence=3)) assert (str(v2) == '1.3.0.1') assert (v3.bump(sequence=3)) assert (str(v3) == '2.0.0.2') assert (v4.bump(sequence=3)) assert (str(v4) == '1.2.3.6') assert (v5.bump(sequence=3)) assert (str(v5) == '1.2.3.5.0') assert (v5.bump(sequence=2)) assert (str(v5) == '1.2.4.0.0') assert (v5.bump(sequence=1)) assert (str(v5) == '1.3.0.0.0') assert (v5.bump(sequence=0)) assert (str(v5) == '2.0.0.0.0')
def upversion(version, major, minor, revision, dev, post, final): v = Version(version) if major: v.bump('major') if minor: v.bump('minor') if revision: v.bump('tiny') if post: v.bump('post') if dev: v.bump('dev') if final: v.parts = [v.parts[0], None, None, None, None] return str(v)
def test_simple4_version_errors(self): """garbage in check, bad versions""" raises(AttributeError, lambda: Version('1.2.3', scheme=Simple4VersionScheme)) raises(AttributeError, lambda: Version('1.2.3.', scheme=Simple4VersionScheme)) raises(AttributeError, lambda: Version('1.2.3.4.', scheme=Simple4VersionScheme)) raises(AttributeError, lambda: Version('1.2.3.4.5', scheme=Simple4VersionScheme))
def test_simple4_version(self): """roundtrip, parse then convert back to string""" assert (str(Version('1.2.3.4', scheme=Simple4VersionScheme)) == '1.2.3.4')
def test_pep440_version_errors(self): """garbage in check, bad versions""" raises(AttributeError, lambda: Version('1.', scheme=Pep440VersionScheme)) raises(AttributeError, lambda: Version('1-2', scheme=Pep440VersionScheme)) raises(AttributeError, lambda: Version('1_2', scheme=Pep440VersionScheme)) raises(AttributeError, lambda: Version('1.2.3.a4', scheme=Pep440VersionScheme)) raises(AttributeError, lambda: Version('1.2.3-a4', scheme=Pep440VersionScheme)) raises(AttributeError, lambda: Version('1.2.3_a4', scheme=Pep440VersionScheme)) raises(AttributeError, lambda: Version('1.2.3a4-foo5', scheme=Pep440VersionScheme)) raises(AttributeError, lambda: Version('1.2.3a4.foo5', scheme=Pep440VersionScheme)) # invalid local versions raises(AttributeError, lambda: Version('1.2.3.dev6+.1', scheme=Pep440VersionScheme)) raises(AttributeError, lambda: Version('1.2.3.dev6+1.', scheme=Pep440VersionScheme)) raises(AttributeError, lambda: Version('1.2.3.dev6+1(a)2', scheme=Pep440VersionScheme))
def test_pep440_version_comparisons(self): """test comparison operators on Pep440VersionScheme""" # load versions with increasing version numbers versions = [Version(vstr, scheme=Pep440VersionScheme) for vstr in [ '0.0.0.0', '0.0.0.1', '0.0.0.2', '0.0.0.9', '0.0.3.0', '0.0.3.4', '0.0.3.5', '0.0.4.0', '0.0.4.9', '0.1.0.0', '0.1.0.1', '0.1.10.0', '0.2.0.0', '0.2.0.11', '0.2.3.0', '0.10.0.0', '0.10.0.18', '0.10.22.0', '1.0.0.0', '1.0.0.1', '1.0.0.1+2', '1.0.0.1+3', '1.0.1.0a1', '1.0.1.0a2', '1.0.1.0b1', '1.0.1.0b2', '1.0.1.0c1', '1.0.1.0c2', '1.0.1.0rc1', '1.0.1.0rc2.dev1', '1.0.1.0rc2.dev1+a', '1.0.1.0rc2.dev1+b', '1.0.1.0rc2.dev2', '1.0.1.0rc2', '1.0.1.0rc2.post1.dev1', '1.0.1.0rc2.post1.dev1+1.2', '1.0.1.0rc2.post1.dev1+1.3', '1.0.1.0rc2.post1.dev2', '1.0.1.0rc2.post1', '1.0.1.0.dev1', '1.0.1.0.dev2', '1.0.1.0', '1.1.0.0', '1.10.0.0', '1.10.10.0', '1.10.10.10', '10.10.10.10', '999.999.999.999' ]] # check each adjacent version numbers for index, version in enumerate(versions[0:-1]): assert versions[index] < versions[index + 1], \ self.compare_to_str(op='<', v1=versions[index], v2=versions[index + 1]) assert versions[index + 1] > versions[index], \ self.compare_to_str(op='>', v1=versions[index + 1], v2=versions[index]) assert versions[index] <= versions[index + 1], \ self.compare_to_str(op='<=', v1=versions[index], v2=versions[index + 1]) assert versions[index + 1] >= versions[index], \ self.compare_to_str(op='>=', v1=versions[index + 1], v2=versions[index]) assert versions[index] != versions[index + 1], \ self.compare_to_str(op='!=', v1=versions[index], v2=versions[index + 1]) assert Version(str(versions[index]), scheme=Pep440VersionScheme) == versions[index], \ self.compare_to_str(op='==', v1=Version(str(versions[index])), v2=versions[index])
def _round_trip(version_str): """roundtrip, parse then convert back to string""" assert (str(Version(version_str, scheme=Pep440VersionScheme)) == version_str) assert (str(Version(version_str)) == version_str)
def test_pep440_bump(self): """version bumps""" v1 = Version('1.2.3a4.post5.dev6+7', scheme=Pep440VersionScheme) assert (v1.bump('local')) assert (str(v1) == '1.2.3a4.post5.dev6+8') assert (not v1.bump('local', 0)) # can't bump '+' assert (str(v1) == '1.2.3a4.post5.dev6+8') assert (v1.bump('local', 1)) assert (str(v1) == '1.2.3a4.post5.dev6+9') assert (v1.bump('dev')) assert (str(v1) == '1.2.3a4.post5.dev7') assert (not v1.bump('dev', 0)) # can't bump 'dev' assert (str(v1) == '1.2.3a4.post5.dev7') assert (v1.bump('dev', 1)) assert (str(v1) == '1.2.3a4.post5.dev8') assert (v1.bump('post')) assert (str(v1) == '1.2.3a4.post6') assert (not v1.bump('post', 0)) # can't bump 'post' assert (str(v1) == '1.2.3a4.post6') assert (v1.bump('post', 1)) assert (str(v1) == '1.2.3a4.post7') assert (v1.bump('pre')) assert (str(v1) == '1.2.3a5') assert (v1.bump('pre', 0)) assert (str(v1) == '1.2.3b1') assert (v1.bump('pre', 0)) assert (str(v1) == '1.2.3c1') assert (v1.bump('pre', 0)) assert (str(v1) == '1.2.3rc1') assert (not v1.bump('pre', 0)) assert (str(v1) == '1.2.3rc1') assert (v1.bump('release')) assert (str(v1) == '1.2.4') assert (v1.bump('release', 2)) assert (str(v1) == '1.2.5') assert (v1.bump('release', 1)) assert (str(v1) == '1.3.0') assert (v1.bump('release', 0)) assert (str(v1) == '2.0.0') v1 = Version('1.2.3a4.post5.dev6') assert (v1.bump('post')) assert (str(v1) == '1.2.3a4.post6') v1 = Version('1.2.3a4.post5.dev6') assert (v1.bump('pre')) assert (str(v1) == '1.2.3a5') v1 = Version('1.2.3a4.post5.dev6') assert (v1.bump('pre', 0)) assert (str(v1) == '1.2.3b1') v1 = Version('1.2.3a4.post5.dev6') assert (v1.bump('release')) assert (str(v1) == '1.2.4') v1 = Version('1.2.3a4.post5.dev6') assert (v1.bump('release', 2)) assert (str(v1) == '1.2.4') v1 = Version('1.2.3a4.post5.dev6') assert (v1.bump('release', 1)) assert (str(v1) == '1.3.0') v1 = Version('1.2.3a4.post5.dev6') assert (v1.bump('release', 0)) assert (str(v1) == '2.0.0')
def handle_register_or_upload(post_data, files, user, repository): """Process a `register` or `upload` comment issued via distutils. This method is called with the authenticated user. """ name = post_data.get('name') version = post_data.get('version') if settings.LOCALSHOP_VERSIONING_TYPE: scheme = get_versio_versioning_scheme( settings.LOCALSHOP_VERSIONING_TYPE) try: Version(version, scheme=scheme) except AttributeError: response = HttpResponseBadRequest( reason="Invalid version supplied '{!s}' for '{!s}' scheme.". format(version, settings.LOCALSHOP_VERSIONING_TYPE)) return response if not name or not version: logger.info("Missing name or version for package") return HttpResponseBadRequest('No name or version given') try: condition = Q() for search_name in get_search_names(name): condition |= Q(name__iexact=search_name) package = repository.packages.get(condition) # Error out when we try to override a mirror'ed package for now # not sure what the best thing is if not package.is_local: return HttpResponseBadRequest('%s is a pypi package!' % package.name) try: release = package.releases.get(version=version) except ObjectDoesNotExist: release = None except ObjectDoesNotExist: package = None release = None # Validate the data form = forms.ReleaseForm(post_data, instance=release) if not form.is_valid(): return HttpResponseBadRequest(reason=form.errors.values()[0][0]) if not package: pkg_form = forms.PackageForm(post_data, repository=repository) if not pkg_form.is_valid(): return HttpResponseBadRequest( reason=six.next(six.itervalues(pkg_form.errors))[0]) package = pkg_form.save() release = form.save(commit=False) release.package = package release.save() # If this is an upload action then process the uploaded file if files: filename = files['distribution']._name try: release_file = release.files.get(filename=filename) if settings.LOCALSHOP_RELEASE_OVERWRITE is False: message = 'That it already released, please bump version.' return HttpResponseBadRequest(message) except ObjectDoesNotExist: release_file = models.ReleaseFile(release=release, filename=filename) form_file = forms.ReleaseFileForm(post_data, files, instance=release_file) if not form_file.is_valid(): return HttpResponseBadRequest('ERRORS %s' % form_file.errors) release_file = form_file.save(commit=False) release_file.save() return HttpResponse()
from versio.version_scheme import Pep440VersionScheme # noinspection PyUnresolvedReferences from versio.version import Version # noinspection PyUnresolvedReferences from herring.herring_app import task, namespace from herringlib.safe_edit import safe_edit from herringlib.simple_logger import info, error, debug from herringlib.project_settings import Project __docformat__ = 'restructuredtext en' VERSION_REGEX = r'__version__\s*=\s*[\'\"](\S+)[\'\"]' Version.set_supported_version_schemes([Pep440VersionScheme]) def _file_spec(basename, project_package=None): """build the file spec in the project""" parts = [Project.herringfile_dir, project_package, basename] return os.path.join(*[f for f in parts if f is not None]) def get_version_from_file(project_package=None): """ get the version from VERSION.txt :param project_package: the package directory relative to the herringfile directory where the VERSION.txt may reside. """ try: