Skip to content

Commit 99e99e9

Browse files
committed
BLD: finish handling of setuptools commands.
Also ignore setup.cfg: this file is created/modified by the alias/setopt/saveopts commands, and therefore needs to be in .gitignore.
1 parent 983eb78 commit 99e99e9

File tree

2 files changed

+90
-26
lines changed

2 files changed

+90
-26
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ numpy/core/include/numpy/__ufunc_api.h
105105
numpy/core/include/numpy/_numpyconfig.h
106106
numpy/version.py
107107
site.cfg
108+
setup.cfg
108109
.tox
109110
numpy/core/include/numpy/__multiarray_api.c
110111
numpy/core/include/numpy/__ufunc_api.c

setup.py

+89-26
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import os
2121
import sys
2222
import subprocess
23+
import textwrap
2324

2425

2526
if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[0:2] < (3, 2):
@@ -205,23 +206,74 @@ def generate_cython():
205206

206207

207208
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+
"""
209214
if len(sys.argv) < 2:
210215
# 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
212231

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',
220237
'bdist_wininst', 'bdist_msi', 'bdist_mpkg')
238+
221239
for command in good_commands:
222240
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.
225277
bad_commands = dict(
226278
test="""
227279
`setup.py test` is not supported. Use one of the following
@@ -249,17 +301,30 @@ def parse_setuppy_commands():
249301
check="`setup.py check` is not supported",
250302
register="`setup.py register` is not supported",
251303
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",
253309
)
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+
254316
for command in bad_commands.keys():
255317
if command in sys.argv[1:]:
256-
import textwrap
257318
print(textwrap.dedent(bad_commands[command]) +
258319
"\nAdd `--force` to your command to use it anyway if you "
259320
"must (unsupported).\n")
260321
sys.exit(1)
261322

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
263328

264329

265330
def setup_package():
@@ -287,27 +352,25 @@ def setup_package():
287352
cmdclass={"sdist": sdist_checked},
288353
)
289354

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()
292360

293361
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:
304363
from numpy.distutils.core import setup
305364
cwd = os.path.abspath(os.path.dirname(__file__))
306365
if not os.path.exists(os.path.join(cwd, 'PKG-INFO')):
307366
# Generate Cython sources, unless building from source release
308367
generate_cython()
309368

310369
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]
311374

312375
try:
313376
setup(**metadata)

0 commit comments

Comments
 (0)