Skip to content

Commit 640f11d

Browse files
authored
Log metaflow_version as a tag for all packaged executions (#376)
* Log metaflow_version as a tag for all packaged executions * Inspect INFO for fetching metaflow version on AWS Batch
1 parent 7567814 commit 640f11d

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

metaflow/metaflow_version.py

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
#!/usr/bin/env python
2-
"""Get version identification from git
2+
"""Get version identification for the package
33
44
See the documentation of get_version for more information
55
66
"""
77

8-
# This file is imported from https://github.com/aebrahim/python-git-version
9-
10-
from __future__ import print_function
8+
# This file is adapted from https://github.com/aebrahim/python-git-version
119

1210
from subprocess import check_output, CalledProcessError
1311
from os import path, name, devnull, environ, listdir
12+
import json
1413

1514
__all__ = ("get_version",)
1615

1716
CURRENT_DIRECTORY = path.dirname(path.abspath(__file__))
18-
VERSION_FILE = path.join(CURRENT_DIRECTORY, "VERSION")
17+
INFO_FILE = path.join(path.dirname(CURRENT_DIRECTORY), "INFO")
1918

2019
GIT_COMMAND = "git"
2120

@@ -96,26 +95,15 @@ def format_git_describe(git_str, pep440=False):
9695
return git_str.replace("-g", "+git")
9796

9897

99-
def read_release_version():
100-
"""Read version information from VERSION file"""
98+
def read_info_version():
99+
"""Read version information from INFO file"""
101100
try:
102-
with open(VERSION_FILE, "r") as infile:
103-
version = str(infile.read().strip())
104-
if len(version) == 0:
105-
version = None
106-
return version
101+
with open(INFO_FILE, "r") as contents:
102+
return json.load(contents).get('metaflow_version')
107103
except IOError:
108104
return None
109105

110106

111-
def update_release_version():
112-
"""Update VERSION file"""
113-
version = get_version(pep440=True)
114-
with open(VERSION_FILE, "w") as outfile:
115-
outfile.write(version)
116-
outfile.write("\n")
117-
118-
119107
def get_version(pep440=False):
120108
"""Tracks the version number.
121109
@@ -124,22 +112,21 @@ def get_version(pep440=False):
124112
a release as defined by PEP 440. When False, the githash (if
125113
available) will be appended to the version string.
126114
127-
The file VERSION holds the version information. If this is not a git
128-
repository, then it is reasonable to assume that the version is not
129-
being incremented and the version returned will be the release version as
130-
read from the file.
131-
132-
However, if the script is located within an active git repository,
115+
If the script is located within an active git repository,
133116
git-describe is used to get the version information.
134117
135-
The file VERSION will need to be changed by manually. This should be done
136-
before running git tag (set to the same as the version in the tag).
118+
Otherwise, the version logged by package installer is returned.
119+
120+
If even that information isn't available (likely when executing on a
121+
remote cloud instance), the version information is returned from INFO file
122+
in the current directory.
137123
138124
"""
139125

140-
git_version = format_git_describe(call_git_describe(), pep440=pep440)
141-
if git_version is None: # not a git repository
126+
version = format_git_describe(call_git_describe(), pep440=pep440)
127+
if version is None: # not a git repository
142128
import metaflow
143-
return metaflow.__version__
144-
else:
145-
return git_version
129+
version = metaflow.__version__
130+
if version is None: # not a proper python package
131+
version = read_info_version()
132+
return version

0 commit comments

Comments
 (0)