Skip to content

Commit 846249f

Browse files
committed
Move {setup,install}_requires from setupext.py to setup.py.
The Numpy class in setupext.py serves two purposes: declare a setup_requires and an install_requires on numpy, and provide a add_flags() (effectively static) method to link extension modules to numpy. Instead, we can just merge the setup and install_requires together with all other install_requires, and move all of them to setup.py (deleting the machinery to grab setup_requires and install_requires from multiple places), and make the add_flags() method a free function (add_numpy_flags()).
1 parent 28e32c6 commit 846249f

File tree

2 files changed

+45
-82
lines changed

2 files changed

+45
-82
lines changed

setup.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
setupext.Matplotlib(),
6161
setupext.Python(),
6262
setupext.Platform(),
63-
setupext.Numpy(),
6463
setupext.LibAgg(),
6564
setupext.FreeType(),
6665
setupext.FT2Font(),
@@ -178,21 +177,13 @@ def run(self):
178177
packages = []
179178
namespace_packages = []
180179
py_modules = []
181-
# Dummy extension to trigger build_ext, which will swap it out with real
182-
# extensions that can depend on numpy for the build.
183-
ext_modules = [Extension('', [])]
184180
package_data = {}
185-
package_dir = {'': 'lib'}
186-
install_requires = []
187-
setup_requires = []
188181

189182
# If the user just queries for information, don't bother figuring out which
190183
# packages to build or install.
191-
if (any('--' + opt in sys.argv for opt in
192-
Distribution.display_option_names + ['help']) or
193-
'clean' in sys.argv):
194-
setup_requires = []
195-
else:
184+
if not (any('--' + opt in sys.argv
185+
for opt in [*Distribution.display_option_names, 'help'])
186+
or 'clean' in sys.argv):
196187
# Go through all of the packages and figure out which ones we are
197188
# going to build/install.
198189
print_line()
@@ -245,8 +236,6 @@ def run(self):
245236
for key, val in data.items():
246237
package_data.setdefault(key, [])
247238
package_data[key] = list(set(val + package_data[key]))
248-
install_requires.extend(package.get_install_requires())
249-
setup_requires.extend(package.get_setup_requires())
250239

251240
# Write the default matplotlibrc file
252241
with open('matplotlibrc.template') as fd:
@@ -268,6 +257,12 @@ def run(self):
268257
author="John D. Hunter, Michael Droettboom",
269258
author_email="matplotlib-users@python.org",
270259
url="https://matplotlib.org",
260+
download_url="https://matplotlib.org/users/installing.html",
261+
project_urls={
262+
'Bug Tracker': 'https://github.com/matplotlib/matplotlib/issues',
263+
'Documentation': 'https://matplotlib.org/contents.html',
264+
'Source Code': 'https://github.com/matplotlib/matplotlib'
265+
},
271266
long_description="""
272267
Matplotlib strives to produce publication quality 2D graphics
273268
for interactive graphing, scientific publishing, user interface
@@ -279,21 +274,24 @@ def run(self):
279274
namespace_packages=namespace_packages,
280275
platforms='any',
281276
py_modules=py_modules,
282-
ext_modules=ext_modules,
283-
package_dir=package_dir,
277+
# Dummy extension to trigger build_ext, which will swap it out with
278+
# real extensions that can depend on numpy for the build.
279+
ext_modules=[Extension("", [])],
280+
package_dir={"": "lib"},
284281
package_data=package_data,
285282
classifiers=classifiers,
286-
download_url="https://matplotlib.org/users/installing.html",
287-
project_urls={
288-
'Bug Tracker': 'https://github.com/matplotlib/matplotlib/issues',
289-
'Documentation': 'https://matplotlib.org/contents.html',
290-
'Source Code': 'https://github.com/matplotlib/matplotlib'
291-
},
292283

293284
python_requires='>={}'.format('.'.join(str(n) for n in min_version)),
294-
# List third-party Python packages that we require
295-
install_requires=install_requires,
296-
setup_requires=setup_requires,
285+
setup_requires=[
286+
"numpy>=1.11",
287+
],
288+
install_requires=[
289+
"cycler>=0.10",
290+
"kiwisolver>=1.0.1",
291+
"numpy>=1.11",
292+
"pyparsing>=2.0.1,!=2.0.4,!=2.1.2,!=2.1.6",
293+
"python-dateutil>=2.1",
294+
],
297295

298296
# matplotlib has C/C++ extensions, so it's not zip safe.
299297
# Telling setuptools this prevents it from doing an automatic

setupext.py

Lines changed: 22 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -353,22 +353,6 @@ def get_extension(self):
353353
"""
354354
return None
355355

356-
def get_install_requires(self):
357-
"""
358-
Get a list of Python packages that we require.
359-
pip/easy_install will attempt to download and install this
360-
package if it is not installed.
361-
"""
362-
return []
363-
364-
def get_setup_requires(self):
365-
"""
366-
Get a list of Python packages that we require at build time.
367-
pip/easy_install will attempt to download and install this
368-
package if it is not installed.
369-
"""
370-
return []
371-
372356
def do_custom_build(self):
373357
"""
374358
If a package needs to do extra custom things, such as building a
@@ -544,14 +528,6 @@ def get_package_data(self):
544528
],
545529
}
546530

547-
def get_install_requires(self):
548-
return [
549-
"cycler>=0.10",
550-
"kiwisolver>=1.0.1",
551-
"pyparsing>=2.0.1,!=2.0.4,!=2.1.2,!=2.1.6",
552-
"python-dateutil>=2.1",
553-
]
554-
555531

556532
class SampleData(OptionalPackage):
557533
"""
@@ -591,27 +567,18 @@ def get_package_data(self):
591567
}
592568

593569

594-
class Numpy(SetupPackage):
595-
name = "numpy"
596-
597-
def add_flags(self, ext):
598-
import numpy as np
599-
ext.include_dirs.append(np.get_include())
600-
ext.define_macros.extend([
601-
# Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for each
602-
# extension.
603-
('PY_ARRAY_UNIQUE_SYMBOL',
604-
'MPL_' + ext.name.replace('.', '_') + '_ARRAY_API'),
605-
('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION'),
606-
# Allow NumPy's printf format specifiers in C++.
607-
('__STDC_FORMAT_MACROS', 1),
608-
])
609-
610-
def get_setup_requires(self):
611-
return ['numpy>=1.11']
612-
613-
def get_install_requires(self):
614-
return ['numpy>=1.11']
570+
def add_numpy_flags(ext):
571+
import numpy as np
572+
ext.include_dirs.append(np.get_include())
573+
ext.define_macros.extend([
574+
# Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for each
575+
# extension.
576+
('PY_ARRAY_UNIQUE_SYMBOL',
577+
'MPL_' + ext.name.replace('.', '_') + '_ARRAY_API'),
578+
('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION'),
579+
# Allow NumPy's printf format specifiers in C++.
580+
('__STDC_FORMAT_MACROS', 1),
581+
])
615582

616583

617584
class LibAgg(SetupPackage):
@@ -794,7 +761,7 @@ def get_extension(self):
794761
]
795762
ext = Extension('matplotlib.ft2font', sources)
796763
FreeType().add_flags(ext)
797-
Numpy().add_flags(ext)
764+
add_numpy_flags(ext)
798765
LibAgg().add_flags(ext, add_sources=False)
799766
return ext
800767

@@ -822,7 +789,7 @@ def get_extension(self):
822789
atleast_version='1.2',
823790
alt_exec=['libpng-config', '--ldflags'],
824791
default_libraries=['png', 'z'])
825-
Numpy().add_flags(ext)
792+
add_numpy_flags(ext)
826793
return ext
827794

828795

@@ -850,7 +817,7 @@ def get_extension(self):
850817
'extern/ttconv/ttutil.cpp'
851818
]
852819
ext = Extension('matplotlib.ttconv', sources)
853-
Numpy().add_flags(ext)
820+
add_numpy_flags(ext)
854821
ext.include_dirs.insert(0, 'extern')
855822
return ext
856823

@@ -863,9 +830,8 @@ def get_extension(self):
863830
'src/py_converters.cpp',
864831
'src/_path_wrapper.cpp'
865832
]
866-
867833
ext = Extension('matplotlib._path', sources)
868-
Numpy().add_flags(ext)
834+
add_numpy_flags(ext)
869835
LibAgg().add_flags(ext)
870836
return ext
871837

@@ -881,7 +847,7 @@ def get_extension(self):
881847
'src/py_converters.cpp'
882848
]
883849
ext = Extension('matplotlib._image', sources)
884-
Numpy().add_flags(ext)
850+
add_numpy_flags(ext)
885851
LibAgg().add_flags(ext)
886852

887853
return ext
@@ -897,7 +863,7 @@ def get_extension(self):
897863
'src/py_converters.cpp',
898864
]
899865
ext = Extension('matplotlib._contour', sources)
900-
Numpy().add_flags(ext)
866+
add_numpy_flags(ext)
901867
LibAgg().add_flags(ext, add_sources=False)
902868
return ext
903869

@@ -909,7 +875,7 @@ def get_extension(self):
909875
sources = ['src/qhull_wrap.c']
910876
ext = Extension('matplotlib._qhull', sources,
911877
define_macros=[('MPL_DEVNULL', os.devnull)])
912-
Numpy().add_flags(ext)
878+
add_numpy_flags(ext)
913879
Qhull().add_flags(ext)
914880
return ext
915881

@@ -924,7 +890,7 @@ def get_extension(self):
924890
"src/mplutils.cpp"
925891
]
926892
ext = Extension('matplotlib._tri', sources)
927-
Numpy().add_flags(ext)
893+
add_numpy_flags(ext)
928894
return ext
929895

930896

@@ -940,7 +906,7 @@ def get_extension(self):
940906
"src/_backend_agg_wrapper.cpp"
941907
]
942908
ext = Extension('matplotlib.backends._backend_agg', sources)
943-
Numpy().add_flags(ext)
909+
add_numpy_flags(ext)
944910
LibAgg().add_flags(ext)
945911
FreeType().add_flags(ext)
946912
return ext
@@ -961,7 +927,7 @@ def get_extension(self):
961927

962928
ext = Extension('matplotlib.backends._tkagg', sources)
963929
self.add_flags(ext)
964-
Numpy().add_flags(ext)
930+
add_numpy_flags(ext)
965931
LibAgg().add_flags(ext, add_sources=False)
966932
return ext
967933

@@ -989,7 +955,6 @@ def get_extension(self):
989955
sources = [
990956
'src/_macosx.m'
991957
]
992-
993958
ext = Extension('matplotlib.backends._macosx', sources)
994959
ext.extra_link_args.extend(['-framework', 'Cocoa'])
995960
if platform.python_implementation().lower() == 'pypy':

0 commit comments

Comments
 (0)