コード例 #1
0
ファイル: startup_test.py プロジェクト: kbase/catalog
    def test_startups(self):

        #Test normal startup, should work
        self.cUtil.setUp()
        catalog = Catalog(self.cUtil.getCatalogConfig())
        self.assertTrue(semantic_version.validate(catalog.version(self.cUtil.anonymous_ctx())[0]))

        #Test empty startup without DB version should work
        self.cUtil.setUpEmpty()
        catalog = Catalog(self.cUtil.getCatalogConfig())
        self.assertTrue(semantic_version.validate(catalog.version(self.cUtil.anonymous_ctx())[0]))
    
        #Test empty startup with several different valid versions should work
        self.cUtil.setUpEmpty(db_version=3)
        catalog = Catalog(self.cUtil.getCatalogConfig())
        self.assertTrue(semantic_version.validate(catalog.version(self.cUtil.anonymous_ctx())[0]))
        self.cUtil.setUpEmpty(db_version=4)
        catalog = Catalog(self.cUtil.getCatalogConfig())
        self.assertTrue(semantic_version.validate(catalog.version(self.cUtil.anonymous_ctx())[0]))

        #Startup with version that is too high should fail
        self.cUtil.setUpEmpty(db_version=2525)

        catalog = None
        with self.assertRaises(IOError) as e:
            catalog = Catalog(self.cUtil.getCatalogConfig())
        self.assertEqual(str(e.exception),
            'Incompatible DB versions.  Expecting DB V4, found DV V2525. You are probably running an old version of the service.  Start up failed.');
コード例 #2
0
ファイル: general.py プロジェクト: kinhvan017/debpackager
def get_new_version(extra_args):
    custom_version = extra_args.get('custom_version')
    if custom_version:
        if sv.validate(custom_version):
            return custom_version
        logger.error(
            'The given version format is invalid. value was: {}, please set '
            'version in format (major.minor.patch) like - 2.1.0'.format(
                custom_version))
        raise Exception(
            'version format is invalid. supplied version: {}'
                .format(custom_version))

    version = extra_args.get('pom').project.get('version')
    if not version:
        raise Exception(
            'Could not get a valid version, please check project.json')

    if not sv.validate(version):
        raise Exception(
            'version format is invalid. value is: {}'.format(version))

    version = sv.Version(version)

    return str(version)
コード例 #3
0
ファイル: repository.py プロジェクト: loles/solar-1
 def add_single_normal(self, name, source, overwrite=False):
     try:
         metadata = read_meta(source)
     except IOError as e:
         if e.errno == errno.ENOENT:
             raise RepositoryException(
                 "meta.yaml not found: %s" % e.filename)
         raise
     version = metadata['version']
     valid = semantic_version.validate(version)
     if not valid:
         raise RepositoryException("Invalid version "
                                   "%s for %s" % (version,
                                                  source))
     # TODO: (jnowak) sanitize version
     target_path = os.path.join(self.fpath, name, version)
     try:
         shutil.copytree(source, target_path, symlinks=True)
     except OSError as e:
         if e.errno != errno.EEXIST:
             raise
         if not overwrite:
             raise
         shutil.rmtree(target_path)
         shutil.copytree(source, target_path, symlinks=True)
コード例 #4
0
def getIndexAnnotations(report_path):

    annotations = report_info.get_report_annotations(report_path)

    set_annotations = {}
    OCPSupportedSet = False
    for annotation in annotations:
        if annotation == "charts.openshift.io/certifiedOpenShiftVersions":
            full_version = annotations[annotation]
            if full_version != "N/A" and semantic_version.validate(
                    full_version):
                ver = semantic_version.Version(full_version)
                set_annotations[
                    "charts.openshift.io/testedOpenShiftVersion"] = f"{ver.major}.{ver.minor}"
            else:
                set_annotations[
                    "charts.openshift.io/testedOpenShiftVersion"] = annotations[
                        annotation]
        else:
            if annotation == "charts.openshift.io/supportedOpenShiftVersions":
                OCPSupportedSet = True
            set_annotations[annotation] = annotations[annotation]

    if not OCPSupportedSet:
        chart = report_info.get_report_chart(report_path)
        OCPVersions = "N/A"
        if "kubeVersion" in chart and chart["kubeVersion"]:
            kubeVersion = chart["kubeVersion"]
            OCPVersions = getOCPVersions(kubeVersion)
        set_annotations[
            "charts.openshift.io/supportedOpenShiftVersions"] = OCPVersions

    return set_annotations
コード例 #5
0
ファイル: repository.py プロジェクト: openstack/solar
 def add_single_normal(self, name, source, overwrite=False):
     try:
         metadata = read_meta(source)
     except IOError as e:
         if e.errno == errno.ENOENT:
             raise RepositoryException(
                 "meta.yaml not found: %s" % e.filename)
         raise
     version = metadata['version']
     valid = semantic_version.validate(version)
     if not valid:
         raise RepositoryException("Invalid version "
                                   "%s for %s" % (version,
                                                  source))
     # TODO: (jnowak) sanitize version
     target_path = os.path.join(self.fpath, name, version)
     try:
         shutil.copytree(source, target_path, symlinks=True)
     except OSError as e:
         if e.errno != errno.EEXIST:
             raise
         if not overwrite:
             raise
         shutil.rmtree(target_path)
         shutil.copytree(source, target_path, symlinks=True)
コード例 #6
0
ファイル: release.py プロジェクト: scp-fs2open/nightlybuild
def main():
    script_state = ScriptState.load_from_file()

    if not semantic_version.validate(args.version):
        print("Specified version is not a valid version string!")
        return

    version = semantic_version.Version(args.version)
    if script_state is None:
        # An existing script state overrides the commandline argument
        if args.tag_name is not None:
            script_state = ReleaseState(version)
            script_state.state = ScriptState.STATE_TAG_PUSHED
            script_state.tag_name = args.tag_name
        else:
            if script_state is None:
                script_state = ReleaseState(version)
    else:
        if args.tag_name:
            print("Tag name ignored because there was a stored script state.")

        if not isinstance(script_state, ReleaseState):
            print("State object is not a nightly state! Delete 'state.pickle' or execute right script.")
            return

    # Always use the loaded values to allow changing the config while a script has a serialized state on disk
    script_state.config = config
    script_state.execute()
コード例 #7
0
def update_version(file, new_version):
    """
    Patches the file with new version
    :param file: file containing __version__ variable
    :param new_version: version to update the file with
    :return: True if file was changed, else False
    """
    with open(file, 'r') as input_file:
        content = input_file.read().splitlines()
        content_original = content.copy()

    changed = False
    for index, line in enumerate(content):
        if line.startswith('__version__'):
            pieces = line.split('=', maxsplit=1)
            if len(pieces) == 2:
                configuration.logger.info(f"Editing line with new version:\n{line}")
                old_version = (pieces[1].strip())[1:-1]  # strip whitespace and ' or "
                if validate(old_version):
                    configuration.logger.info(f"Replacing version {old_version} with {new_version}")
                    content[index] = f"{pieces[0].strip()} = '{new_version}'"
                    changed = True if content != content_original else False
                    break
                else:
                    configuration.logger.warning(f"Failed to validate version, aborting")
                    return False
    if changed:
        with open(file, 'w') as output:
            output.write('\n'.join(content) + '\n')
        configuration.logger.info('Version replaced.')
    return changed
コード例 #8
0
ファイル: utils.py プロジェクト: marusinm/release-bot
def process_version_from_title(title, latest_version):
    """
    checks for a valid version keyword, and if found
    returns the requested release version
    :param title: the pr/issue title to check keyword for
    :param latest_version: the current latest version with type Version()
    :return match: true if it is a valid version
    :return version: version string for requested latest release
    """
    match = False
    version = ''
    re_match = re.match(r'(.+) release$', title)
    if re_match:
        keyword = re_match[1].strip()
        if validate(keyword):
            match = True
            version = keyword
        elif keyword == "new major":
            match = True
            version = str(latest_version.next_major())
        elif keyword == "new minor":
            match = True
            version = str(latest_version.next_minor())
        elif keyword == "new patch":
            match = True
            version = str(latest_version.next_patch())
        else:
            logger.info(f"No valid version in {title!r}")
    return match, version
コード例 #9
0
ファイル: pynwb_utils.py プロジェクト: dandi/dandi-cli
def _sanitize_nwb_version(v, filename=None, log=None):
    """Helper to sanitize the value of nwb_version where possible

    Would log a warning if something detected to be fishy"""
    msg = f"File {filename}: " if filename else ""
    msg += f"nwb_version {v!r}"

    if log is None:
        log = lgr.warning
    elif not log:

        def log(v: str) -> str:  # does nothing
            return v

    if isinstance(v, str):
        if v.startswith("NWB-"):
            v_ = v[4:]
            # should be semver since 2.1.0
            if not (v_.startswith("1.") or v_.startswith("2.0")):
                log(f"{msg} starts with NWB- prefix, which is not part of the "
                    f"specification since NWB 2.1.0")
            v = v_
    elif isinstance(v, int):
        log(f"{msg} is an integer whenever it should be text")
        v = str(v)
    elif v:
        log(f"{msg} is not text which follows semver specification")

    if isinstance(v, str) and not semantic_version.validate(v):
        log(f"error: {msg} is not a proper semantic version. See http://semver.org"
            )

    return v
コード例 #10
0
 def _check_version_format(self, attribute, value):
     """Check that version is in semantic version format, and max length."""
     if not semantic_version.validate(value):
         self.value_error("Expecting 'version' to be in semantic version "
                          f"format, instead found '{value}'.")
     if len(value) > MAX_LENGTH_VERSION:
         self.value_error(
             f"'version' must not be greater than {MAX_LENGTH_VERSION} characters"
         )
コード例 #11
0
ファイル: querier.py プロジェクト: hitochan777/yadoc
 def sort_tags(tags: List[str], reverse: bool=True) -> List[str]:
     filtered_tags = filter(
         lambda tag: semantic_version.validate(tag), tags
     )
     return sorted(
         filtered_tags,
         key=lambda tag: semantic_version.Version(tag),
         reverse=reverse
     )
コード例 #12
0
ファイル: app.py プロジェクト: ngerakines/pyhelot
 def version_match(app, given_versions, way):
     app_versions = given_versions[app.name] if app.name in given_versions else []
     if validate(app.version):
         matching_versions = []
         s = Spec("%s%s" % (way, app.version))
         for version in app_versions:
             if s.match(Version(version)):
                 matching_versions.append(version)
         return matching_versions
     return app_versions
コード例 #13
0
    def __rcv(self):
        payload = self.__basepl("version")
        rcv = self._call_api(payload, "version")[0].decode("utf-8")
        if "error" in rcv:
            warnings.warn("Version information not available for this REDCap instance")
            return ""
        if semantic_version.validate(rcv):
            return semantic_version.Version(rcv)

        return rcv
コード例 #14
0
ファイル: repository.py プロジェクト: openstack/solar
 def _list_source_contents_from_multidir(cls, source):
     for pth in os.listdir(source):
         single_path = os.path.join(source, pth)
         if pth.endswith('.yaml'):
             pth = pth[:-5]
             yield RES_TYPE.Composer, pth, single_path
         elif os.path.exists(os.path.join(single_path, 'meta.yaml')):
             valid = semantic_version.validate(pth)
             if not valid:
                 name = pth
             else:
                 # if it was semver then single_path may look like
                 # /a/b/name/version
                 # and source may look like /a/b/name
                 # we can extract name from this path then
                 name = os.path.split(source)[-1]
             yield RES_TYPE.Normal, name, single_path
         else:
             maybe_cr = os.path.join(single_path,
                                     "{}.yaml".format(
                                         os.path.split(source)[-1]))
             if os.path.exists(maybe_cr):
                 name = os.path.split(source)[-1]
                 yield RES_TYPE.Composer, name, maybe_cr
                 continue
             if not os.path.isdir(single_path):
                 continue
             for single in os.listdir(single_path):
                 valid = semantic_version.validate(single)
                 if not valid:
                     fp = os.path.join(single_path, single)
                     raise RepositoryException(
                         "Unexpected repository content "
                         "structure: {} ""Expected directory "
                         "with version number".format(single_path))
                 else:
                     fp = os.path.join(single_path, single)
                     if os.path.exists(os.path.join(fp, 'meta.yaml')):
                         yield RES_TYPE.Normal, pth, fp
                     elif os.path.exists(
                             os.path.join(fp, '{}.yaml'.format(pth))):
                         cr = os.path.join(fp, '{}.yaml'.format(pth))
                         yield RES_TYPE.Composer, pth, cr
コード例 #15
0
ファイル: repository.py プロジェクト: loles/solar-1
 def _list_source_contents_from_multidir(cls, source):
     for pth in os.listdir(source):
         single_path = os.path.join(source, pth)
         if pth.endswith('.yaml'):
             pth = pth[:-5]
             yield RES_TYPE.Composer, pth, single_path
         elif os.path.exists(os.path.join(single_path, 'meta.yaml')):
             valid = semantic_version.validate(pth)
             if not valid:
                 name = pth
             else:
                 # if it was semver then single_path may look like
                 # /a/b/name/version
                 # and source may look like /a/b/name
                 # we can extract name from this path then
                 name = os.path.split(source)[-1]
             yield RES_TYPE.Normal, name, single_path
         else:
             maybe_cr = os.path.join(single_path,
                                     "{}.yaml".format(
                                         os.path.split(source)[-1]))
             if os.path.exists(maybe_cr):
                 name = os.path.split(source)[-1]
                 yield RES_TYPE.Composer, name, maybe_cr
                 continue
             if not os.path.isdir(single_path):
                 continue
             for single in os.listdir(single_path):
                 valid = semantic_version.validate(single)
                 if not valid:
                     fp = os.path.join(single_path, single)
                     raise RepositoryException(
                         "Unexpected repository content "
                         "structure: {} ""Expected directory "
                         "with version number".format(single_path))
                 else:
                     fp = os.path.join(single_path, single)
                     if os.path.exists(os.path.join(fp, 'meta.yaml')):
                         yield RES_TYPE.Normal, pth, fp
                     elif os.path.exists(
                             os.path.join(fp, '{}.yaml'.format(pth))):
                         cr = os.path.join(fp, '{}.yaml'.format(pth))
                         yield RES_TYPE.Composer, pth, cr
コード例 #16
0
ファイル: project.py プロジェクト: Yaroslav00/DockerProject
 def __rcv(self):
     p_l = self.__basepl('version')
     rcv = self._call_api(p_l, 'version')[0].decode('utf-8')
     if 'error' in rcv:
         warnings.warn('Version information not available for this REDCap instance')
         return ''
     if semantic_version.validate(rcv):
         return semantic_version.Version(rcv)
     else:
         return rcv
コード例 #17
0
ファイル: project.py プロジェクト: EBRL/PyCap
 def __rcv(self):
     p_l = self.__basepl('version')
     rcv = self._call_api(p_l, 'version')[0]
     if 'error' in rcv:
         warnings.warn('Version information not available for this REDCap instance')
         return ''
     if semantic_version.validate(rcv):
         return semantic_version.Version(rcv)
     else:
         return rcv
コード例 #18
0
def filter_semver_tags(tags: List[str]) -> List[str]:
    """
    Filter a list of tags to only the tags that follow a semantic versioning scheme.
    :param tags:  input tags
    :return:  those input tags that are semver
    """
    output = []
    for tag in tags:
        if validate(normalize(tag)):
            output.append(tag)
    return output
コード例 #19
0
ファイル: retag.py プロジェクト: matemaciek/test_all
def all_vers(repo):
    """
    @param repo: repository to check
    @return: all tagged versions in this repo
    """
    enter_repo(repo)
    tags = split_output("git", "tag", "-l")
    result = []
    for tag in tags:
        if semantic_version.validate(tag):
            result.append(semantic_version.Version(tag))
    return result
コード例 #20
0
def validate_versions(content_versions):
    valid_versions = []
    invalid_versions = []
    for version in content_versions:
        if not semantic_version.validate(version):
            log.warning('The version string "%s" is not valid, skipping.',
                        version)
            invalid_versions.append(version)
            continue
        valid_versions.append(version)

    return (valid_versions, invalid_versions)
コード例 #21
0
def parse_next_version(version: Text) -> Text:
    """Find the next version as a proper semantic version string."""
    if version == "major":
        return str(Version.coerce(get_current_version()).next_major())
    elif version == "minor":
        return str(Version.coerce(get_current_version()).next_minor())
    elif version == "patch":
        return str(Version.coerce(get_current_version()).next_patch())
    elif semantic_version.validate(version):
        return version
    else:
        raise Exception(
            f"Invalid version number '{cmdline_args.next_version}'.")
コード例 #22
0
 def find_open_release_issues(self):
     """
     Looks for opened release issues on github
     :return: True on found, False if not found
     """
     cursor = ''
     release_issues = {}
     while True:
         edges = self.github.walk_through_open_issues(start=cursor,
                                                      direction='before')
         if not edges:
             self.logger.debug(f'No more open issues found')
             break
         else:
             for edge in reversed(edges):
                 cursor = edge['cursor']
                 match = re.match(r'(.+) release',
                                  edge['node']['title'].lower())
                 if match:
                     version = match[1].strip()
                     if validate(version):
                         if edge['node']['authorAssociation'] in [
                                 'MEMBER', 'OWNER', 'COLLABORATOR'
                         ]:
                             release_issues[version] = edge['node']
                             self.logger.info(
                                 f'Found new release issue with version: {version}'
                             )
                         else:
                             self.logger.warning(
                                 f"Author association {edge['node']['authorAssociation']!r} "
                                 f"not in ['MEMBER', 'OWNER', 'COLLABORATOR']"
                             )
                     else:
                         self.logger.warning(
                             f"{version!r} is not a valid version")
     if len(release_issues) > 1:
         msg = f'Multiple release issues are open {release_issues}, please reduce them to one'
         self.logger.error(msg)
         return False
     if len(release_issues) == 1:
         for version, node in release_issues.items():
             self.new_pr = {
                 'version': version,
                 'issue_id': node['id'],
                 'issue_number': node['number'],
                 'labels': self.new_release.get('labels')
             }
             return True
     else:
         return False
コード例 #23
0
 def version(self, new_version):
     new_version = str(new_version)
     is_semantic = semantic_version.validate(new_version)
     if is_semantic:
         v = semantic_version.Version(new_version)
     else:
         try:
             v = semantic_version.Version(new_version, partial=True)
         except ValueError:
             raise ValueError(
                 f"'{new_version}'' is not a valid partial semantic version."
             )
         v = semantic_version.Version.coerce(str(v))
     self._version = str(v)
コード例 #24
0
def is_valid_proposed_version(release_context, proposed_version):
    valid_version = False
    sv = None
    if semantic_version.validate(proposed_version):
        sv = semantic_version.Version(proposed_version)
        if release_context.is_snapshot_release():
            valid_version = sv.prerelease and sv.prerelease[0].upper() == SNAPSHOT
        else:
            valid_version = not sv.prerelease

    if valid_version:
        return sv
    else:
        return None
コード例 #25
0
def fracFitSemVer(repo, branch):

    count_ok = 0
    count_total = 0
    
    if "" in branch:
        countTotal = 0
    else:
        for line in repo.git.log('--oneline').split('\n'):
            if '.' in line:
                if "not" in branch:
                    tmpBranch = branch.copy()
                    tmpBranch.remove("not")
                    if "remote-tracking" not in line.lower() and not any(notRel in line.lower() for notRel in tmpBranch):
                        count_total += 1
                        #print(line)
                        version = [vers for vers in re.split('/| |-', line) if '.' in vers][-1]
                        if version[0].isdigit():
                            count_total += 1
                            #print(version)
                            if sv.validate(version):
                                count_ok += 1
                else:
                    if "remote-tracking" not in line.lower() and any(rel in line.lower() for rel in branch):
                        count_total += 1
                        #print(line)
                        version = [vers for vers in re.split('/| |-', line) if '.' in vers][-1]
                        if version[0].isdigit():
                            count_total += 1
                            #print(version)
                            if sv.validate(version):
                                count_ok += 1
    
    if count_total == 0:
        return 0
    else:
        return count_ok / count_total
コード例 #26
0
def is_valid_proposed_version(release_context, proposed_version):
    validations = []
    sv = None
    if semantic_version.validate(proposed_version):
        sv = semantic_version.Version(proposed_version)
        if release_context.is_snapshot_release():
            validations.append(sv.prerelease
                               and sv.prerelease[0].upper() == SNAPSHOT)
        else:
            validations.append(not sv.prerelease)

    if all(v for v in validations):
        return sv
    else:
        None
コード例 #27
0
def update_version_number(update_level='patch'):
    """Update version number

    Returns a semantic_version object"""

    """Find current version"""
    temp_file = version_file().parent / ("~" + version_file().name)
    with open(str(temp_file), 'w') as g:
        with open(str(version_file()), 'r') as f:
            for line in f:
                version_matches = bare_version_re.match(line)
                if version_matches:
                    bare_version_str = version_matches.groups(0)[0]
                    if semantic_version.validate(bare_version_str):
                        current_version = Version(bare_version_str)
                        print("{}Current version is {}".format(" "*4, current_version))
                    else:
                        current_version = Version.coerce(bare_version_str)
                        if not text.query_yes_quit("{}I think the version is {}. Use it?".format(" "*4, current_version), default="yes"):
                            exit(colorama.Fore.RED + 'Please set an initial version number to continue')

                    """Determine new version number"""
                    if update_level is 'major':
                        current_version = current_version.next_major()
                    elif update_level is 'minor':
                        current_version = current_version.next_minor()
                    elif update_level is 'patch':
                        current_version = current_version.next_patch()
                    elif update_level is 'prerelease':
                        if not current_version.prerelease:
                            current_version = current_version.next_patch()
                            current_version.prerelease = ('dev', )
                    elif update_level is None:
                        # don't update version
                        pass
                    else:
                        exit(colorama.Fore.RED + 'Cannot update version in {} mode'.format(update_level))

                    print("{}New version is     {}".format(" "*4, current_version))

                    """Update version number"""
                    line = '__version__ = "{}"\n'.format(current_version)
                print(line, file=g, end="")
        #print('', file=g)  # add a blank line at the end of the file
    shutil.copyfile(str(temp_file), str(version_file()))
    os.remove(str(temp_file))
    return(current_version)
コード例 #28
0
ファイル: tasks.py プロジェクト: MinchinWeb/colourettu
def update_version_number(update_level='patch'):
    """Update version number

    Returns a semantic_version object"""

    """Find current version"""
    temp_file = version_file().parent / ("~" + version_file().name)
    with open(str(temp_file), 'w') as g:
        with open(str(version_file()), 'r') as f:
            for line in f:
                version_matches = bare_version_re.match(line)
                if version_matches:
                    bare_version_str = version_matches.groups(0)[0]
                    if semantic_version.validate(bare_version_str):
                        current_version = Version(bare_version_str)
                        print("{}Current version is {}".format(" "*4, current_version))
                    else:
                        current_version = Version.coerce(bare_version_str)
                        if not text.query_yes_quit("{}I think the version is {}. Use it?".format(" "*4, current_version), default="yes"):
                            exit(colorama.Fore.RED + 'Please set an initial version number to continue')

                    """Determine new version number"""
                    if update_level is 'major':
                        current_version = current_version.next_major()
                    elif update_level is 'minor':
                        current_version = current_version.next_minor()
                    elif update_level is 'patch':
                        current_version = current_version.next_patch()
                    elif update_level is 'prerelease':
                        if not current_version.prerelease:
                            current_version = current_version.next_patch()
                            current_version.prerelease = ('dev', )
                    elif update_level is None:
                        # don't update version
                        pass
                    else:
                        exit(colorama.Fore.RED + 'Cannot update version in {} mode'.format(update_level))

                    print("{}New version is     {}".format(" "*4, current_version))

                    """Update version number"""
                    line = '__version__ = "{}"\n'.format(current_version)
                print(line, file=g, end="")
        #print('', file=g)  # add a blank line at the end of the file
    shutil.copyfile(str(temp_file), str(version_file()))
    os.remove(str(temp_file))
    return(current_version)
コード例 #29
0
 def check_for_new_pull_request_since_latest_pypi(self, cursor):
     while True:
         response = self.github.walk_through_closed_prs(cursor, which="first")
         if not response['data']['repository']['pullRequests']['edges']:
             self.logger.debug('No newer release PR found')
             self.new_release = {}
             return False
         for edge in response['data']['repository']['pullRequests']['edges']:
             cursor = edge['cursor']
             match = re.match(r'(.+) release', edge['node']['title'].lower())
             if match and validate(match[1]):
                 merge_commit = edge['node']['mergeCommit']
                 self.logger.debug(f'Found newer PR with version {match[1]}')
                 self.new_release = {'version': match[1],
                                     'commitish': merge_commit['oid'],
                                     'author_name': merge_commit['author']['name'],
                                     'author_email': merge_commit['author']['email']}
                 return True
コード例 #30
0
ファイル: version.py プロジェクト: dalepotter/pyIATI
    def _is_semver(self, version_string):
        """Determine whether a version string is in a SemVer format and is a permitted value.

        Args:
            version_string (string): The string for which to check conformance.

        Returns:
            bool: True if the provided string is a permitted in SemVer-format version number. False if not.

        """
        is_semver_format = semantic_version.validate(version_string)
        try:
            is_permitted_value = semantic_version.Version(
                version_string).major != 0
        except ValueError:
            return False

        return is_semver_format and is_permitted_value
コード例 #31
0
ファイル: release.py プロジェクト: ereichert/vors
def is_valid_proposed_version(release_context, proposed_version):
    validations = []
    sv = None
    if semantic_version.validate(proposed_version):
        sv = semantic_version.Version(proposed_version)
        if release_context.is_snapshot_release():
            validations.append(
                sv.prerelease
                and sv.prerelease[0].upper() == SNAPSHOT
            )
        else:
            validations.append(
                not sv.prerelease
            )

    if all(v for v in validations):
        return sv
    else:
        None
コード例 #32
0
ファイル: schema.py プロジェクト: ansible/galaxy-importer
    def _check_version_format(self, attribute, value):
        """Check that version is in semantic version format, and max length."""
        if not semantic_version.validate(value):
            self.value_error(
                f"Expecting 'version' to be in semantic version format, instead found '{value}'."
            )
        if len(value) > MAX_LENGTH_VERSION:
            self.value_error(
                f"'version' must not be greater than {MAX_LENGTH_VERSION} characters"
            )

        config_data = config.ConfigFile.load()
        cfg = config.Config(config_data=config_data)
        if cfg.require_v1_or_greater:
            if semantic_version.Version(value) < semantic_version.Version(
                    "1.0.0"):
                self.value_error(
                    "Config is enabled that requires version to be 1.0.0 or greater."
                )
コード例 #33
0
ファイル: render_package.json.py プロジェクト: xgqt/mydot
def main():
    """The main function."""

    parser = argparse.ArgumentParser(
        description="%(prog)s - generate package.json from package.json.j2",
        epilog='''Copyright (c) 2019-2022, Maciej Barć <*****@*****.**>
    Licensed under the GNU GPL v3 License''')
    parser.add_argument(
        "version",
        type=str,
        help="version string to use, following 'semver', ie.: 9.9.9")
    args = parser.parse_args()
    v = args.version

    if validate(v):
        render_package_json(v)
    else:
        print("[ERROR]: Given version sting {} is incorrect.".format(v))
        print("         Please follow the semver specification.")
        EXIT(1)
コード例 #34
0
ファイル: repository.py プロジェクト: openstack/solar
 def _list_source_contents(cls, source):
     if source.endswith('.yaml'):
         # single CR
         pth = os.path.split(source)[-1][:-5]
         return ((RES_TYPE.Composer, pth, source), )
     elif os.path.isdir(source):
         meta_path = os.path.join(source, 'meta.yaml')
         if os.path.exists(meta_path):
             # single normal
             pth = os.path.split(source)[-1]
             valid = semantic_version.validate(pth)
             if not valid:
                 name = pth
             else:
                 # if it was semver then single_path may look like
                 # /a/b/name/version
                 # and source may look like /a/b/name
                 # we can extract name from this path then
                 name = source.split(os.path.sep)[-2]
             return ((RES_TYPE.Normal, name, source), )
         return tuple(cls._list_source_contents_from_multidir(source))
コード例 #35
0
ファイル: python.py プロジェクト: mozilla/mozilla-depends
 def match(self, package_name, version):
     if not validate(version):
         logger.debug(f"Package {package_name} has partial semver version {version}")
     try:
         v = Version(version, partial=True)
     except ValueError:
         logger.error(f"Invalid version {version}. Ignoring packet")
         return
     if package_name in self.db:
         for vuln in self.db[package_name]:
             for semver_spec in vuln["specs"]:
                 try:
                     if v in Spec(semver_spec):
                         yield vuln
                         break
                 except ValueError:
                     # Fallback for broken semver specs in deb: try raw comparison
                     logger.warning(f"Broken semver spec for {package_name} in SafetyDB: {semver_spec}")
                     if version == semver_spec:
                         yield vuln
                         break
コード例 #36
0
ファイル: repository.py プロジェクト: loles/solar-1
 def _list_source_contents(cls, source):
     if source.endswith('.yaml'):
         # single CR
         pth = os.path.split(source)[-1][:-5]
         return ((RES_TYPE.Composer, pth, source), )
     elif os.path.isdir(source):
         meta_path = os.path.join(source, 'meta.yaml')
         if os.path.exists(meta_path):
             # single normal
             pth = os.path.split(source)[-1]
             valid = semantic_version.validate(pth)
             if not valid:
                 name = pth
             else:
                 # if it was semver then single_path may look like
                 # /a/b/name/version
                 # and source may look like /a/b/name
                 # we can extract name from this path then
                 name = source.split(os.path.sep)[-2]
             return ((RES_TYPE.Normal, name, source), )
         return tuple(cls._list_source_contents_from_multidir(source))
コード例 #37
0
    def export_version(self) -> Optional[semantic_version.Version]:
        """
        Get the REDCap version

        Returns:
            REDCap version running on the url provided

        Examples:
            >>> import semantic_version
            >>> redcap_version = proj.export_version()
            >>> assert redcap_version >= semantic_version.Version("12.0.1")
        """
        payload = self._initialize_payload("version")
        resp = None

        redcap_version = self._call_api(payload, return_type="str")

        if semantic_version.validate(redcap_version):
            resp = semantic_version.Version(redcap_version)

        return resp
コード例 #38
0
def main(args):
    input_file = open(args.file, 'r')
    try:
        constraint = hcl.load(input_file)['terraform']['required_version']
    except:
        # Using the latest version
        constraint = '>= 0.1.0'
    token = get_token(args.username, args.password)
    all_versions = sorted(get_versions(args.repository, token),
                          key=LooseVersion)
    # Get the required versions range
    valid_versions = semantic_version.SimpleSpec(format_constraint(constraint))
    while all_versions:
        match = all_versions.pop()
        if semantic_version.validate(match) \
                and not(semantic_version.Version(match).prerelease) \
                and semantic_version.Version(match) in valid_versions:
            # Valid x.y.z & release & in the required versions range
            break
        match = 'No match'
    print(match)
コード例 #39
0
ファイル: dashv.py プロジェクト: SalilGokhale/dashv
 def _get_semantic_version(tag):
     three_numbered_version = re.search("(\\d+)[._](\\d+)[._](\\d+)(.*)", tag)
     two_numbered_version = re.search("(\\d+)[._](\\d+)(.*)", tag)
     if semantic_version.validate(tag):
         semver = semantic_version.Version(tag)
     elif three_numbered_version:
         if len(three_numbered_version.groups()) == 4:
             major, minor, patch, trailing = three_numbered_version.groups()
             semver = semantic_version.Version.coerce("{}.{}.{}{}".format(major, minor, patch, trailing))
         else:
             major, minor, patch = three_numbered_version.groups()
             semver = semantic_version.Version.coerce("{}.{}.{}".format(major, minor, patch))
     elif two_numbered_version:
         if len(two_numbered_version.groups()) == 3:
             major, minor, trailing = two_numbered_version.groups()
             semver = semantic_version.Version.coerce("{}.{}.0{}".format(major, minor, trailing))
         else:
             major, minor = two_numbered_version.groups()
             semver = semantic_version.Version.coerce("{}.{}.0".format(major, minor))
     else:
         raise SemanticVersionException("Was not able to parse {} as a semantic versioned tag".format(tag))
     return semver
コード例 #40
0
ファイル: unpacker.py プロジェクト: rafie/RAMP
def _validate_metadata(metadata, module):
    """
    Checks metadata isn't missing any required fields
    metadata - dictionary
    module - path to module file
    """

    for field in module_metadata.FIELDS:
        if not field in metadata:
            raise UnpackerPackageError("module did not pass sanity validation", reason="Missing mandatory field [{}]".format(field))

    # Empty module name
    if metadata["module_name"] == "":
        raise UnpackerPackageError("module did not pass sanity validation", reason="Empty module name")

    # Empty module file name
    if metadata["module_file"] == "":
        raise UnpackerPackageError("module did not pass sanity validation", reason="Empty module file name")

    # Architecture must 64 bits
    if metadata["architecture"] != "x86_64":
        raise UnpackerPackageError("module did not pass sanity validation", reason="Architecture must 64 bits")

    # Missing version
    if not semantic_version.validate(metadata["semantic_version"]):
        raise UnpackerPackageError("module did not pass sanity validation", reason="Invalid semantic version")

    if StrictVersion(metadata["min_redis_pack_version"]) < StrictVersion(module_metadata.MIN_REDIS_PACK_VERSION):
        raise UnpackerPackageError("module did not pass sanity validation", reason="Min redis pack version is too low")

    # wrong signature
    # TODO: this check should be deffered to a later stage
    # As _sha256_checksum will read entire module file
    # And we're unable to seek it back to its starting point.
    # if _sha256_checksum(module) != metadata["sha256"]:
    #     raise UnpackerPackageError("module did not pass sanity validation", reason="Wrong signature")

    return True
コード例 #41
0
ファイル: settings.py プロジェクト: Codaisseur/deis
except ImportError:
    pass

# have confd_settings within container execution override all others
# including local_settings (which may end up in the container)
if os.path.exists('/templates/confd_settings.py'):
    sys.path.append('/templates')
    from confd_settings import *  # noqa

# Disable swap when mem limits are set, unless Docker is too old
DISABLE_SWAP = '--memory-swap=-1'
try:
    version = 'unknown'
    from registry.dockerclient import DockerClient
    version = DockerClient().client.version().get('Version')
    if not semver.validate(version) or semver.Version(version) < semver.Version('1.5.0'):
        DISABLE_SWAP = ''
except:
    print("Not disabling --memory-swap for Docker version {}".format(version))

# LDAP Backend Configuration
# Should be always after the confd_settings import.
LDAP_USER_SEARCH = LDAPSearch(
    base_dn=USER_BASEDN,
    scope=ldap.SCOPE_SUBTREE,
    filterstr="(%s=%%(user)s)" % USER_FILTER
)
LDAP_GROUP_SEARCH = LDAPSearch(
    base_dn=GROUP_BASEDN,
    scope=ldap.SCOPE_SUBTREE,
    filterstr="(%s=%s)" % (GROUP_FILTER, GROUP_TYPE)
コード例 #42
0
def test_valid_version():
    assert semantic_version.validate(python_template.__version__)
コード例 #43
0
    def run(self, terms, variables=None, **kwargs):

        bump = kwargs.get('bump', '').lower()
        if not isinstance(bump, string_types) or bump not in [
                'patch', 'minor', 'major', ''
        ]:
            raise AnsibleError(
                '"bump" must be a string and one of "patch", "minor" or "major", not %s'
                % bump)

        want = kwargs.get('want', 'str').lower()
        if not isinstance(want, string_types) or want not in [
                'str', 'dict', 'list'
        ]:
            raise AnsibleError(
                '"want" must be a string and one of "str", "dict" or "list", not %s'
                % want)

        ret = []
        for term in terms:
            display.debug("Repo path: %s" % term)
            repo = Repo(term)

            display.vvvv(u"Git semver lookup using %s as repo" % repo)
            try:
                if repo:
                    # gheck this is a git repo
                    assert not repo.bare

                    # get branch name
                    branch = repo.git.branch('--show-current')

                    # get tag
                    try:
                        # get tag
                        v = repo.git.describe('--tags', '--abbrev=0')
                        # set tag as rev
                        rev = v
                    except git.GitCommandError as e:
                        # initialize semantic version if error code 128
                        if e.status == 128 and ('No names' in e.stderr
                                                or 'No tags' in e.stderr):
                            # set default initial semver
                            v = '0.0.1' + '-SNAPSHOT-' + \
                                os.getenv('BRANCH_NAME', branch) + \
                                '-' + os.getenv('BUILD_ID', repo.git.describe('--always'))
                            # set HEAD as rev
                            rev = 'HEAD'
                        else:
                            raise

                    # set commit
                    commit = repo.git.rev_parse(rev)

                    # check v prefix
                    if v.startswith('v'):
                        v = v[1:]

                    # Validate semver
                    if not semantic_version.validate(v):
                        raise AnsibleError(
                            'Tag "%s" is not a proper semantic version' % v)

                    # bump
                    v = semantic_version.Version(v)
                    if bump:
                        v = getattr(v, 'next_' + bump)()
                        commit = None

                    # return dict
                    if want == 'dict':
                        v = {
                            "full": str(v),
                            "major": v.major,
                            "minor": v.minor,
                            "patch": v.patch,
                            "prerelease": '.'.join(v.prerelease),
                            "build": '.'.join(v.build),
                            "branch": branch,
                            "commit": commit
                        }

                    # return list
                    if want == 'list':
                        v = [str(v)] + list(v) + [branch] + [commit]

                    # return str
                    if want == 'str':
                        v = str(v)

                    ret.append(v)
                else:
                    raise AnsibleParserError()
            except AnsibleParserError:
                raise AnsibleError("could not get version in lookup: %s" %
                                   term)

        return ret
コード例 #44
0
# Supports:
#  default      - Docker generated hostname
#  application  - Hostname based on application unit name (i.e. my-application.v2.web.1)
#  server       - Hostname based on CoreOS server hostname
UNIT_HOSTNAME = 'default'

# Create a file named "local_settings.py" to contain sensitive settings data
# such as database configuration, admin email, or passwords and keys. It
# should also be used for any settings which differ between development
# and production.
# The local_settings.py file should *not* be checked in to version control.
try:
    from .local_settings import *  # noqa
except ImportError:
    pass


# have confd_settings within container execution override all others
# including local_settings (which may end up in the container)
if os.path.exists('/templates/confd_settings.py'):
    sys.path.append('/templates')
    from confd_settings import *  # noqa

DOCKER_VERSION = os.environ.get('DOCKER_VERSION', '1.4.1')

DISABLE_SWAP = ""

if (semantic_version.validate(DOCKER_VERSION) and
        semantic_version.Version(DOCKER_VERSION) >= semantic_version.Version('1.5.0')):
    DISABLE_SWAP = "--memory-swap=-1"
コード例 #45
0
ファイル: registrar.py プロジェクト: kbase/catalog
    def sanity_checks_and_parse(self, basedir, git_commit_hash):
        # check that files exist
        yaml_filename = 'kbase.yaml'
        if not os.path.isfile(os.path.join(basedir,'kbase.yaml')) :
            if not os.path.isfile(os.path.join(basedir,'kbase.yml')):
                raise ValueError('kbase.yaml file does not exist in repo, but is required!')
            else:
                yaml_filename = 'kbase.yml'
        # parse some stuff, and check for things

        with codecs.open(os.path.join(basedir,yaml_filename), 'r', "utf-8", errors='ignore') as kb_yaml_file:
            kb_yaml_string = kb_yaml_file.read()
        self.kb_yaml = yaml.load(kb_yaml_string)
        self.log('=====kbase.yaml parse:')
        self.log(pprint.pformat(self.kb_yaml))
        self.log('=====end kbase.yaml')

        module_name = self.get_required_field_as_string(self.kb_yaml,'module-name').strip()
        module_description = self.get_required_field_as_string(self.kb_yaml,'module-description').strip()
        version = self.get_required_field_as_string(self.kb_yaml,'module-version').strip()

        # must be a semantic version
        if not semantic_version.validate(version):
            raise ValueError('Invalid version string in kbase.yaml - must be in semantic version format.  See http://semver.org')

        service_language = self.get_required_field_as_string(self.kb_yaml,'service-language').strip()
        owners = self.get_required_field_as_list(self.kb_yaml,'owners')

        service_config = self.get_optional_field_as_dict(self.kb_yaml, 'service-config')
        if service_config:
            # validate service_config parameters
            if 'dynamic-service' in service_config:
                if not type(service_config['dynamic-service']) == type(True):
                    raise ValueError('Invalid service-config in kbase.yaml - "dynamic-service" property must be a boolean "true" or "false".') 

        # module_name must match what exists (unless it is not yet defined)
        if 'module_name' in self.module_details:
            if self.module_details['module_name'] != module_name:
                raise ValueError('kbase.yaml file module_name field has changed since last version! ' +
                                    'Module names are permanent- if this is a problem, contact a kbase admin.')
        else:
            # This must be the first registration, so the module must not exist yet
            self.check_that_module_name_is_valid(module_name);

        # associate the module_name with the log file for easier searching (if we fail sooner, then the module name
        # cannot be used to lookup this log)
        self.db.set_build_log_module_name(self.registration_id, module_name)

        # you can't remove yourself from the owners list, or register something that you are not an owner of
        if self.username not in owners and self.is_admin is False:
            raise ValueError('Your kbase username ('+self.username+') must be in the owners list in the kbase.yaml file.')

        # OPTIONAL TODO: check if all the users are on the owners list?  not necessarily required, because we
        # do a check during registration of the person who started the registration...

        # TODO: check for directory structure, method spec format, documentation, version
        self.validate_method_specs(basedir)

        # initial validation of the local function specifications
        lf_report = self.local_function_reader.parse_and_basic_validation(basedir, self.module_details, module_name, version, git_commit_hash)
        self.log(self.local_function_reader.report_to_string_for_log(lf_report))

        if len(lf_report['functions_errored']) > 0:
            raise ValueError('Errors exist in local function specifications.')

        # return the parse so we can figure things out later
        return self.kb_yaml
コード例 #46
0
ファイル: requirement.py プロジェクト: awsum/pypiup
 def valid_semver(self):
     valid_current = semantic_version.validate(self.current_version)
     valid_latest = semantic_version.validate(self.latest_version)
     return valid_current and valid_latest
コード例 #47
0
ファイル: check.py プロジェクト: aureooms/sak
 def OldSemverVersionTagNotValidException(version, src):
     if not semantic_version.validate(version):
         raise lib.error.OldSemverVersionTagNotValidException(version, src)