diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2019-03-29 14:22:49 -0700 |
---|---|---|
committer | Tomáš Mráz <t8m@users.noreply.github.com> | 2019-04-01 10:30:43 +0200 |
commit | 5ebc3e6935341367defaac6933b62e80705fd10c (patch) | |
tree | 0718b7a31e1d65126a84860526bab30f11a63404 | |
parent | 9d6140b4c37f39cdd0c1947adf07dc5ca1762055 (diff) | |
download | libpwquality-git-5ebc3e6935341367defaac6933b62e80705fd10c.tar.gz |
Changes to allow building a tarball of the python extension
With these changes it is possible to do a `python setup.py sdist` in the
python subdirectory and create a tarball which can be pushed to pypi.
That will allow people to pip install the Python extension module for
libpwquality (for instance, if their distribution is not building the
extension for their version of python)
-rw-r--r-- | python/MANIFEST.in | 1 | ||||
-rwxr-xr-x | python/setup.py.in | 32 |
2 files changed, 22 insertions, 11 deletions
diff --git a/python/MANIFEST.in b/python/MANIFEST.in new file mode 100644 index 0000000..75e6be4 --- /dev/null +++ b/python/MANIFEST.in @@ -0,0 +1 @@ +include constants.c diff --git a/python/setup.py.in b/python/setup.py.in index 6457595..a741b91 100755 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -4,23 +4,33 @@ # See the end of the file for Copyright and License Information # +import os + from distutils.core import setup, Extension from distutils.command.build_ext import build_ext as _build_ext +from distutils.command.sdist import sdist as _sdist -class build_ext(_build_ext): - def genconstants(self, headerfile, outputfile): - hf = open(headerfile, 'r') - of = open(outputfile, 'w') - of.write('/* This file is generated during build time from pwquality.h */\n\n') - for line in hf: - if line.startswith('#define PWQ_'): - s = line.split() - of.write('PyModule_AddIntConstant(module, "%s", %s);\n' % (s[1], s[2])) +def genconstants(headerfile, outputfile): + hf = open(headerfile, 'r') + of = open(outputfile, 'w') + of.write('/* This file is generated during build time from pwquality.h */\n\n') + for line in hf: + if line.startswith('#define PWQ_'): + s = line.split() + of.write('PyModule_AddIntConstant(module, "%s", %s);\n' % (s[1], s[2])) +class build_ext(_build_ext): def run(self): - self.genconstants('../src/pwquality.h', 'constants.c') + if not os.path.exists('constants.c'): + genconstants('../src/pwquality.h', 'constants.c') _build_ext.run(self) +class sdist(_sdist): + def run(self): + if not os.path.exists('constants.c'): + genconstants('../src/pwquality.h', 'constants.c') + _sdist.run(self) + pwqmodule = Extension('pwquality', sources = ['pwquality.c'], include_dirs = ['../src'], @@ -36,7 +46,7 @@ setup( url = 'http://fedorahosted.org/libpwquality', license = 'BSD or GPLv2+', ext_modules = [pwqmodule], - cmdclass = {'build_ext': build_ext} + cmdclass = {'build_ext': build_ext, 'sdist': sdist} ) # Copyright (c) Red Hat, Inc, 2011 |