Skip to content

Commit

Permalink
Merge pull request #186 from nickhand/versioning
Browse files Browse the repository at this point in the history
adds proper versioning for release 0.1.1
  • Loading branch information
nickhand authored Jun 9, 2016
2 parents fd1860b + e1ba3f5 commit c7b068a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
nbodykit/version.py
*.pyc
examples/output
nersc/cori
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def setup(app):
# built documents.
#
# The short X.Y version.
version = '0.1'
version = nbodykit.version.short_version
# The full version, including alpha/beta/rc tags.
release = '0.1.0'
release = nbodykit.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
8 changes: 8 additions & 0 deletions nbodykit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@
pkg_dir = os.path.abspath(os.path.join(__file__, '..', '..'))
examples_dir = os.path.join(pkg_dir, 'examples')
bin_dir = os.path.join(pkg_dir, 'bin')


try:
from .version import version as __version__
except ImportError:
raise ImportError('nbodykit not properly installed. If you are running from '
'the source directory, please install it in-place by running: '
'pip install -e .')
79 changes: 78 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,83 @@
from setuptools import setup, find_packages
from glob import glob
setup(name="nbodykit", version="0.1.1",
import os
import re
import sys
import warnings

### versioning framework borrowed from xarray
MAJOR = 0
MINOR = 1
MICRO = 1
ISRELEASED = True
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
QUALIFIER = ''

FULLVERSION = VERSION
write_version = True

if not ISRELEASED:
import subprocess
FULLVERSION += '.dev'

pipe = None
for cmd in ['git', 'git.cmd']:
try:
pipe = subprocess.Popen(
[cmd, "describe", "--always", "--match", "v[0-9]*"],
stdout=subprocess.PIPE)
(so, serr) = pipe.communicate()
if pipe.returncode == 0:
break
except:
pass

if pipe is None or pipe.returncode != 0:
# no git, or not in git dir
if os.path.exists('nbodykit/version.py'):
warnings.warn("WARNING: Couldn't get git revision, using existing xarray/version.py")
write_version = False
else:
warnings.warn("WARNING: Couldn't get git revision, using generic version string")
else:
# have git, in git dir, but may have used a shallow clone (travis does this)
rev = so.strip()
# makes distutils blow up on Python 2.7
if sys.version_info[0] >= 3:
rev = rev.decode('ascii')

if not rev.startswith('v') and re.match("[a-zA-Z0-9]{7,9}", rev):
# partial clone, manually construct version string
# this is the format before we started using git-describe
# to get an ordering on dev version strings.
rev = "v%s.dev-%s" % (VERSION, rev)

# Strip leading v from tags format "vx.y.z" to get th version string
FULLVERSION = rev.lstrip('v')

else:
FULLVERSION += QUALIFIER

def write_version_py(filename=None):
cnt = """\
version = '%s'
short_version = '%s'
"""
if not filename:
filename = os.path.join(
os.path.dirname(__file__), 'nbodykit', 'version.py')

a = open(filename, 'w')
try:
a.write(cnt % (FULLVERSION, VERSION))
finally:
a.close()

if write_version:
write_version_py()

setup(name="nbodykit",
version=VERSION,
author="Yu Feng, Nick Hand, et al",
maintainer="Yu Feng",
maintainer_email="rainwoodman@gmail.com",
Expand Down

0 comments on commit c7b068a

Please sign in to comment.