Mercurial > hgrepos > Python > libs > ConfigMix
comparison setup.py @ 575:9ce13f753c04
Allow execution of setup.py by packaging a cross-built Windows _speedups.pyd.
BUGS: ABI tag must be fixed afterwards.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 08 Jan 2022 23:00:36 +0100 |
| parents | 1bdf88437555 |
| children | 3ad416265652 |
comparison
equal
deleted
inserted
replaced
| 574:0c9169de6e3a | 575:9ce13f753c04 |
|---|---|
| 44 all_requirements.extend(yaml_requirements) | 44 all_requirements.extend(yaml_requirements) |
| 45 all_requirements.extend(toml_requirements) | 45 all_requirements.extend(toml_requirements) |
| 46 | 46 |
| 47 | 47 |
| 48 cmdclass = {} | 48 cmdclass = {} |
| 49 ext_modules = [] | 49 ext_modules = None |
| 50 setup_extra_kwds = {} | 50 setup_extra_kwds = {} |
| 51 | 51 |
| 52 # | 52 windows_cross_pack = False |
| 53 # Handle the optinal C-extension for Python3.7+ and CPython only. | 53 |
| 54 # PyPy does not need this. | 54 try: |
| 55 # | 55 wcp_idx = sys.argv.index("--windows-cross-pack") |
| 56 | 56 except ValueError: |
| 57 # The C-extension uses multi-phase module initialization (PEP 489, PY 3.5+) | 57 wcp_idx = None |
| 58 if (platform.python_implementation() == "CPython" | 58 else: |
| 59 and (sys.version_info[0] > 3 | 59 del sys.argv[wcp_idx] |
| 60 or (sys.version_info[0] == 3 and sys.version_info[1] >= 5))): | 60 |
| 61 | 61 |
| 62 # The stable API for Python 3.7+ is used | 62 if wcp_idx is None: |
| 63 if sys.version_info[0] == 3 and sys.version_info[1] < 7: | 63 |
| 64 py_limited_api = False | 64 # |
| 65 else: | 65 # Otherwise some cached package_data would be used. |
| 66 py_limited_api = True | 66 # But our package data differs between "standard" builds and |
| 67 | 67 # builds with "--windows-cross-pack". |
| 68 if py_limited_api: | 68 # |
| 69 define_macros = [("Py_LIMITED_API", "0x03070000")] | 69 |
| 70 else: | 70 if os.path.isdir("ConfigMix.egg-info"): |
| 71 define_macros = [] | 71 raise RuntimeError("please remove ConfigMix.egg-info before") |
| 72 | 72 |
| 73 try: | 73 # |
| 74 from setuptools import Extension | 74 # Handle the optinal C-extension for Python3.7+ and CPython only. |
| 75 except ImportError: | 75 # PyPy does not need this. |
| 76 from distutils.core import Extension | 76 # |
| 77 | 77 |
| 78 ext_modules = [ | 78 # The C-extension uses multi-phase module initialization (PEP 489, PY 3.5+) |
| 79 Extension( | 79 if (platform.python_implementation() == "CPython" |
| 80 name="configmix._speedups", | 80 and (sys.version_info[0] > 3 |
| 81 sources=["configmix/_speedups.c"], | 81 or (sys.version_info[0] == 3 and sys.version_info[1] >= 5))): |
| 82 define_macros=define_macros, | 82 |
| 83 py_limited_api=py_limited_api, | 83 # The stable API for Python 3.7+ is used |
| 84 optional=True | 84 if sys.version_info[0] == 3 and sys.version_info[1] < 7: |
| 85 ), | 85 py_limited_api = False |
| 86 ] | 86 else: |
| 87 py_limited_api = True | |
| 88 | |
| 89 if py_limited_api: | |
| 90 define_macros = [("Py_LIMITED_API", "0x03070000")] | |
| 91 else: | |
| 92 define_macros = [] | |
| 93 | |
| 94 try: | |
| 95 from setuptools import Extension | |
| 96 except ImportError: | |
| 97 from distutils.core import Extension | |
| 98 | |
| 99 ext_modules = [ | |
| 100 Extension( | |
| 101 name="configmix._speedups", | |
| 102 sources=["configmix/_speedups.c"], | |
| 103 define_macros=define_macros, | |
| 104 py_limited_api=py_limited_api, | |
| 105 optional=True | |
| 106 ), | |
| 107 ] | |
| 108 | |
| 109 if py_limited_api: | |
| 110 # | |
| 111 # Build a wheel that is properly named using the stable API | |
| 112 # | |
| 113 try: | |
| 114 import wheel.bdist_wheel | |
| 115 except ImportError: | |
| 116 pass | |
| 117 else: | |
| 118 class BDistWheel(wheel.bdist_wheel.bdist_wheel): | |
| 119 def finalize_options(self): | |
| 120 # Synchronize this with Py_LIMITED_API | |
| 121 self.py_limited_api = 'cp37' | |
| 122 super().finalize_options() | |
| 123 | |
| 124 cmdclass["bdist_wheel"] = BDistWheel | |
| 125 else: | |
| 126 | |
| 127 if not os.path.isfile("configmix/_speedups.pyd"): | |
| 128 raise RuntimeError("no _speedups.pyd found") | |
| 129 | |
| 130 if os.path.isdir("ConfigMix.egg-info"): | |
| 131 raise RuntimeError("please remove ConfigMix.egg-info before") | |
| 132 | |
| 133 setup_extra_kwds["package_data"] = { | |
| 134 "configmix": ["*.pyd"] | |
| 135 } | |
| 136 | |
| 137 ext_modules = [] | |
| 138 | |
| 139 py_limited_api = True | |
| 87 | 140 |
| 88 if py_limited_api: | 141 if py_limited_api: |
| 89 # | 142 # |
| 90 # Build a wheel that is properly named using the stable API | 143 # Build a wheel that is properly named using the stable API |
| 91 # | 144 # |
| 92 try: | 145 try: |
| 93 import wheel.bdist_wheel | 146 import wheel.bdist_wheel |
| 94 except ImportError: | 147 except ImportError: |
| 95 cmdclass = {} | 148 pass |
| 96 else: | 149 else: |
| 97 class BDistWheel(wheel.bdist_wheel.bdist_wheel): | 150 class BDistWheel(wheel.bdist_wheel.bdist_wheel): |
| 98 def finalize_options(self): | 151 def finalize_options(self): |
| 99 # Synchronize this with Py_LIMITED_API | 152 # Synchronize this with Py_LIMITED_API |
| 100 self.py_limited_api = 'cp37' | 153 self.py_limited_api = 'cp37' |
| 101 super().finalize_options() | 154 super().finalize_options() |
| 102 | 155 |
| 103 cmdclass = {'bdist_wheel': BDistWheel} | 156 cmdclass["bdist_wheel"] = BDistWheel |
| 104 | 157 |
| 105 if ext_modules: | 158 from setuptools.dist import Distribution |
| 159 | |
| 160 # | |
| 161 # Force a binary package. An empty ext_modules does not do this always. | |
| 162 # Tested with wheel v0.29.0 | |
| 163 # | |
| 164 class BinaryDistribution(Distribution): | |
| 165 """Distribution which always forces a binary package with | |
| 166 | |
| 167 platform name | |
| 168 | |
| 169 """ | |
| 170 def has_ext_modules(foo): | |
| 171 return True | |
| 172 | |
| 173 setup_extra_kwds["distclass"] = BinaryDistribution | |
| 174 | |
| 175 | |
| 176 if ext_modules is not None: | |
| 106 setup_extra_kwds["ext_modules"] = ext_modules | 177 setup_extra_kwds["ext_modules"] = ext_modules |
| 107 setup_extra_kwds["zip_safe"] = False | 178 setup_extra_kwds["zip_safe"] = False |
| 108 else: | 179 else: |
| 109 setup_extra_kwds["zip_safe"] = True | 180 setup_extra_kwds["zip_safe"] = True |
| 110 if cmdclass: | 181 if cmdclass: |
| 119 description="Library for extended configuration files", | 190 description="Library for extended configuration files", |
| 120 long_description=long_description, | 191 long_description=long_description, |
| 121 long_description_content_type="text/x-rst", | 192 long_description_content_type="text/x-rst", |
| 122 packages=["configmix", | 193 packages=["configmix", |
| 123 "configmix.extras"], | 194 "configmix.extras"], |
| 195 # | |
| 196 # Use non-automatic explicit package_data instead | |
| 197 # (or MANIFEST.in for sdist) | |
| 198 # | |
| 124 include_package_data=False, | 199 include_package_data=False, |
| 125 platforms="any", | 200 platforms="any", |
| 126 classifiers=[ | 201 classifiers=[ |
| 127 "Development Status :: 5 - Production/Stable", | 202 "Development Status :: 5 - Production/Stable", |
| 128 "Environment :: Console", | 203 "Environment :: Console", |
| 135 "Programming Language :: Python :: 3", | 210 "Programming Language :: Python :: 3", |
| 136 "Topic :: Software Development :: Libraries :: Python Modules" | 211 "Topic :: Software Development :: Libraries :: Python Modules" |
| 137 ], | 212 ], |
| 138 python_requires=">=2.6", | 213 python_requires=">=2.6", |
| 139 extras_require={ | 214 extras_require={ |
| 140 "aws" : aws_requirements, | 215 "aws": aws_requirements, # noqa: E241 |
| 141 "toml": toml_requirements, | 216 "toml": toml_requirements, |
| 142 "yaml": yaml_requirements, | 217 "yaml": yaml_requirements, |
| 143 "all" : all_requirements, | 218 "all": all_requirements, # noqa: E241 |
| 144 }, | 219 }, |
| 145 tests_require=all_requirements, | 220 tests_require=all_requirements, |
| 146 **setup_extra_kwds | 221 **setup_extra_kwds |
| 147 ) | 222 ) |
