Skip to content
Snippets Groups Projects
Commit 7681ce33 authored by Stephan Kuschel's avatar Stephan Kuschel
Browse files

refactor versioning scheme

the central versioning file is now _postpic_version.py. It will be
called by setup.py as well as by postpic itself.

_postpic_version.py will try to retrieve the version info from git
first. If that fails it will try to access a version fiel _version.txt,
which will be written, whenever getting the version from git succeds.
parent 01ea6929
No related branches found
No related tags found
No related merge requests found
# auto generated by setup.py
_version.txt
examples/_openPMDdata
# Byte-compiled / optimized / DLL files
......
......@@ -2,3 +2,5 @@ include *.md
include LICENSE
include CONTRIBUTING.md
include postpic/*.pyx
include _version.txt
include postpic/_version.txt
postpic/_postpic_version.py
\ No newline at end of file
......@@ -32,6 +32,7 @@ from .particles import *
from . import datareader
from .datareader import chooseCode, readDump, readSim
from . import plotting
from . import _postpic_version
__all__ = ['helper']
__all__ += datahandling.__all__
......@@ -42,36 +43,5 @@ __all__ += ['datareader', 'plotting']
__all__ += ['chooseCode', 'readDump', 'readSim']
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
__git_version__, __version__ = _postpic_version.getversion_package()
# 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', '--dirty'], stdout=sub.PIPE,
stderr=sub.PIPE, cwd=cwd)
out, err = p.communicate()
if not p.returncode: # git exited without error
__version__ += '_' + str(out)
except OSError:
# 'git' command not found
pass
return __version__
__version__ = _createversionstring()
#!/usr/bin/env python
# Copyright (C) 2016 Stephan Kuschel
#
# This file is part of postpic.
#
# postpic is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# postpic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with postpic. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import absolute_import, division, print_function, unicode_literals
__version__ = 'v0.2.2'
def _gitversion():
'''
returns the git version string if the source in inside a git repo.
returns None otherwise.
'''
ret = None
try:
import subprocess as sub
import os.path
cwd = os.path.dirname(__file__)
p = sub.Popen(['git', 'describe', '--always', '--long', '--dirty'], stdout=sub.PIPE,
stderr=sub.PIPE, cwd=cwd)
out, err = p.communicate()
if not p.returncode: # git ran without error
ret = out.decode().strip('\n')
except OSError:
# 'git' command not found
pass
return ret
def _version(gitversion):
'''
returns the version as readable for setup.py.
For example: v0.2.2, v0.1.7-65
'''
ret = gitversion.strip('-dirty')
ret = ret[:-9] # remove the SHA
ret = ret.strip('-0')
return ret
def getversion_setup():
# search for the current version with git
gitversion = _gitversion()
# if found, write it to _version.txt and postpic/_version.txt
if gitversion is not None:
version = _version(gitversion)
with open('_version.txt', 'w') as fs, open('postpic/_version.txt', 'w') as fp:
for f in [fs, fp]:
f.write(gitversion + '\n')
f.write(version + '\n')
# if not found, try to read from _version.txt
else:
try:
with open('_version.txt', 'r') as f:
gitversion = f.readline()
version = f.readline()
except(FileNotFoundError):
# this can happen, if the code is downloaded
# from github directly as zip or tar
version = __version__
gitversion = 'unknown'
return gitversion, version
def getversion_package():
# search for the current version with git
gitversion = _gitversion()
# if found, write it to _version.txt and postpic/_version.txt
if gitversion is not None:
version = _version(gitversion)
# if not found, try to read from _version.txt
else:
try:
import pkgutil
data = pkgutil.get_data('postpic', '_version.txt')
gitversion, version = data.decode().splitlines()
except(FileNotFoundError):
# this can happen, if the code is downloaded
# from github directly as zip or tar
version = __version__
gitversion = 'unknown'
return gitversion, version
#!/usr/bin/env python
# Copyright (C) 2016 Stephan Kuschel
#
# This file is part of postpic.
#
......@@ -18,9 +20,16 @@
from setuptools import setup, find_packages
from Cython.Build import cythonize
import numpy
import os
import _postpic_version
_, version = _postpic_version.getversion_setup()
setup(name='postpic',
version='0.2.2',
version=version,
include_package_data = True,
author='Stephan Kuschel',
author_email='stephan.kuschel@gmail.de',
description='The open source particle-in-cell post processor.',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment