From 53f61f19d1815c992788745e748610daf4bc2f96 Mon Sep 17 00:00:00 2001 From: Kishi85 Date: Fri, 22 Mar 2019 11:46:01 +0100 Subject: [PATCH] setup: rework version determination for release bundles and update values --- .gitignore | 1 + setup.py | 41 ++++++++++++++++++++++++++++------------- version.txt | 1 + 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 version.txt diff --git a/.gitignore b/.gitignore index 175d3aa..ccfc15a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.pyc __pycache__ *dist/ +*build/ *egg-info/ *.tar.gz diff --git a/setup.py b/setup.py index 4b216c3..bf5633b 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +import io import os import subprocess @@ -8,34 +9,45 @@ from setuptools import setup, find_packages # Used for the long_description. It's nice, because now 1) we have a top level # README file and 2) it's easier to type in the README file than to put a raw # string in below ... -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() +def read(filename): + with io.open(os.path.join(os.path.dirname(__file__), filename)) as f: + return f.read() -# Utility function to determine version using git in a PEP-440 compatible way -def get_git_version(): +# Utility function to determine version using git in a PEP-440 compatible way, fallback to version.txt for releases +def determine_version(): + dir_path = os.path.dirname(os.path.realpath(__file__)) + ver_file = os.path.join(dir_path, "version.txt") + version = "0.0.0" + if os.path.exists(ver_file): + version = read(ver_file) + # If this is a release file and no git is found, use version.txt + if not os.path.isdir(os.path.join(dir_path, ".git")): + return version + # Derive version from git try: - output = subprocess.check_output(['git', 'describe', '--tags', '--dirty']).decode('utf-8').strip().split('-') + output = subprocess.check_output(['git', 'describe', '--tags', '--dirty'], cwd=dir_path)\ + .decode('utf-8').strip().split('-') if len(output) == 1: - version = output[0] + return output[0] elif len(output) == 2: - version = "{}.dev0".format(output[0]) + return "{}.dev0".format(output[0]) else: release = 'dev' if len(output) == 4 and output[3] == 'dirty' else '' - version = "{}.{}{}+{}".format(output[0], release, output[1], output[2]) + return "{}.{}{}+{}".format(output[0], release, output[1], output[2]) except subprocess.CalledProcessError: try: commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8').strip() status = subprocess.check_output(['git', 'status', '-s']).decode('utf-8').strip() - version = "0.0.0.dev0+{}".format(commit) if len(status) > 0 else "0.0.0+{}".format(commit) + return "{}.dev0+{}".format(version, commit) if len(status) > 0 else "{}+{}".format(version, commit) except subprocess.CalledProcessError: - version = "0.0.0" - return version + # finding the git version has utterly failed, use version.txt + return version setup( name="acertmgr", - version=get_git_version(), + version=determine_version(), author="Markus Hauschild", author_email="moepman@binary-kitchen.de", description="An automated certificate manager using ACME/letsencrypt", @@ -46,7 +58,10 @@ setup( long_description=read('README.md'), long_description_content_type="text/markdown", classifiers=[ - "Development Status :: 3 - Alpha", + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Environment :: Console", + "Topic :: Security :: Cryptography", "License :: OSI Approved :: ISC License", ], install_requires=[ diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..f514a2f --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.9.1 \ No newline at end of file