1
1
#!/usr/bin/env python
2
- """Get version identification from git
2
+ """Get version identification for the package
3
3
4
4
See the documentation of get_version for more information
5
5
6
6
"""
7
7
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
11
9
12
10
from subprocess import check_output , CalledProcessError
13
11
from os import path , name , devnull , environ , listdir
12
+ import json
14
13
15
14
__all__ = ("get_version" ,)
16
15
17
16
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 " )
19
18
20
19
GIT_COMMAND = "git"
21
20
@@ -96,26 +95,15 @@ def format_git_describe(git_str, pep440=False):
96
95
return git_str .replace ("-g" , "+git" )
97
96
98
97
99
- def read_release_version ():
100
- """Read version information from VERSION file"""
98
+ def read_info_version ():
99
+ """Read version information from INFO file"""
101
100
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' )
107
103
except IOError :
108
104
return None
109
105
110
106
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
-
119
107
def get_version (pep440 = False ):
120
108
"""Tracks the version number.
121
109
@@ -124,22 +112,21 @@ def get_version(pep440=False):
124
112
a release as defined by PEP 440. When False, the githash (if
125
113
available) will be appended to the version string.
126
114
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,
133
116
git-describe is used to get the version information.
134
117
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.
137
123
138
124
"""
139
125
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
142
128
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