From 7e695f078e71b66c414888b070dfd626a5f78d3c Mon Sep 17 00:00:00 2001 From: mrbuche Date: Wed, 27 Jul 2022 13:25:13 -0600 Subject: [PATCH] better version mechanics --- .github/workflows/docs.sh | 4 +--- docs/conf.py | 20 ++++++++++++++++++-- setup.py | 16 +++++++++++++++- ufjc/__init__.py | 2 ++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docs.sh b/.github/workflows/docs.sh index ec08f1c..d2397e4 100644 --- a/.github/workflows/docs.sh +++ b/.github/workflows/docs.sh @@ -3,13 +3,11 @@ mkdir docs-temp/ mv docs/* docs-temp/ cd docs/ -export VERSION=$(grep version ../setup.py | cut -f2 -d "'") +export VERSION=$(grep __version__ ../ufjc/__init__.py | cut -f2 -d '"') sphinx-quickstart --sep -p ufjc -l en -a 'Michael R. Buche, Scott J. Grutzik' -r ${VERSION} -v ${VERSION} sphinx-apidoc -e -P -o source ../ ../*setup* mv ../docs-temp/* source/ rm -r ../docs-temp/ -echo "release = '${VERSION}'" >> source/conf.py -echo "version = '${VERSION}'" >> source/conf.py for file in ../ufjc/*.py; do export file_basename=$(basename ${file%.*}) export rst_file=$(echo "source/*`basename ${file%.*}`.rst") diff --git a/docs/conf.py b/docs/conf.py index 4a1aff9..6915817 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,8 +1,24 @@ -import os +import re import sys -sys.path.insert(0, os.path.abspath("../../")) +from os.path import join, abspath +sys.path.insert(0, abspath("../../")) + + +def get_version(): + VERSIONFILE = join('..', '..', 'ufjc', '__init__.py') + with open(VERSIONFILE, 'rt') as f: + lines = f.readlines() + vgx = '^__version__ = \"[0-9+.0-9+.0-9+]*[a-zA-Z0-9]*\"' + for line in lines: + mo = re.search(vgx, line, re.M) + if mo: + return mo.group().split('"')[1] + raise RuntimeError('Unable to find version in %s.' % (VERSIONFILE,)) + project = 'uFJC' +version = get_version() +release = version author = 'Michael R. Buche, Scott J. Grutzik' copyright = '2022 National Technology & Engineering Solutions of Sandia, \ LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, \ diff --git a/setup.py b/setup.py index c0f4aaf..3755061 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +import re +from os.path import join from distutils.core import setup from setuptools import find_packages @@ -8,9 +10,21 @@ def read(fname): return content +def get_version(): + VERSIONFILE = join('ufjc', '__init__.py') + with open(VERSIONFILE, 'rt') as f: + lines = f.readlines() + vgx = '^__version__ = \"[0-9+.0-9+.0-9+]*[a-zA-Z0-9]*\"' + for line in lines: + mo = re.search(vgx, line, re.M) + if mo: + return mo.group().split('"')[1] + raise RuntimeError('Unable to find version in %s.' % (VERSIONFILE,)) + + setup( name='ufjc', - version='1.3.1', + version=get_version(), package_dir={'ufjc': 'ufjc'}, packages=find_packages(), description='The Python package for the uFJC single-chain model.', diff --git a/ufjc/__init__.py b/ufjc/__init__.py index 935a677..37c1d50 100644 --- a/ufjc/__init__.py +++ b/ufjc/__init__.py @@ -1,2 +1,4 @@ from .core import * from .swfjc import * + +__version__ = "1.3.1"