Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions autover/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def fetch(self):
self._commit = self._expected_commit
return self

output = self._output_from_file()
if output is not None:
self._update_from_vcs(output)
return self

# Only git right now but easily extended to SVN, Mercurial, etc.
for cmd in ['git', 'git.cmd', 'git.exe']:
try:
Expand Down Expand Up @@ -272,6 +277,7 @@ def git_fetch(self, cmd='git', as_string=False):
cwd=os.path.dirname(self.fpath))
if as_string: return output
except Exception as e1:
print('Git describe exception: %s' % str(e1))
try:
output = self._output_from_file()
if output is not None:
Expand Down Expand Up @@ -483,7 +489,7 @@ def extract_directory_tag(cls, setup_path, reponame):


@classmethod
def setup_version(cls, setup_path, reponame, archive_commit=None,
def record_version(cls, setup_path, reponame, archive_commit=None,
pkgname=None, dirty='report'):
info = {}
git_describe = None
Expand Down Expand Up @@ -524,11 +530,22 @@ def setup_version(cls, setup_path, reponame, archive_commit=None,
except:
print('Error in setup_version: could not write .version file.')

return info['version_string']
@classmethod
def setup_version(cls, setup_path, reponame, archive_commit=None,
pkgname=None, dirty='report', record_version=False):
if record_version:
cls.record_version(setup_path, reponame, archive_commit=archive_commit,
pkgname=pkgname, dirty=dirty)
return Version.get_setup_version(setup_path, reponame,
describe=False,
dirty=dirty,
pkgname=pkgname,
archive_commit=archive_commit)



def get_setup_version(location, reponame, pkgname=None, archive_commit=None):
def get_setup_version(location, reponame, pkgname=None, archive_commit=None,
record_version=False):
"""Helper for use in setup.py to get the current version from either
git describe or the .version file (if available).

Expand All @@ -548,7 +565,9 @@ def get_setup_version(location, reponame, pkgname=None, archive_commit=None):
pkgname = reponame if pkgname is None else pkgname
if archive_commit is None:
warnings.warn("No archive commit available; git archives will not contain version information")
return Version.setup_version(os.path.dirname(os.path.abspath(location)),reponame,pkgname=pkgname,archive_commit=archive_commit)
return Version.setup_version(os.path.dirname(os.path.abspath(location)),reponame,
pkgname=pkgname, archive_commit=archive_commit,
record_version=record_version)


def get_setupcfg_version():
Expand Down
24 changes: 24 additions & 0 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,36 @@ def task_original_script():
env2 = os.environ.copy()
env2['PYTHONPATH'] = os.getcwd() # TODO win

def record_pkg_bundle_version(example,example_pkgname):
pkgname = _x(example,example_pkgname)
return ("""python -c 'import os; from version import Version;"""
+ ('print("Writing .version for %s in %s");' % (example_pkgname, example))
+ """Version.record_version(os.getcwd(), """ + "\"%s\"" % pkgname + """, archive_commit="$Format:%%h$")'""")

def record_pkg_skip(example,example_pkgname):
return """python -c 'print(\"Not recording .version\")'"""

def remove_version_file(example,example_pkgname):
pkgname = _x(example,example_pkgname)
return (("rm ./%s/.version" % pkgname)
if pkgname in ['pkg_bundle', 'PkgBundle']
else ("echo 'Skipping removal of .version for %s in %s'"
% (example_pkgname, example)))


record_mapping={'pkg_bundle':record_pkg_bundle_version,
'PkgBundle': record_pkg_bundle_version}
return {
'getargs': {'git_version': ('get_git_version','git_version')},
'params': [example,example_pkgname],
'actions':[
# 0. Create .version file for tox
action.CmdAction(lambda example,example_pkgname: record_mapping.get(_x(example,example_pkgname),record_pkg_skip)(example,example_pkgname),
env=env1),
# 1. verify package generation & installation
action.CmdAction('tox -e py -- %(git_version)s',env=env1),
# 2. Remove .version file
action.CmdAction(remove_version_file, env=env1),

# dev install, then...
# TODO: need prerelease param just now; remove pre & index urls after release
Expand Down
27 changes: 23 additions & 4 deletions examples/PkgBundle/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def fetch(self):
self._commit = self._expected_commit
return self

output = self._output_from_file()
if output is not None:
self._update_from_vcs(output)
return self

# Only git right now but easily extended to SVN, Mercurial, etc.
for cmd in ['git', 'git.cmd', 'git.exe']:
try:
Expand Down Expand Up @@ -272,6 +277,7 @@ def git_fetch(self, cmd='git', as_string=False):
cwd=os.path.dirname(self.fpath))
if as_string: return output
except Exception as e1:
print('Git describe exception: %s' % str(e1))
try:
output = self._output_from_file()
if output is not None:
Expand Down Expand Up @@ -483,7 +489,7 @@ def extract_directory_tag(cls, setup_path, reponame):


@classmethod
def setup_version(cls, setup_path, reponame, archive_commit=None,
def record_version(cls, setup_path, reponame, archive_commit=None,
pkgname=None, dirty='report'):
info = {}
git_describe = None
Expand Down Expand Up @@ -524,11 +530,22 @@ def setup_version(cls, setup_path, reponame, archive_commit=None,
except:
print('Error in setup_version: could not write .version file.')

return info['version_string']
@classmethod
def setup_version(cls, setup_path, reponame, archive_commit=None,
pkgname=None, dirty='report', record_version=False):
if record_version:
cls.record_version(setup_path, reponame, archive_commit=archive_commit,
pkgname=pkgname, dirty=dirty)
return Version.get_setup_version(setup_path, reponame,
describe=False,
dirty=dirty,
pkgname=pkgname,
archive_commit=archive_commit)



def get_setup_version(location, reponame, pkgname=None, archive_commit=None):
def get_setup_version(location, reponame, pkgname=None, archive_commit=None,
record_version=False):
"""Helper for use in setup.py to get the current version from either
git describe or the .version file (if available).

Expand All @@ -548,7 +565,9 @@ def get_setup_version(location, reponame, pkgname=None, archive_commit=None):
pkgname = reponame if pkgname is None else pkgname
if archive_commit is None:
warnings.warn("No archive commit available; git archives will not contain version information")
return Version.setup_version(os.path.dirname(os.path.abspath(location)),reponame,pkgname=pkgname,archive_commit=archive_commit)
return Version.setup_version(os.path.dirname(os.path.abspath(location)),reponame,
pkgname=pkgname, archive_commit=archive_commit,
record_version=record_version)


def get_setupcfg_version():
Expand Down
27 changes: 23 additions & 4 deletions examples/pkg_bundle/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def fetch(self):
self._commit = self._expected_commit
return self

output = self._output_from_file()
if output is not None:
self._update_from_vcs(output)
return self

# Only git right now but easily extended to SVN, Mercurial, etc.
for cmd in ['git', 'git.cmd', 'git.exe']:
try:
Expand Down Expand Up @@ -272,6 +277,7 @@ def git_fetch(self, cmd='git', as_string=False):
cwd=os.path.dirname(self.fpath))
if as_string: return output
except Exception as e1:
print('Git describe exception: %s' % str(e1))
try:
output = self._output_from_file()
if output is not None:
Expand Down Expand Up @@ -483,7 +489,7 @@ def extract_directory_tag(cls, setup_path, reponame):


@classmethod
def setup_version(cls, setup_path, reponame, archive_commit=None,
def record_version(cls, setup_path, reponame, archive_commit=None,
pkgname=None, dirty='report'):
info = {}
git_describe = None
Expand Down Expand Up @@ -524,11 +530,22 @@ def setup_version(cls, setup_path, reponame, archive_commit=None,
except:
print('Error in setup_version: could not write .version file.')

return info['version_string']
@classmethod
def setup_version(cls, setup_path, reponame, archive_commit=None,
pkgname=None, dirty='report', record_version=False):
if record_version:
cls.record_version(setup_path, reponame, archive_commit=archive_commit,
pkgname=pkgname, dirty=dirty)
return Version.get_setup_version(setup_path, reponame,
describe=False,
dirty=dirty,
pkgname=pkgname,
archive_commit=archive_commit)



def get_setup_version(location, reponame, pkgname=None, archive_commit=None):
def get_setup_version(location, reponame, pkgname=None, archive_commit=None,
record_version=False):
"""Helper for use in setup.py to get the current version from either
git describe or the .version file (if available).

Expand All @@ -548,7 +565,9 @@ def get_setup_version(location, reponame, pkgname=None, archive_commit=None):
pkgname = reponame if pkgname is None else pkgname
if archive_commit is None:
warnings.warn("No archive commit available; git archives will not contain version information")
return Version.setup_version(os.path.dirname(os.path.abspath(location)),reponame,pkgname=pkgname,archive_commit=archive_commit)
return Version.setup_version(os.path.dirname(os.path.abspath(location)),reponame,
pkgname=pkgname, archive_commit=archive_commit,
record_version=record_version)


def get_setupcfg_version():
Expand Down