From 54911fff39a57426f4b071675c5f0b0a5dc6e2ef Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Wed, 3 Jul 2019 23:31:38 +0200 Subject: [PATCH] Consolidate version strings in pyproject.toml Storing the current version in a single place greatly simplifies issuing new package releases. --- docs/conf.py | 2 +- pelican/__init__.py | 7 ++++++- setup.py | 20 +++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 7645a86d..43009cdd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ copyright = '2010 – present, Alexis Metaireau and contributors' exclude_patterns = ['_build'] release = __version__ version = '.'.join(release.split('.')[:1]) -last_stable = '4.0.1' +last_stable = __version__ rst_prolog = ''' .. |last_stable| replace:: :pelican-doc:`{0}` '''.format(last_stable) diff --git a/pelican/__init__.py b/pelican/__init__.py index 9b5791ac..0a06d905 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -32,7 +32,12 @@ from pelican.utils import (clean_output_dir, file_watcher, folder_watcher, maybe_pluralize) from pelican.writers import Writer -__version__ = "4.0.2.dev0" +try: + __version__ = __import__('pkg_resources') \ + .get_distribution('pelican').version +except Exception: + __version__ = "unknown" + DEFAULT_CONFIG_NAME = 'pelicanconf.py' logger = logging.getLogger(__name__) diff --git a/setup.py b/setup.py index e8918941..53d9dd1c 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import re import sys from io import open from os import walk @@ -6,6 +7,23 @@ from os.path import join, relpath from setuptools import setup + +def get_version(): + VERSION_REGEX = re.compile( + r"^version\s*=\s*\"(?P.*)\"$" + ) + with open("pyproject.toml") as f: + for line in f: + match = VERSION_REGEX.match(line) + + if match: + return match.group("version") + + return None + + +version = get_version() + requires = ['feedgenerator >= 1.9', 'jinja2 >= 2.7', 'pygments', 'docutils', 'pytz >= 0a', 'blinker', 'unidecode', 'six >= 1.4', 'python-dateutil'] @@ -28,7 +46,7 @@ if sys.version_info.major < 3: setup( name='pelican', - version='4.0.2.dev0', + version=version, url='https://getpelican.com/', author='Alexis Metaireau', maintainer='Justin Mayer',