summaryrefslogtreecommitdiffstats
path: root/base/common/python
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2016-08-08 13:08:17 +0200
committerChristian Heimes <cheimes@redhat.com>2016-08-08 13:08:17 +0200
commite948a42f8bf7823b18ad4551a8fe8a5db991e966 (patch)
treebf7f6d5e69b35c05cfc91b8028dcdf1196747c3b /base/common/python
parent7bed80ef6b1529f948da260a6b43f2052c6ffb21 (diff)
downloadpki-e948a42f8bf7823b18ad4551a8fe8a5db991e966.tar.gz
pki-e948a42f8bf7823b18ad4551a8fe8a5db991e966.tar.xz
pki-e948a42f8bf7823b18ad4551a8fe8a5db991e966.zip
Improve setup.py for standalone Dogtag client releases
PyPI requires a different spelling of LGPLv3+ classifier. The correct name for installation requirements is 'install_requires', not 'requirements'. Add a new version_info command that rewrites setup.py in place to include the current version. This fixes a problem with source distributions of the client package.
Diffstat (limited to 'base/common/python')
-rw-r--r--base/common/python/setup.cfg2
-rw-r--r--base/common/python/setup.py83
2 files changed, 63 insertions, 22 deletions
diff --git a/base/common/python/setup.cfg b/base/common/python/setup.cfg
index ad4348612..32f212641 100644
--- a/base/common/python/setup.cfg
+++ b/base/common/python/setup.cfg
@@ -2,5 +2,5 @@
universal = 1
[aliases]
-packages = clean --all egg_info bdist_wheel sdist --format=zip
+packages = clean --all version_info egg_info bdist_wheel sdist --format=zip
release = packages register upload
diff --git a/base/common/python/setup.py b/base/common/python/setup.py
index 86e0704cd..e0920c1e6 100644
--- a/base/common/python/setup.py
+++ b/base/common/python/setup.py
@@ -43,28 +43,67 @@ try:
except ImportError:
from distutils.core import setup
+from distutils.cmd import Command
+
+
+class VersionInfo(Command):
+ user_options = []
-def get_version(specfile='../../../specs/pki-core.spec'):
version_re = re.compile('^Version:\s*(\d+\.\d+\.\d+)')
release_re = re.compile('^Release:.*?([\d\.]+)')
- version = release = None
- with open(specfile) as f:
- for line in f:
- if version is None:
- match = version_re.match(line)
- if match is not None:
- version = match.group(1)
- if release is None:
- match = release_re.match(line)
- if match is not None:
- release = match.group(1)
- if version is not None and release is not None:
- break
- if version is None or release is None:
- raise ValueError(version, release)
- return "%s.%s" % (version, release)
-
-VERSION = get_version()
+ specfile = '../../../specs/pki-core.spec'
+
+ def initialize_options(self):
+ self.rpm_version = None
+
+ def finalize_options(self):
+ try:
+ version, release = self.get_version()
+ except IOError:
+ pass
+ else:
+ self.rpm_version = "%s.%s" % (version, release)
+
+ def run(self):
+ if self.rpm_version is not None:
+ self.distribution.metadata.version = self.rpm_version
+ self.rewrite_setup_py()
+ else:
+ raise ValueError(
+ 'Cannot load version from {}'.format(self.specfile)
+ )
+
+ def get_version(self):
+ version = release = None
+ with open(self.specfile) as f:
+ for line in f:
+ if version is None:
+ match = self.version_re.match(line)
+ if match is not None:
+ version = match.group(1)
+ if release is None:
+ match = self.release_re.match(line)
+ if match is not None:
+ release = match.group(1)
+ if version is not None and release is not None:
+ break
+ if version is None or release is None:
+ raise ValueError(version, release)
+ return version, release
+
+ def rewrite_setup_py(self):
+ with open(__file__) as f:
+ lines = list(f)
+ for i, line in enumerate(lines):
+ if line.startswith('VERSION ='):
+ lines[i] = "VERSION = '{}'\n".format(self.rpm_version)
+ with open(__file__, 'w') as f:
+ f.write(''.join(lines))
+
+
+# auto-generated by version_info
+VERSION = None
+
setup(
author='Dogtag Certificate System Team',
@@ -85,7 +124,8 @@ and set up in less than an hour.""",
keywords='pki x509 cert certificate',
url='http://pki.fedoraproject.org/',
packages=['pki', 'pki.cli'],
- requirements=['python-nss', 'requests', 'six'],
+ install_requires=['python-nss', 'requests', 'six'],
+ cmdclass={'version_info': VersionInfo},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
@@ -93,7 +133,8 @@ and set up in less than an hour.""",
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
- 'License :: OSI Approved :: GNU Lesser General Public License v3+ (LGPLv3+)',
+ 'License :: OSI Approved :: GNU Lesser General Public License ' +
+ 'v3 or later (LGPLv3+)',
'Topic :: Security :: Cryptography',
],
)