|
20 | 20 | import os
|
21 | 21 | import sys
|
22 | 22 | import subprocess
|
| 23 | +import textwrap |
23 | 24 |
|
24 | 25 |
|
25 | 26 | if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[0:2] < (3, 2):
|
@@ -205,23 +206,74 @@ def generate_cython():
|
205 | 206 |
|
206 | 207 |
|
207 | 208 | def parse_setuppy_commands():
|
208 |
| - """Check the commands and respond appropriately. Disable broken commands.""" |
| 209 | + """Check the commands and respond appropriately. Disable broken commands. |
| 210 | +
|
| 211 | + Return a boolean value for whether or not to run the build or not (avoid |
| 212 | + parsing Cython and template files if False). |
| 213 | + """ |
209 | 214 | if len(sys.argv) < 2:
|
210 | 215 | # User forgot to give an argument probably, let setuptools handle that.
|
211 |
| - return |
| 216 | + return True |
| 217 | + |
| 218 | + info_commands = ['--help-commands', '--name', '--version', '-V', |
| 219 | + '--fullname', '--author', '--author-email', |
| 220 | + '--maintainer', '--maintainer-email', '--contact', |
| 221 | + '--contact-email', '--url', '--license', '--description', |
| 222 | + '--long-description', '--platforms', '--classifiers', |
| 223 | + '--keywords', '--provides', '--requires', '--obsoletes'] |
| 224 | + # Add commands that do more than print info, but also don't need Cython and |
| 225 | + # template parsing. |
| 226 | + info_commands.extend(['egg_info', 'install_egg_info', 'rotate']) |
| 227 | + |
| 228 | + for command in info_commands: |
| 229 | + if command in sys.argv[1:]: |
| 230 | + return False |
212 | 231 |
|
213 |
| - # TODO: 'alias' seems broken, but check after the rest works |
214 |
| - # TODO: 'rotate' command - not sure if it works or is useful |
215 |
| - # TODO: 'saveopts' and 'setopt' commands - not sure if they work or are useful |
216 |
| - # TODO: 'bdist_*' commands |
217 |
| - good_commands = ('--help-commands', 'egg_info', '--version', 'develop', |
218 |
| - 'install', 'install_egg_info', 'sdist', 'build', |
219 |
| - 'build_ext', 'build_clib', 'bdist_wheel', 'bdist_rpm', |
| 232 | + # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work |
| 233 | + # fine as they are, but are usually used together with one of the commands |
| 234 | + # below and not standalone. Hence they're not added to good_commands. |
| 235 | + good_commands = ('develop', 'sdist', 'build', 'build_ext', 'build_py', |
| 236 | + 'build_clib', 'buld_scripts', 'bdist_wheel', 'bdist_rpm', |
220 | 237 | 'bdist_wininst', 'bdist_msi', 'bdist_mpkg')
|
| 238 | + |
221 | 239 | for command in good_commands:
|
222 | 240 | if command in sys.argv[1:]:
|
223 |
| - return |
224 |
| - |
| 241 | + return True |
| 242 | + |
| 243 | + # The following commands are supported, but we need to show some more |
| 244 | + # useful messages to the user |
| 245 | + if 'install' in sys.argv[1:]: |
| 246 | + print(textwrap.dedent(""" |
| 247 | + Note: if you need reliable uninstall behavior, then install |
| 248 | + with pip instead of using `setup.py install`: |
| 249 | +
|
| 250 | + - `pip install .` (from a git repo or downloaded source |
| 251 | + release) |
| 252 | + - `pip install numpy` (last Numpy release on PyPi) |
| 253 | +
|
| 254 | + """)) |
| 255 | + return True |
| 256 | + |
| 257 | + if '--help' in sys.argv[1:] or '-h' in sys.argv[1]: |
| 258 | + print(textwrap.dedent(""" |
| 259 | + Numpy-specific help |
| 260 | + ------------------- |
| 261 | +
|
| 262 | + To install Numpy from here with reliable uninstall, we recommend |
| 263 | + that you use `pip install .`. To install the latest Numpy release |
| 264 | + from PyPi, use `pip install numpy`. |
| 265 | +
|
| 266 | + For help with build/installation issues, please ask on the |
| 267 | + numpy-discussion mailing list. If you are sure that you have run |
| 268 | + into a bug, please report it at https://github.com/numpy/numpy/issues. |
| 269 | +
|
| 270 | + Setuptools commands help |
| 271 | + ------------------------ |
| 272 | + """)) |
| 273 | + return False |
| 274 | + |
| 275 | + # The following commands aren't supported. They can only be executed when |
| 276 | + # the user explicitly adds a --force command-line argument. |
225 | 277 | bad_commands = dict(
|
226 | 278 | test="""
|
227 | 279 | `setup.py test` is not supported. Use one of the following
|
@@ -249,17 +301,30 @@ def parse_setuppy_commands():
|
249 | 301 | check="`setup.py check` is not supported",
|
250 | 302 | register="`setup.py register` is not supported",
|
251 | 303 | bdist_dumb="`setup.py bdist_dumb` is not supported",
|
252 |
| - |
| 304 | + bdist="`setup.py bdist` is not supported", |
| 305 | + build_sphinx=""" |
| 306 | + `setup.py build_sphinx` is not supported, use the |
| 307 | + Makefile under doc/""", |
| 308 | + flake8="`setup.py flake8` is not supported, use flake8 standalone", |
253 | 309 | )
|
| 310 | + bad_commands['nosetests'] = bad_commands['test'] |
| 311 | + for commands in ('upload_docs', 'easy_install', 'bdist', 'bdist_dumb', |
| 312 | + 'register', 'check', 'install_data', 'install_headers', |
| 313 | + 'install_lib', 'install_scripts', ): |
| 314 | + bad_commands[command] = "`setup.py %s` is not supported" % command |
| 315 | + |
254 | 316 | for command in bad_commands.keys():
|
255 | 317 | if command in sys.argv[1:]:
|
256 |
| - import textwrap |
257 | 318 | print(textwrap.dedent(bad_commands[command]) +
|
258 | 319 | "\nAdd `--force` to your command to use it anyway if you "
|
259 | 320 | "must (unsupported).\n")
|
260 | 321 | sys.exit(1)
|
261 | 322 |
|
262 |
| - modify_commands = dict() |
| 323 | + # If we got here, we didn't detect what setup.py command was given |
| 324 | + import warnings |
| 325 | + warnings.warn("Unrecognized setuptools command, proceeding with " |
| 326 | + "generating Cython sources and expanding templates") |
| 327 | + return True |
263 | 328 |
|
264 | 329 |
|
265 | 330 | def setup_package():
|
@@ -287,27 +352,25 @@ def setup_package():
|
287 | 352 | cmdclass={"sdist": sdist_checked},
|
288 | 353 | )
|
289 | 354 |
|
290 |
| - FULLVERSION, GIT_REVISION = get_version_info() |
291 |
| - metadata['version'] = FULLVERSION |
| 355 | + if "--force" in sys.argv: |
| 356 | + run_build = True |
| 357 | + else: |
| 358 | + # Raise errors for unsupported commands, improve help output, etc. |
| 359 | + run_build = parse_setuppy_commands() |
292 | 360 |
|
293 | 361 | from setuptools import setup
|
294 |
| - # Raise errors for unsupported commands, improve help output, etc. |
295 |
| - if not "--force" in sys.argv: |
296 |
| - parse_setuppy_commands() |
297 |
| - |
298 |
| - # Run build |
299 |
| - if len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or |
300 |
| - sys.argv[1] in ('--help-commands', 'egg_info', '--version', |
301 |
| - 'clean')): |
302 |
| - pass |
303 |
| - else: |
| 362 | + if run_build: |
304 | 363 | from numpy.distutils.core import setup
|
305 | 364 | cwd = os.path.abspath(os.path.dirname(__file__))
|
306 | 365 | if not os.path.exists(os.path.join(cwd, 'PKG-INFO')):
|
307 | 366 | # Generate Cython sources, unless building from source release
|
308 | 367 | generate_cython()
|
309 | 368 |
|
310 | 369 | metadata['configuration'] = configuration
|
| 370 | + else: |
| 371 | + # Version number is added to metadata inside configuration() if build |
| 372 | + # is run. |
| 373 | + metadata['version'] = get_version_info()[0] |
311 | 374 |
|
312 | 375 | try:
|
313 | 376 | setup(**metadata)
|
|
0 commit comments