Skip to content

Commit

Permalink
Update version.py from autover to allow repo and pkg names to differ.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceball committed Apr 20, 2018
1 parent 445d051 commit 06894b5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions param/version.py
@@ -1,5 +1,5 @@
"""Apart from this first paragraph, this version.py file is an exact
copy of https://github.com/ioam/autover/blob/59c207db70da6f41b689e8be5c5f6abb1e062c8e/autover/version.py.
copy of https://github.com/ioam/autover/blob/ad22b3fcbcdaa40570c3fc8eedb3aeed23b5cdcf/autover/version.py.
Autover's version.py is included inside the param package only to make
version.py available to various other projects that use version.py and
already depend on param, thus saving them from bundling version.py or
Expand Down Expand Up @@ -438,13 +438,14 @@ def verify(self, string_version=None):

@classmethod
def get_setup_version(cls, setup_path, reponame, describe=False,
dirty='raise', archive_commit=None):
dirty='raise', pkgname=None, archive_commit=None):
"""
Helper for use in setup.py to get the version from the .version file (if available)
or more up-to-date information from git describe (if available).
Assumes the __init__.py will be found in the directory
{reponame}/__init__.py relative to setup.py.
{reponame}/__init__.py relative to setup.py unless pkgname is
explicitly specified in which case that name is used instead.
If describe is True, the raw string obtained from git described is
returned which is useful for updating the .version file.
Expand All @@ -457,11 +458,12 @@ def get_setup_version(cls, setup_path, reponame, describe=False,
be useful if you want to make sure packages are not built from a
dirty repository state.
"""
pkgname = reponame if pkgname is None else pkgname
policies = ['raise','report', 'strip']
if dirty not in policies:
raise AssertionError("get_setup_version dirty policy must be in %r" % policies)

fpath = os.path.join(setup_path, reponame, "__init__.py")
fpath = os.path.join(setup_path, pkgname, "__init__.py")
version = Version(fpath=fpath, reponame=reponame, archive_commit=archive_commit)
if describe:
vstring = version.git_fetch(as_string=True)
Expand Down Expand Up @@ -489,15 +491,18 @@ def extract_directory_tag(cls, setup_path, reponame):


@classmethod
def setup_version(cls, setup_path, reponame, archive_commit=None, dirty='raise'):
def setup_version(cls, setup_path, reponame, archive_commit=None,
pkgname=None, dirty='raise'):
info = {}
git_describe = None
pkgname = reponame if pkgname is None else pkgname
try:
# Will only work if in a git repo and git is available
git_describe = Version.get_setup_version(setup_path,
reponame,
describe=True,
dirty=dirty,
pkgname=pkgname,
archive_commit=archive_commit)

if git_describe is not None:
Expand All @@ -509,7 +514,7 @@ def setup_version(cls, setup_path, reponame, archive_commit=None, dirty='raise')
if extracted_directory_tag is not None:
info['extracted_directory_tag'] = extracted_directory_tag
try:
with open(os.path.join(setup_path, reponame, '.version'), 'w') as f:
with open(os.path.join(setup_path, pkgname, '.version'), 'w') as f:
f.write(json.dumps({'extracted_directory_tag':extracted_directory_tag}))
except:
print('Error in setup_version: could not write .version file.')
Expand All @@ -519,9 +524,10 @@ def setup_version(cls, setup_path, reponame, archive_commit=None, dirty='raise')
reponame,
describe=False,
dirty=dirty,
pkgname=pkgname,
archive_commit=archive_commit)
try:
with open(os.path.join(setup_path, reponame, '.version'), 'w') as f:
with open(os.path.join(setup_path, pkgname, '.version'), 'w') as f:
f.write(json.dumps(info))
except:
print('Error in setup_version: could not write .version file.')
Expand Down

0 comments on commit 06894b5

Please sign in to comment.