Skip to content

Commit dbd4f3c

Browse files
committed
Single source the version number
Version number mismatches are annoying and it happened already twice in two years. The pypi people have some solutions for that problem: https://packaging.python.org/single_source_version/ Now, the version is only defined at a single place; the __init__.py file in the pygccxml package.
1 parent fe3beb5 commit dbd4f3c

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

docs/conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# documentation root, use os.path.abspath to make it absolute, like shown here.
2222
sys.path.insert(0, os.path.abspath('.') + "/../")
2323

24+
from ..release_utils import utils # nopep8
25+
2426
# -- General configuration ------------------------------------------------
2527

2628
# If your documentation needs a minimal Sphinx version, state it here.
@@ -55,9 +57,9 @@
5557
# built documents.
5658
#
5759
# The short X.Y version.
58-
version = '1.8.2'
60+
version = utils.find_version("../pygccxml/__init__.py")
5961
# The full version, including alpha/beta/rc tags.
60-
release = '1.8.2'
62+
release = utils.find_version("../pygccxml/__init__.py")
6163

6264
# The language for content autogenerated by Sphinx. Refer to documentation
6365
# for a list of supported languages.

release_utils/__init__.py

Whitespace-only changes.

release_utils/utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
# Copyright 2014-2016 Insight Software Consortium.
3+
# Copyright 2004-2008 Roman Yakovenko.
4+
# Distributed under the Boost Software License, Version 1.0.
5+
# See http://www.boost.org/LICENSE_1_0.txt
6+
7+
import io
8+
import os
9+
import re
10+
11+
12+
def find_version(file_path):
13+
"""
14+
Find the version of pygccxml.
15+
16+
Used by setup.py and the sphinx's conf.py.
17+
Inspired by https://packaging.python.org/single_source_version/
18+
19+
Args:
20+
file_path (str): path to the file containing the version.
21+
"""
22+
23+
with io.open(
24+
os.path.join(
25+
os.path.dirname(__file__),
26+
os.path.normpath(file_path)),
27+
encoding="utf8") as fp:
28+
content = fp.read()
29+
30+
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
31+
content, re.M)
32+
if version_match:
33+
return version_match.group(1)
34+
raise RuntimeError("Unable to find version string.")

setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
# See http://www.boost.org/LICENSE_1_0.txt
66

77
from setuptools import setup
8+
from release_utils import utils
9+
10+
version = utils.find_version("pygccxml/__init__.py")
811

912
setup(name="pygccxml",
10-
version="1.8.2",
13+
version=version,
1114
author="Roman Yakovenko",
1215
author_email="roman yakovenko at gmail com",
1316
maintainer="Michka Popoff and the Insight Software Consortium",
1417
maintainer_email="[email protected]",
1518
description="Python package for easy C++ declarations navigation.",
1619
url="https://github.com/gccxml/pygccxml",
17-
download_url="https://github.com/gccxml/pygccxml/archive/v1.8.1.tar.gz",
20+
download_url="https://github.com/gccxml/pygccxml/archive/v" +
21+
version + ".tar.gz",
1822
license="Boost",
1923
keywords="C++, declaration parser, CastXML, gccxml",
2024
packages=["pygccxml",

0 commit comments

Comments
 (0)