def get(strRepositoryPath): # The default version is 'unknown'. strProjectVersionVcs = 'unknown' strProjectVersionVcsLong = 'unknown' try: strGitId = porcelain.describe(strRepositoryPath, abbrev=12, long=True, dirty='+') tMatch = re.match(r'[0-9a-f]{12}\+?$', strGitId) if tMatch is not None: # This is a repository with no tags. # Use the raw SHA sum. strProjectVersionVcs = strGitId strProjectVersionVcsLong = strGitId else: tMatch = re.match(r'v(\d+(\.\d+)*)-(\d+)-g([0-9a-f]{12})$', strGitId) if tMatch is not None: ulRevsSinceTag = int(tMatch.group(3)) if ulRevsSinceTag == 0: # This is a repository which is exactly on a # tag. Use the tag name. strProjectVersionVcs = tMatch.group(1) strProjectVersionVcsLong = '%s-%s' % (tMatch.group(1), tMatch.group(4)) else: # This is a repository with commits after # the last tag. Use the checkin ID. strProjectVersionVcs = tMatch.group(4) strProjectVersionVcsLong = tMatch.group(4) else: tMatch = re.match(r'v(\d+(\.\d+)*)-(\d+)-g([0-9a-f]{12})\+?$', strGitId) if tMatch is not None: ulRevsSinceTag = int(tMatch.group(3)) if ulRevsSinceTag == 0: # This is a repository on a tag, but it has # modified files. Use the tag name and the '+'. strProjectVersionVcs = '%s+' % (tMatch.group(1)) strProjectVersionVcsLong = '%s-%s+' % (tMatch.group(1), tMatch.group(4)) else: # This is a repository with commits after the last tag # and modified files. Use the checkin ID and the '+'. strProjectVersionVcs = '%s+' % (tMatch.group(4)) strProjectVersionVcsLong = '%s+' % (tMatch.group(4)) else: # The description has an unknown format. strProjectVersionVcs = strGitId strProjectVersionVcsLong = strGitId strProjectVersionVcs = 'GIT%s' % strProjectVersionVcs strProjectVersionVcsLong = 'GIT%s' % strProjectVersionVcsLong except Exception as e: pass return strProjectVersionVcs, strProjectVersionVcsLong
import os import sys from setuptools import setup from subprocess import check_output pext_path = os.path.dirname(os.path.abspath(__file__)) pext_version_path = os.path.join(pext_path, 'pext', 'VERSION') with open(pext_version_path) as version_file: version = version_file.read().strip() try: from dulwich.porcelain import describe print("Updating version with dulwich") version = describe(pext_path) except Exception as e: print("Failed to determine version with dulwich, falling back to git describe: {}".format(e)) try: version = check_output(['git', 'describe'], cwd=pext_path).splitlines()[0] except Exception as e: print("Failed to determine version with git describe: {}".format(e)) if isinstance(version, bytes): version = version.decode() version = version.lstrip("v") with open(pext_version_path, "w") as version_file: version_file.write(version) with open(os.path.join(pext_path, 'requirements.txt')) as requirements_file:
def run(self, args): parser = optparse.OptionParser() options, args = parser.parse_args(args) print(porcelain.describe('.'))
def get(strRepositoryPath): # The default version is 'unknown'. strProjectVersionVcs = 'unknown' strProjectVersionVcsLong = 'unknown' try: strGitId = porcelain.describe( strRepositoryPath, abbrev=12, long=True, dirty='+' ) tMatch = re.match('[0-9a-f]{12}\+?$', strGitId) if tMatch is not None: # This is a repository with no tags. # Use the raw SHA sum. strProjectVersionVcs = strGitId strProjectVersionVcsLong = strGitId else: tMatch = re.match( 'v(\d+(\.\d+)*)-(\d+)-g([0-9a-f]{12})$', strGitId ) if tMatch is not None: ulRevsSinceTag = int(tMatch.group(3)) if ulRevsSinceTag == 0: # This is a repository which is exactly on a # tag. Use the tag name. strProjectVersionVcs = tMatch.group(1) strProjectVersionVcsLong = '%s-%s' % ( tMatch.group(1), tMatch.group(4) ) else: # This is a repository with commits after # the last tag. Use the checkin ID. strProjectVersionVcs = tMatch.group(4) strProjectVersionVcsLong = tMatch.group(4) else: tMatch = re.match( 'v(\d+(\.\d+)*)-(\d+)-g([0-9a-f]{12})\+?$', strGitId ) if tMatch is not None: ulRevsSinceTag = int(tMatch.group(3)) if ulRevsSinceTag == 0: # This is a repository on a tag, but it has # modified files. Use the tag name and the '+'. strProjectVersionVcs = '%s+' % (tMatch.group(1)) strProjectVersionVcsLong = '%s-%s+' % ( tMatch.group(1), tMatch.group(4) ) else: # This is a repository with commits after the last tag # and modified files. Use the checkin ID and the '+'. strProjectVersionVcs = '%s+' % (tMatch.group(4)) strProjectVersionVcsLong = '%s+' % (tMatch.group(4)) else: # The description has an unknown format. strProjectVersionVcs = strGitId strProjectVersionVcsLong = strGitId strProjectVersionVcs = 'GIT%s' % strProjectVersionVcs strProjectVersionVcsLong = 'GIT%s' % strProjectVersionVcsLong except Exception as e: pass return strProjectVersionVcs, strProjectVersionVcsLong
import os import sys from setuptools import setup with open(os.path.join('pext', 'VERSION')) as version_file: version_file_version = version_file.read().strip() try: from dulwich.porcelain import describe version = describe(os.path.dirname( os.path.abspath(__file__))).lstrip('v').replace('-', '+', 1).replace('-', '.') with open(os.path.join('pext', 'VERSION'), "w") as version_file: version_file.write(version) except Exception as e: print( "Could not determine version from git, falling back to version file: {}" .format(e)) version = version_file_version if sys.platform == 'linux': extra_options = dict( data_files=[('share/icons/hicolor/scalable/apps', ['pext/images/scalable/pext.svg']), ('share/icons/hicolor/48x48/apps', ['pext/images/48x48/pext.png']), ('share/icons/hicolor/128x128/apps', ['pext/images/128x128/pext.png'] ), ('share/applications', ['io.pext.pext.desktop'] ), ('share/metainfo', ['io.pext.pext.appdata.xml'])]) extra_deps = []
from ._version_lock import version # type: ignore # pylint: disable=unused-import except ImportError: # For development trees from os import environ from os.path import dirname, join try: from dulwich.porcelain import describe # type: ignore except ImportError: from subprocess import SubprocessError, run from warnings import warn def describe(repo): env = dict(environ) env['GIT_DIR'] = repo try: return (run(['git', 'describe'], capture_output=True, check=True, env=env, encoding='ascii').stdout.rstrip('\n')) except SubprocessError as e: # pragma: no cover warn("Could not determine dvrip version: {}".format(e)) return '0.0.0-0-unknown' if '_repo' not in globals(): # except for setup.py _repo = join(dirname(dirname(__file__)), '.git') _desc = describe(_repo).split('-', 3) version = ('{0}.dev{1}+{2}'.format( *_desc) if len(_desc) == 3 else _desc[0])