forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dvc: refactor package versioning logic
- Use `version.py` to compute a dynamic version stored in `__version__`. Version information was scattered across the source code (`VERSION_BASE`, `VERSION`, `__version__`, and `version.py`). - Read `__version__` from `setup.py` and **pin** it using custom `build_py` command class. This way, we can maintain consistancy between the build version and the runtime one. Also, this gives us the ability to run `setup.py` without depending on on `dvc` itself. Close iterative#1824
- Loading branch information
Mr. Outis
committed
Apr 7, 2019
1 parent
2699a47
commit b4d0d37
Showing
11 changed files
with
108 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,6 @@ innosetup/config.ini | |
|
||
.coverage | ||
|
||
dvc/version.py | ||
|
||
*.swp | ||
|
||
pip-wheel-metadata/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Used from setup.py, so don't pull any additional dependencies | ||
import os | ||
import subprocess | ||
|
||
|
||
def generate_version(base_version): | ||
"""Generate a version with information about the git repository""" | ||
pkg_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) | ||
|
||
if not is_git_repo(pkg_dir) or not have_git(pkg_dir): | ||
return base_version | ||
|
||
return "{base_version}+{short_sha}{dirty}".format( | ||
base_version=base_version, | ||
short_sha=git_revision(pkg_dir).decode("utf-8")[0:6], | ||
dirty=".mod" if is_dirty(pkg_dir) else "", | ||
) | ||
|
||
|
||
def is_git_repo(dir_path): | ||
"""Is the given directory version-controlled with git?""" | ||
return os.path.exists(os.path.join(dir_path, ".git")) | ||
|
||
|
||
def have_git(dir_path): | ||
"""Can we run the git executable?""" | ||
try: | ||
subprocess.check_output(["git", "--help"]) | ||
return True | ||
except subprocess.CalledProcessError: | ||
return False | ||
except OSError: | ||
return False | ||
|
||
|
||
def git_revision(dir_path): | ||
"""Get the SHA-1 of the HEAD of a git repository.""" | ||
return subprocess.check_output( | ||
["git", "rev-parse", "HEAD"], cwd=dir_path | ||
).strip() | ||
|
||
|
||
def is_dirty(dir_path): | ||
"""Check whether a git repository has uncommitted changes.""" | ||
try: | ||
subprocess.check_call(["git", "diff", "--quiet"], cwd=dir_path) | ||
return False | ||
except subprocess.CalledProcessError: | ||
return True | ||
|
||
|
||
__version__ = generate_version(base_version="0.34.2") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# This script generates config.ini for setup.iss script | ||
from dvc import VERSION | ||
from dvc import __version__ | ||
from dvc.utils.compat import ConfigParser | ||
|
||
config = ConfigParser.ConfigParser() | ||
config.add_section("Version") | ||
config.set("Version", "Version", VERSION) | ||
config.set("Version", "Version", __version__) | ||
|
||
with open("scripts/innosetup/config.ini", "w") as f: | ||
config.write(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters