Mercurial > hgrepos > Python > libs > ConfigMix
changeset 586:d68e8204f7c3
Allow to build a distribution without C-extensions by using --only-pure
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 09 Jan 2022 13:46:57 +0100 |
| parents | 233bd8bbda28 |
| children | eac8e2d3933c |
| files | setup.py |
| diffstat | 1 files changed, 89 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/setup.py Sun Jan 09 13:40:22 2022 +0100 +++ b/setup.py Sun Jan 09 13:46:57 2022 +0100 @@ -62,6 +62,12 @@ wcp_idx = None else: del sys.argv[wcp_idx] +try: + pure_only_idx = sys.argv.index("--pure-only") +except ValueError: + pure_only_idx = None +else: + del sys.argv[pure_only_idx] # @@ -73,42 +79,72 @@ print("removing `%s.egg-info'" % (PROJECT_NAME,)) shutil.rmtree(PROJECT_NAME + ".egg-info") -if wcp_idx is None: - # - # Handle the optinal C-extension for Python3.7+ and CPython only. - # PyPy does not need this. - # +if pure_only_idx is None: + if wcp_idx is None: + # + # Handle the optinal C-extension for Python3.7+ and CPython only. + # PyPy does not need this. + # + + # The C-extension uses multi-phase module initialization (PEP 489, PY 3.5+) + if (platform.python_implementation() == "CPython" + and (sys.version_info[0] > 3 + or (sys.version_info[0] == 3 and sys.version_info[1] >= 5))): - # The C-extension uses multi-phase module initialization (PEP 489, PY 3.5+) - if (platform.python_implementation() == "CPython" - and (sys.version_info[0] > 3 - or (sys.version_info[0] == 3 and sys.version_info[1] >= 5))): + # The stable API for Python 3.7+ is used + if sys.version_info[0] == 3 and sys.version_info[1] < 7: + py_limited_api = False + else: + py_limited_api = True - # The stable API for Python 3.7+ is used - if sys.version_info[0] == 3 and sys.version_info[1] < 7: - py_limited_api = False - else: - py_limited_api = True + if py_limited_api: + define_macros = [("Py_LIMITED_API", "0x03070000")] + else: + define_macros = [] + + try: + from setuptools import Extension + except ImportError: + from distutils.core import Extension - if py_limited_api: - define_macros = [("Py_LIMITED_API", "0x03070000")] - else: - define_macros = [] - - try: - from setuptools import Extension - except ImportError: - from distutils.core import Extension + ext_modules = [ + Extension( + name="configmix._speedups", + sources=["configmix/_speedups.c"], + define_macros=define_macros, + py_limited_api=py_limited_api, + optional=True + ), + ] - ext_modules = [ - Extension( - name="configmix._speedups", - sources=["configmix/_speedups.c"], - define_macros=define_macros, - py_limited_api=py_limited_api, - optional=True - ), - ] + if py_limited_api: + # + # Build a wheel that is properly named using the stable API + # + try: + import wheel.bdist_wheel + except ImportError: + pass + else: + class BDistWheel(wheel.bdist_wheel.bdist_wheel): + def finalize_options(self): + # Synchronize this with Py_LIMITED_API + self.py_limited_api = 'cp37' + super().finalize_options() + + cmdclass["bdist_wheel"] = BDistWheel + else: + + if not os.path.isfile("configmix/_speedups.pyd"): + raise RuntimeError("no _speedups.pyd found") + + setup_extra_kwds["package_data"] = { + "configmix": ["*.pyd"] + } + + ext_modules = [] + + py_limited_api = True if py_limited_api: # @@ -121,62 +157,38 @@ else: class BDistWheel(wheel.bdist_wheel.bdist_wheel): def finalize_options(self): - # Synchronize this with Py_LIMITED_API + # + # Synchronize this with Py_LIMITED_API and with the + # external build of _speedups.pyd. + # Also use the --plat-name (-p) for tagging the Wheel + # properly (e.g. -p win_amd64). + # self.py_limited_api = 'cp37' super().finalize_options() cmdclass["bdist_wheel"] = BDistWheel -else: - if not os.path.isfile("configmix/_speedups.pyd"): - raise RuntimeError("no _speedups.pyd found") + from setuptools.dist import Distribution - setup_extra_kwds["package_data"] = { - "configmix": ["*.pyd"] - } - - ext_modules = [] - - py_limited_api = True - - if py_limited_api: # - # Build a wheel that is properly named using the stable API + # Force a binary package. An empty ext_modules does not do this always. + # Tested with wheel v0.29.0 # - try: - import wheel.bdist_wheel - except ImportError: - pass - else: - class BDistWheel(wheel.bdist_wheel.bdist_wheel): - def finalize_options(self): - # - # Synchronize this with Py_LIMITED_API and with the - # external build of _speedups.pyd. - # Also use the --plat-name (-p) for tagging the Wheel - # properly (e.g. -p win_amd64). - # - self.py_limited_api = 'cp37' - super().finalize_options() + class BinaryDistribution(Distribution): + """Distribution which always forces a binary package with + + platform name - cmdclass["bdist_wheel"] = BDistWheel - - from setuptools.dist import Distribution + """ + def has_ext_modules(foo): + return True - # - # Force a binary package. An empty ext_modules does not do this always. - # Tested with wheel v0.29.0 + setup_extra_kwds["distclass"] = BinaryDistribution +else: # - class BinaryDistribution(Distribution): - """Distribution which always forces a binary package with - - platform name - - """ - def has_ext_modules(foo): - return True - - setup_extra_kwds["distclass"] = BinaryDistribution + # pure + # + pass if ext_modules is not None:
