Skip to content

Commit

Permalink
create version string in separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
skuschel committed Mar 15, 2015
1 parent 8d5d06c commit f888659
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions postpic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import datareader
import analyzer
import plotting
from pkg_resources import get_distribution, DistributionNotFound
from analyzer import ParticleAnalyzer, identifyspecies
from datareader import chooseCode, readDump, readSim

Expand All @@ -35,33 +34,37 @@
__all__ += ['ParticleAnalyzer', 'identifyspecies']
__all__ += ['chooseCode', 'readDump', 'readSim']

# read version from installed metadata
try:
import os.path
_dist = get_distribution('postpic')
# Normalize case for Windows systems
dist_loc = os.path.normcase(_dist.location)
here = os.path.normcase(__file__)
if not here.startswith(os.path.join(dist_loc, 'postpic')):
# not installed, but there is another version that *is*
raise DistributionNotFound
except DistributionNotFound:
__version__ = 'Please install this project with setup.py'
else:
__version__ = _dist.version

# add Git description for __version__ if present
try:
import subprocess as sub
import os.path
cwd = os.path.dirname(__file__)
p = sub.Popen(['git', 'describe', '--always'], stdout=sub.PIPE,
stderr=sub.PIPE, cwd=cwd)
out, err = p.communicate()
if not p.returncode: # git exited without error
__version__ += '_g' + out
except OSError:
# 'git' command not found
pass
def _createversionstring():
from pkg_resources import get_distribution, DistributionNotFound
# read version from installed metadata
try:
import os.path
_dist = get_distribution('postpic')
# Normalize case for Windows systems
dist_loc = os.path.normcase(_dist.location)
here = os.path.normcase(__file__)
if not here.startswith(os.path.join(dist_loc, 'postpic')):
# not installed, but there is another version that *is*
raise DistributionNotFound
except DistributionNotFound:
__version__ = 'Please install this project with setup.py'
else:
__version__ = _dist.version

# add Git description for __version__ if present
try:
import subprocess as sub
import os.path
cwd = os.path.dirname(__file__)
p = sub.Popen(['git', 'describe', '--always'], stdout=sub.PIPE,
stderr=sub.PIPE, cwd=cwd)
out, err = p.communicate()
if not p.returncode: # git exited without error
__version__ += '_' + out
except OSError:
# 'git' command not found
pass
return __version__

__version__ = _createversionstring()

0 comments on commit f888659

Please sign in to comment.