Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7ad9109

Browse files
committed
Don't bother working out packages to install if user requests information from setup.py
1 parent 0487ec2 commit 7ad9109

File tree

1 file changed

+86
-85
lines changed

1 file changed

+86
-85
lines changed

setup.py

Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -166,96 +166,97 @@ def run(self):
166166
setup_requires = []
167167
default_backend = None
168168

169-
# Go through all of the packages and figure out which ones we are
170-
# going to build/install.
171-
print_line()
172-
print_raw("Edit setup.cfg to change the build options")
173-
174-
required_failed = []
175-
good_packages = []
176-
for package in mpl_packages:
177-
if isinstance(package, str):
178-
print_raw('')
179-
print_raw(package.upper())
180-
else:
181-
try:
182-
result = package.check()
183-
if result is not None:
184-
message = 'yes [%s]' % result
185-
print_status(package.name, message)
186-
except setupext.CheckFailed as e:
187-
msg = str(e).strip()
188-
if len(msg):
189-
print_status(package.name, 'no [%s]' % msg)
190-
else:
191-
print_status(package.name, 'no')
192-
if not package.optional:
193-
required_failed.append(package)
194-
else:
195-
good_packages.append(package)
196-
if isinstance(package, setupext.OptionalBackendPackage):
197-
if default_backend is None:
198-
default_backend = package.name
199-
print_raw('')
200-
201-
# Abort if any of the required packages can not be built.
202-
if required_failed:
169+
# If the user just queries for information, don't bother figuring out which
170+
# packages to build or install.
171+
if (any('--' + opt in sys.argv for opt in
172+
Distribution.display_option_names + ['help']) or
173+
'clean' in sys.argv):
174+
setup_requires = []
175+
else:
176+
# Go through all of the packages and figure out which ones we are
177+
# going to build/install.
203178
print_line()
204-
message = ("The following required packages can not "
205-
"be built: %s" %
206-
", ".join(x.name for x in required_failed))
207-
for pkg in required_failed:
208-
pkg_help = pkg.install_help_msg()
209-
if pkg_help:
210-
message += "\n* " + pkg_help
211-
print_message(message)
212-
sys.exit(1)
213-
214-
# Now collect all of the information we need to build all of the
215-
# packages.
216-
for package in good_packages:
217-
packages.extend(package.get_packages())
218-
namespace_packages.extend(package.get_namespace_packages())
219-
py_modules.extend(package.get_py_modules())
220-
ext = package.get_extension()
221-
if ext is not None:
222-
ext_modules.append(ext)
223-
data = package.get_package_data()
224-
for key, val in data.items():
225-
package_data.setdefault(key, [])
226-
package_data[key] = list(set(val + package_data[key]))
227-
install_requires.extend(package.get_install_requires())
228-
setup_requires.extend(package.get_setup_requires())
229-
230-
# Write the default matplotlibrc file
231-
if default_backend is None:
232-
default_backend = 'svg'
233-
if setupext.options['backend']:
234-
default_backend = setupext.options['backend']
235-
with open('matplotlibrc.template') as fd:
236-
template = fd.read()
237-
template = Template(template)
238-
with open('lib/matplotlib/mpl-data/matplotlibrc', 'w') as fd:
239-
fd.write(template.safe_substitute(TEMPLATE_BACKEND=default_backend))
240-
241-
# Build in verbose mode if requested
242-
if setupext.options['verbose']:
179+
print_raw("Edit setup.cfg to change the build options")
180+
181+
required_failed = []
182+
good_packages = []
183+
for package in mpl_packages:
184+
if isinstance(package, str):
185+
print_raw('')
186+
print_raw(package.upper())
187+
else:
188+
try:
189+
result = package.check()
190+
if result is not None:
191+
message = 'yes [%s]' % result
192+
print_status(package.name, message)
193+
except setupext.CheckFailed as e:
194+
msg = str(e).strip()
195+
if len(msg):
196+
print_status(package.name, 'no [%s]' % msg)
197+
else:
198+
print_status(package.name, 'no')
199+
if not package.optional:
200+
required_failed.append(package)
201+
else:
202+
good_packages.append(package)
203+
if isinstance(package, setupext.OptionalBackendPackage):
204+
if default_backend is None:
205+
default_backend = package.name
206+
print_raw('')
207+
208+
# Abort if any of the required packages can not be built.
209+
if required_failed:
210+
print_line()
211+
message = ("The following required packages can not "
212+
"be built: %s" %
213+
", ".join(x.name for x in required_failed))
214+
for pkg in required_failed:
215+
pkg_help = pkg.install_help_msg()
216+
if pkg_help:
217+
message += "\n* " + pkg_help
218+
print_message(message)
219+
sys.exit(1)
220+
221+
# Now collect all of the information we need to build all of the
222+
# packages.
223+
for package in good_packages:
224+
packages.extend(package.get_packages())
225+
namespace_packages.extend(package.get_namespace_packages())
226+
py_modules.extend(package.get_py_modules())
227+
ext = package.get_extension()
228+
if ext is not None:
229+
ext_modules.append(ext)
230+
data = package.get_package_data()
231+
for key, val in data.items():
232+
package_data.setdefault(key, [])
233+
package_data[key] = list(set(val + package_data[key]))
234+
install_requires.extend(package.get_install_requires())
235+
setup_requires.extend(package.get_setup_requires())
236+
237+
# Write the default matplotlibrc file
238+
if default_backend is None:
239+
default_backend = 'svg'
240+
if setupext.options['backend']:
241+
default_backend = setupext.options['backend']
242+
with open('matplotlibrc.template') as fd:
243+
template = fd.read()
244+
template = Template(template)
245+
with open('lib/matplotlib/mpl-data/matplotlibrc', 'w') as fd:
246+
fd.write(template.safe_substitute(TEMPLATE_BACKEND=default_backend))
247+
248+
# Build in verbose mode if requested
249+
if setupext.options['verbose']:
250+
for mod in ext_modules:
251+
mod.extra_compile_args.append('-DVERBOSE')
252+
253+
# Finalize the extension modules so they can get the Numpy include
254+
# dirs
243255
for mod in ext_modules:
244-
mod.extra_compile_args.append('-DVERBOSE')
245-
246-
# Finalize the extension modules so they can get the Numpy include
247-
# dirs
248-
for mod in ext_modules:
249-
mod.finalize()
256+
mod.finalize()
250257

251258
extra_args = {}
252259

253-
# Avoid installing setup_requires dependencies if the user just
254-
# queries for information
255-
if (any('--' + opt in sys.argv for opt in
256-
Distribution.display_option_names + ['help']) or
257-
'clean' in sys.argv):
258-
setup_requires = []
259260

260261
# Finally, pass this all along to distutils to do the heavy lifting.
261262
distrib = setup(

0 commit comments

Comments
 (0)