|
165 | 165 | },
|
166 | 166 | setup_requires=[
|
167 | 167 | # version compatibility
|
168 |
| - #'bpc-f2format; python_version < "3.6"', |
169 | 168 | 'f2format; python_version < "3.6"',
|
170 |
| - #'bpc-walrus; python_version < "3.8"', |
171 |
| - 'python-walrus==0.1.5rc1; python_version < "3.8"', |
| 169 | + 'bpc-walrus; python_version < "3.8"', |
172 | 170 | 'pathlib2>=2.3.2; python_version == "3.4"',
|
173 | 171 | ]
|
174 | 172 | )
|
175 | 173 |
|
| 174 | + |
| 175 | +def refactor() -> 'None': |
| 176 | + """Refactor code.""" |
| 177 | + if version_info < (3, 6): |
| 178 | + try: |
| 179 | + subprocess.check_call( # nosec |
| 180 | + [sys.executable, '-m', 'f2format', '--no-archive', 'pcapkit'] |
| 181 | + ) |
| 182 | + except subprocess.CalledProcessError as error: |
| 183 | + print('Failed to perform assignment expression backport compiling.' |
| 184 | + 'Please consider manually install `bpc-f2format` and try again.', file=sys.stderr) |
| 185 | + sys.exit(error.returncode) |
| 186 | + |
| 187 | + if version_info < (3, 8): |
| 188 | + try: |
| 189 | + subprocess.check_call( # nosec |
| 190 | + [sys.executable, '-m', 'walrus', '--no-archive', 'pcapkit'] |
| 191 | + ) |
| 192 | + except subprocess.CalledProcessError as error: |
| 193 | + print('Failed to perform assignment expression backport compiling.' |
| 194 | + 'Please consider manually install `bpc-walrus` and try again.', file=sys.stderr) |
| 195 | + sys.exit(error.returncode) |
| 196 | + |
| 197 | + |
176 | 198 | try:
|
177 | 199 | from setuptools import setup
|
178 |
| - from setuptools.command.build_py import build_py |
| 200 | + from setuptools.command.bdist_egg import bdist_egg as _bdist_egg |
| 201 | + from setuptools.command.build_py import build_py as _build_py |
| 202 | + from setuptools.command.develop import develop as _develop |
| 203 | + from setuptools.command.install import install as _install |
| 204 | + from setuptools.command.sdist import sdist as _sdist |
179 | 205 |
|
180 | 206 | version_info = sys.version_info[:2]
|
181 | 207 |
|
|
191 | 217 | python_requires='>=3.6',
|
192 | 218 | zip_safe=True, # type: ignore
|
193 | 219 | ))
|
| 220 | + |
| 221 | + |
| 222 | + class bdist_egg(_bdist_egg): |
| 223 | + """Add on-distribution backport code conversion.""" |
| 224 | + |
| 225 | + def run(self) -> 'None': |
| 226 | + """Run command.""" |
| 227 | + refactor() |
| 228 | + _bdist_egg.run(self) |
| 229 | + |
| 230 | + |
| 231 | + class develop(_develop): |
| 232 | + """Add on-develop backport code conversion.""" |
| 233 | + |
| 234 | + def run(self) -> 'None': |
| 235 | + """Run command.""" |
| 236 | + refactor() |
| 237 | + _develop.run(self) |
| 238 | + |
| 239 | + |
| 240 | + cmdclass = { |
| 241 | + 'bdist_egg': bdist_egg, |
| 242 | + 'develop': develop, |
| 243 | + } |
| 244 | + |
194 | 245 | except ImportError:
|
195 | 246 | from distutils.core import setup # pylint: disable=deprecated-module
|
196 |
| - from distutils.command.build_py import build_py # pylint: disable=deprecated-module |
| 247 | + from distutils.command.bdist import bdist as _bdist # pylint: disable=deprecated-module |
| 248 | + from distutils.command.build_py import build_py as _build_py # pylint: disable=deprecated-module |
| 249 | + from distutils.command.install import install as _install # pylint: disable=deprecated-module |
| 250 | + from distutils.command.sdist import sdist as _sdist # pylint: disable=deprecated-module |
| 251 | + |
| 252 | + |
| 253 | + class bdist(_bdist): |
| 254 | + """Add on-distribution backport code conversion.""" |
| 255 | + |
| 256 | + def run(self) -> 'None': |
| 257 | + """Run command.""" |
| 258 | + refactor() |
| 259 | + _bdist.run(self) |
| 260 | + |
| 261 | + |
| 262 | + cmdclass = { |
| 263 | + 'bdist': bdist, |
| 264 | + } |
197 | 265 |
|
198 | 266 |
|
199 |
| -class build(build_py): |
| 267 | +try: |
| 268 | + from wheel.bdist_wheel import bdist_wheel as _bdist_wheel |
| 269 | + |
| 270 | + |
| 271 | + class bdist_wheel(_bdist_wheel): |
| 272 | + """Add on-wheel backport code conversion.""" |
| 273 | + |
| 274 | + def run(self) -> 'None': |
| 275 | + """Run command.""" |
| 276 | + refactor() |
| 277 | + _bdist_wheel.run(self) |
| 278 | + |
| 279 | + |
| 280 | + cmdclass['bdist_wheel'] = bdist_wheel |
| 281 | +except ImportError: |
| 282 | + pass |
| 283 | + |
| 284 | + |
| 285 | +class build_py(_build_py): |
200 | 286 | """Add on-build backport code conversion."""
|
201 | 287 |
|
202 | 288 | def run(self) -> 'None':
|
203 |
| - if version_info < (3, 6): |
204 |
| - try: |
205 |
| - subprocess.check_call( # nosec |
206 |
| - [sys.executable, '-m', 'f2format', '--no-archive', 'pcapkit'] |
207 |
| - ) |
208 |
| - except subprocess.CalledProcessError as error: |
209 |
| - print('Failed to perform assignment expression backport compiling.' |
210 |
| - 'Please consider manually install `bpc-f2format` and try again.', file=sys.stderr) |
211 |
| - sys.exit(error.returncode) |
212 |
| - |
213 |
| - if version_info < (3, 8): |
214 |
| - try: |
215 |
| - subprocess.check_call( # nosec |
216 |
| - [sys.executable, '-m', 'walrus', '--no-archive', 'pcapkit'] |
217 |
| - ) |
218 |
| - except subprocess.CalledProcessError as error: |
219 |
| - print('Failed to perform assignment expression backport compiling.' |
220 |
| - 'Please consider manually install `bpc-walrus` and try again.', file=sys.stderr) |
221 |
| - sys.exit(error.returncode) |
222 |
| - build_py.run(self) |
| 289 | + refactor() |
| 290 | + _build_py.run(self) |
| 291 | + |
| 292 | + |
| 293 | +class install(_install): |
| 294 | + """Add on-install backport code conversion.""" |
| 295 | + |
| 296 | + def run(self) -> 'None': |
| 297 | + refactor() |
| 298 | + _install.run(self) |
| 299 | + |
| 300 | + |
| 301 | +class sdist(_sdist): |
| 302 | + """Add on-distribution backport code conversion.""" |
| 303 | + |
| 304 | + def run(self) -> 'None': |
| 305 | + refactor() |
| 306 | + _sdist.run(self) |
223 | 307 |
|
224 | 308 |
|
225 | 309 | # set-up script for pip distribution
|
226 | 310 | setup(cmdclass={
|
227 |
| - 'build_py': build, |
| 311 | + 'build_py': build_py, |
| 312 | + 'install': install, |
| 313 | + 'sdist': sdist, |
| 314 | + **cmdclass, |
228 | 315 | }, **attrs)
|
0 commit comments