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

Skip to content

Commit cd8bb26

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 dce1dc3 commit cd8bb26

File tree

2 files changed

+40
-77
lines changed

2 files changed

+40
-77
lines changed

setup.py

Lines changed: 18 additions & 20 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,7 @@ def run(self):
268257
author="John D. Hunter, Michael Droettboom",
269258
author_email="[email protected]",
270259
url="http://matplotlib.org",
260+
download_url="http://matplotlib.org/users/installing.html",
271261
long_description="""
272262
Matplotlib strives to produce publication quality 2D graphics
273263
for interactive graphing, scientific publishing, user interface
@@ -279,16 +269,24 @@ def run(self):
279269
namespace_packages=namespace_packages,
280270
platforms='any',
281271
py_modules=py_modules,
282-
ext_modules=ext_modules,
283-
package_dir=package_dir,
272+
# Dummy extension to trigger build_ext, which will swap it out with
273+
# real extensions that can depend on numpy for the build.
274+
ext_modules=[Extension("", [])],
275+
package_dir={"": "lib"},
284276
package_data=package_data,
285277
classifiers=classifiers,
286-
download_url="http://matplotlib.org/users/installing.html",
287278

288279
python_requires='>={}'.format('.'.join(str(n) for n in min_version)),
289-
# List third-party Python packages that we require
290-
install_requires=install_requires,
291-
setup_requires=setup_requires,
280+
setup_requires=[
281+
"numpy>=1.11",
282+
],
283+
install_requires=[
284+
"cycler>=0.10",
285+
"kiwisolver>=1.0.1",
286+
"numpy>=1.11",
287+
"pyparsing>=2.0.1,!=2.0.4,!=2.1.2,!=2.1.6",
288+
"python-dateutil>=2.1",
289+
],
292290

293291
# matplotlib has C/C++ extensions, so it's not zip safe.
294292
# 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
@@ -360,22 +360,6 @@ def get_extension(self):
360360
"""
361361
return None
362362

363-
def get_install_requires(self):
364-
"""
365-
Get a list of Python packages that we require.
366-
pip/easy_install will attempt to download and install this
367-
package if it is not installed.
368-
"""
369-
return []
370-
371-
def get_setup_requires(self):
372-
"""
373-
Get a list of Python packages that we require at build time.
374-
pip/easy_install will attempt to download and install this
375-
package if it is not installed.
376-
"""
377-
return []
378-
379363
def do_custom_build(self):
380364
"""
381365
If a package needs to do extra custom things, such as building a
@@ -551,14 +535,6 @@ def get_package_data(self):
551535
],
552536
}
553537

554-
def get_install_requires(self):
555-
return [
556-
"cycler>=0.10",
557-
"kiwisolver>=1.0.1",
558-
"pyparsing>=2.0.1,!=2.0.4,!=2.1.2,!=2.1.6",
559-
"python-dateutil>=2.1",
560-
]
561-
562538

563539
class SampleData(OptionalPackage):
564540
"""
@@ -600,27 +576,18 @@ def get_package_data(self):
600576
}
601577

602578

603-
class Numpy(SetupPackage):
604-
name = "numpy"
605-
606-
def add_flags(self, ext):
607-
import numpy as np
608-
ext.include_dirs.append(np.get_include())
609-
ext.define_macros.extend([
610-
# Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for each
611-
# extension.
612-
('PY_ARRAY_UNIQUE_SYMBOL',
613-
'MPL_' + ext.name.replace('.', '_') + '_ARRAY_API'),
614-
('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION'),
615-
# Allow NumPy's printf format specifiers in C++.
616-
('__STDC_FORMAT_MACROS', 1),
617-
])
618-
619-
def get_setup_requires(self):
620-
return ['numpy>=1.11']
621-
622-
def get_install_requires(self):
623-
return ['numpy>=1.11']
579+
def add_numpy_flags(ext):
580+
import numpy as np
581+
ext.include_dirs.append(np.get_include())
582+
ext.define_macros.extend([
583+
# Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for each
584+
# extension.
585+
('PY_ARRAY_UNIQUE_SYMBOL',
586+
'MPL_' + ext.name.replace('.', '_') + '_ARRAY_API'),
587+
('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION'),
588+
# Allow NumPy's printf format specifiers in C++.
589+
('__STDC_FORMAT_MACROS', 1),
590+
])
624591

625592

626593
class LibAgg(SetupPackage):
@@ -803,7 +770,7 @@ def get_extension(self):
803770
]
804771
ext = Extension('matplotlib.ft2font', sources)
805772
FreeType().add_flags(ext)
806-
Numpy().add_flags(ext)
773+
add_numpy_flags(ext)
807774
LibAgg().add_flags(ext, add_sources=False)
808775
return ext
809776

@@ -831,7 +798,7 @@ def get_extension(self):
831798
atleast_version='1.2',
832799
alt_exec=['libpng-config', '--ldflags'],
833800
default_libraries=['png', 'z'])
834-
Numpy().add_flags(ext)
801+
add_numpy_flags(ext)
835802
return ext
836803

837804

@@ -859,7 +826,7 @@ def get_extension(self):
859826
'extern/ttconv/ttutil.cpp'
860827
]
861828
ext = Extension('matplotlib.ttconv', sources)
862-
Numpy().add_flags(ext)
829+
add_numpy_flags(ext)
863830
ext.include_dirs.insert(0, 'extern')
864831
return ext
865832

@@ -872,9 +839,8 @@ def get_extension(self):
872839
'src/py_converters.cpp',
873840
'src/_path_wrapper.cpp'
874841
]
875-
876842
ext = Extension('matplotlib._path', sources)
877-
Numpy().add_flags(ext)
843+
add_numpy_flags(ext)
878844
LibAgg().add_flags(ext)
879845
return ext
880846

@@ -890,7 +856,7 @@ def get_extension(self):
890856
'src/py_converters.cpp'
891857
]
892858
ext = Extension('matplotlib._image', sources)
893-
Numpy().add_flags(ext)
859+
add_numpy_flags(ext)
894860
LibAgg().add_flags(ext)
895861

896862
return ext
@@ -906,7 +872,7 @@ def get_extension(self):
906872
'src/py_converters.cpp',
907873
]
908874
ext = Extension('matplotlib._contour', sources)
909-
Numpy().add_flags(ext)
875+
add_numpy_flags(ext)
910876
LibAgg().add_flags(ext, add_sources=False)
911877
return ext
912878

@@ -918,7 +884,7 @@ def get_extension(self):
918884
sources = ['src/qhull_wrap.c']
919885
ext = Extension('matplotlib._qhull', sources,
920886
define_macros=[('MPL_DEVNULL', os.devnull)])
921-
Numpy().add_flags(ext)
887+
add_numpy_flags(ext)
922888
Qhull().add_flags(ext)
923889
return ext
924890

@@ -933,7 +899,7 @@ def get_extension(self):
933899
"src/mplutils.cpp"
934900
]
935901
ext = Extension('matplotlib._tri', sources)
936-
Numpy().add_flags(ext)
902+
add_numpy_flags(ext)
937903
return ext
938904

939905

@@ -949,7 +915,7 @@ def get_extension(self):
949915
"src/_backend_agg_wrapper.cpp"
950916
]
951917
ext = Extension('matplotlib.backends._backend_agg', sources)
952-
Numpy().add_flags(ext)
918+
add_numpy_flags(ext)
953919
LibAgg().add_flags(ext)
954920
FreeType().add_flags(ext)
955921
return ext
@@ -970,7 +936,7 @@ def get_extension(self):
970936

971937
ext = Extension('matplotlib.backends._tkagg', sources)
972938
self.add_flags(ext)
973-
Numpy().add_flags(ext)
939+
add_numpy_flags(ext)
974940
LibAgg().add_flags(ext, add_sources=False)
975941
return ext
976942

@@ -998,7 +964,6 @@ def get_extension(self):
998964
sources = [
999965
'src/_macosx.m'
1000966
]
1001-
1002967
ext = Extension('matplotlib.backends._macosx', sources)
1003968
ext.extra_link_args.extend(['-framework', 'Cocoa'])
1004969
if platform.python_implementation().lower() == 'pypy':

0 commit comments

Comments
 (0)