Loading setup.py +6 −88 Original line number Diff line number Diff line Loading @@ -22,99 +22,17 @@ module_name = 'pdo' # INITIAL_VERSION = "0.0.1" _REGEX = re.compile( r""" (?P<subdir>(?:0|[1-9A-Za-z-][0-9A-Za-z-]*)) - (?P<major>(?:0|[1-9][0-9]*)) \. (?P<minor>(?:0|[1-9][0-9]*)) \. (?P<patch>(?:0|[1-9][0-9]*)) (\-(?P<prerelease> (?:0|[1-9A-Za-z-][0-9A-Za-z-]*) (\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))* ))? (\+(?P<build> [0-9A-Za-z-]+ (\.[0-9A-Za-z-]+)* ))? $ """, re.VERBOSE) def git(*args): """Helper that invokes git""" ret = subprocess.run(["git"] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE) ret.git_args = args return ret def get_tags(subdir=None, head=None): """Get the tags from the current repo :param subdir: if provided, used as a filter :param head: if provided, used to limit what we see :returns: a list of tags """ args = ['tag'] if subdir is not None: args.append('-l') args.append('{}-*'.format(subdir)) if head is not None: args.append(head) ret = git(*args) return ret.stdout.decode('utf-8').splitlines() VERSION = "0.0.1" def parse_tag(tag): """Parse a tag string and return a subdir, semver pair :param tag: A tag string from git that has subdir-semver format :returns: A tuple with subdir and semver """ match = _REGEX.match(tag) if match is None: raise ValueError('%s is not valid SemVer string' % tag) parts = match.groupdict() return (parts['subdir'], tag.replace("{}-".format(parts['subdir']), "")) def index_history(taglist): """Get the tag history from the current repo The result gives you capability of figuring out order of things If the taglist was based on a single timeline of tags, then it will be keyed with '.' :param taglist: A multi-line text blob of multiple tags :returns: dictionary indexed with subdir names and lists of sorted versions as values """ def cmp_ver(ver1, ver2): return parse_version(ver1) < parse_version(ver2) i = defaultdict(list) for line in taglist: subdir, ver = parse_tag(line) i[subdir].append(ver) r = dict() for subdir, verlist in i.items(): r[subdir] = sorted(verlist, key=cmp_to_key(cmp_ver)) return r def get_version(module_name): def version(module_name): """ Retrieve the version """ taglist = get_tags(module_name, None) history = index_history(taglist).get(module_name, None) version = INITIAL_VERSION if history is not None: version = history[-1] # Propagate version to the module with open('{}/version.py'.format(module_name), 'w+') as f: f.write('__version__ = "{}"'.format(version)) return version f.write(f'__version__ = "{VERSION}"') return VERSION # Get the long description from the README file Loading @@ -141,7 +59,7 @@ setup( name=module_name, description=short_description, long_description=long_description, version=get_version(module_name), version=version(module_name), # The project's main homepage. url='https://code.ornl.gov/wg8/pdo', Loading Loading
setup.py +6 −88 Original line number Diff line number Diff line Loading @@ -22,99 +22,17 @@ module_name = 'pdo' # INITIAL_VERSION = "0.0.1" _REGEX = re.compile( r""" (?P<subdir>(?:0|[1-9A-Za-z-][0-9A-Za-z-]*)) - (?P<major>(?:0|[1-9][0-9]*)) \. (?P<minor>(?:0|[1-9][0-9]*)) \. (?P<patch>(?:0|[1-9][0-9]*)) (\-(?P<prerelease> (?:0|[1-9A-Za-z-][0-9A-Za-z-]*) (\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))* ))? (\+(?P<build> [0-9A-Za-z-]+ (\.[0-9A-Za-z-]+)* ))? $ """, re.VERBOSE) def git(*args): """Helper that invokes git""" ret = subprocess.run(["git"] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE) ret.git_args = args return ret def get_tags(subdir=None, head=None): """Get the tags from the current repo :param subdir: if provided, used as a filter :param head: if provided, used to limit what we see :returns: a list of tags """ args = ['tag'] if subdir is not None: args.append('-l') args.append('{}-*'.format(subdir)) if head is not None: args.append(head) ret = git(*args) return ret.stdout.decode('utf-8').splitlines() VERSION = "0.0.1" def parse_tag(tag): """Parse a tag string and return a subdir, semver pair :param tag: A tag string from git that has subdir-semver format :returns: A tuple with subdir and semver """ match = _REGEX.match(tag) if match is None: raise ValueError('%s is not valid SemVer string' % tag) parts = match.groupdict() return (parts['subdir'], tag.replace("{}-".format(parts['subdir']), "")) def index_history(taglist): """Get the tag history from the current repo The result gives you capability of figuring out order of things If the taglist was based on a single timeline of tags, then it will be keyed with '.' :param taglist: A multi-line text blob of multiple tags :returns: dictionary indexed with subdir names and lists of sorted versions as values """ def cmp_ver(ver1, ver2): return parse_version(ver1) < parse_version(ver2) i = defaultdict(list) for line in taglist: subdir, ver = parse_tag(line) i[subdir].append(ver) r = dict() for subdir, verlist in i.items(): r[subdir] = sorted(verlist, key=cmp_to_key(cmp_ver)) return r def get_version(module_name): def version(module_name): """ Retrieve the version """ taglist = get_tags(module_name, None) history = index_history(taglist).get(module_name, None) version = INITIAL_VERSION if history is not None: version = history[-1] # Propagate version to the module with open('{}/version.py'.format(module_name), 'w+') as f: f.write('__version__ = "{}"'.format(version)) return version f.write(f'__version__ = "{VERSION}"') return VERSION # Get the long description from the README file Loading @@ -141,7 +59,7 @@ setup( name=module_name, description=short_description, long_description=long_description, version=get_version(module_name), version=version(module_name), # The project's main homepage. url='https://code.ornl.gov/wg8/pdo', Loading