Skip to content

Commit

Permalink
fix to make setup.py get_version more robust
Browse files Browse the repository at this point in the history
Now it only considers a git repo in which setup.py lives at the top level.
This fixed the problem where running setup.py with a relative path from another
directory which happened to be a git repo, or installing the sdist from inside
some other git repo, would make get_version report the version of the *other*
repo.  This was initially encountered in the readthedocs.org build environment,
where the builds seem to be run within the git repo of the RTD source itself.
  • Loading branch information
jmuhlich committed Sep 6, 2012
1 parent 084c4d2 commit 5b1d6fd
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ class GitError(Exception):

def get_version():
"""Get a nice version number from git-describe"""

# ensure that we are working in a pysb git repo
setup_path = os.path.abspath(os.path.dirname(__file__))
print setup_path
if not os.path.exists(os.path.join(setup_path, '.git')):
raise Exception("setup.py is not in the root of a git repository; "
"aborting")
os.chdir(setup_path)

# run git describe
gitcmd = ['git', 'describe', '--always', '--abbrev=4']
try:
gitproc = subprocess.Popen(gitcmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down

0 comments on commit 5b1d6fd

Please sign in to comment.