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

Skip to content

Commit a9875d4

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 9a8df49 commit a9875d4

File tree

2 files changed

+40
-75
lines changed

2 files changed

+40
-75
lines changed

setup.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
setupext.Matplotlib(),
5959
setupext.Python(),
6060
setupext.Platform(),
61-
setupext.Numpy(),
6261
setupext.LibAgg(),
6362
setupext.FreeType(),
6463
setupext.FT2Font(),
@@ -176,21 +175,13 @@ def run(self):
176175
packages = []
177176
namespace_packages = []
178177
py_modules = []
179-
# Dummy extension to trigger build_ext, which will swap it out with real
180-
# extensions that can depend on numpy for the build.
181-
ext_modules = [Extension('', [])]
182178
package_data = {}
183-
package_dir = {'': 'lib'}
184-
install_requires = []
185-
setup_requires = []
186179

187180
# If the user just queries for information, don't bother figuring out which
188181
# packages to build or install.
189-
if (any('--' + opt in sys.argv for opt in
190-
Distribution.display_option_names + ['help']) or
191-
'clean' in sys.argv):
192-
setup_requires = []
193-
else:
182+
if not (any('--' + opt in sys.argv
183+
for opt in [*Distribution.display_option_names, 'help'])
184+
or 'clean' in sys.argv):
194185
# Go through all of the packages and figure out which ones we are
195186
# going to build/install.
196187
print_line()
@@ -243,8 +234,6 @@ def run(self):
243234
for key, val in data.items():
244235
package_data.setdefault(key, [])
245236
package_data[key] = list(set(val + package_data[key]))
246-
install_requires.extend(package.get_install_requires())
247-
setup_requires.extend(package.get_setup_requires())
248237

249238
# Write the default matplotlibrc file
250239
with open('matplotlibrc.template') as fd:
@@ -266,6 +255,7 @@ def run(self):
266255
author="John D. Hunter, Michael Droettboom",
267256
author_email="[email protected]",
268257
url="http://matplotlib.org",
258+
download_url="http://matplotlib.org/users/installing.html",
269259
long_description="""
270260
Matplotlib strives to produce publication quality 2D graphics
271261
for interactive graphing, scientific publishing, user interface
@@ -277,16 +267,24 @@ def run(self):
277267
namespace_packages=namespace_packages,
278268
platforms='any',
279269
py_modules=py_modules,
280-
ext_modules=ext_modules,
281-
package_dir=package_dir,
270+
# Dummy extension to trigger build_ext, which will swap it out with
271+
# real extensions that can depend on numpy for the build.
272+
ext_modules=[Extension("", [])],
273+
package_dir={"": "lib"},
282274
package_data=package_data,
283275
classifiers=classifiers,
284-
download_url="http://matplotlib.org/users/installing.html",
285276

286277
python_requires='>=3.6',
287-
# List third-party Python packages that we require
288-
install_requires=install_requires,
289-
setup_requires=setup_requires,
278+
setup_requires=[
279+
"numpy>=1.11",
280+
],
281+
install_requires=[
282+
"cycler>=0.10",
283+
"kiwisolver>=1.0.1",
284+
"numpy>=1.11",
285+
"pyparsing>=2.0.1,!=2.0.4,!=2.1.2,!=2.1.6",
286+
"python-dateutil>=2.1",
287+
],
290288

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

setupext.py

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -507,22 +507,6 @@ def get_extension(self):
507507
"""
508508
return None
509509

510-
def get_install_requires(self):
511-
"""
512-
Get a list of Python packages that we require.
513-
pip/easy_install will attempt to download and install this
514-
package if it is not installed.
515-
"""
516-
return []
517-
518-
def get_setup_requires(self):
519-
"""
520-
Get a list of Python packages that we require at build time.
521-
pip/easy_install will attempt to download and install this
522-
package if it is not installed.
523-
"""
524-
return []
525-
526510
def _check_for_pkg_config(self, package, include_file, min_version=None,
527511
version=None):
528512
"""
@@ -739,14 +723,6 @@ def get_package_data(self):
739723
],
740724
}
741725

742-
def get_install_requires(self):
743-
return [
744-
"cycler>=0.10",
745-
"kiwisolver>=1.0.1",
746-
"pyparsing>=2.0.1,!=2.0.4,!=2.1.2,!=2.1.6",
747-
"python-dateutil>=2.1",
748-
]
749-
750726

751727
class SampleData(OptionalPackage):
752728
"""
@@ -788,27 +764,18 @@ def get_package_data(self):
788764
}
789765

790766

791-
class Numpy(SetupPackage):
792-
name = "numpy"
793-
794-
def add_flags(self, ext):
795-
import numpy as np
796-
ext.include_dirs.append(np.get_include())
797-
ext.define_macros.extend([
798-
# Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for each
799-
# extension.
800-
('PY_ARRAY_UNIQUE_SYMBOL',
801-
'MPL_' + ext.name.replace('.', '_') + '_ARRAY_API'),
802-
('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION'),
803-
# Allow NumPy's printf format specifiers in C++.
804-
('__STDC_FORMAT_MACROS', 1),
805-
])
806-
807-
def get_setup_requires(self):
808-
return ['numpy>=1.11']
809-
810-
def get_install_requires(self):
811-
return ['numpy>=1.11']
767+
def add_numpy_flags(ext):
768+
import numpy as np
769+
ext.include_dirs.append(np.get_include())
770+
ext.define_macros.extend([
771+
# Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for each
772+
# extension.
773+
('PY_ARRAY_UNIQUE_SYMBOL',
774+
'MPL_' + ext.name.replace('.', '_') + '_ARRAY_API'),
775+
('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION'),
776+
# Allow NumPy's printf format specifiers in C++.
777+
('__STDC_FORMAT_MACROS', 1),
778+
])
812779

813780

814781
class LibAgg(SetupPackage):
@@ -993,7 +960,7 @@ def get_extension(self):
993960
]
994961
ext = make_extension('matplotlib.ft2font', sources)
995962
FreeType().add_flags(ext)
996-
Numpy().add_flags(ext)
963+
add_numpy_flags(ext)
997964
LibAgg().add_flags(ext, add_sources=False)
998965
return ext
999966

@@ -1019,7 +986,7 @@ def get_extension(self):
1019986
pkg_config.setup_extension(
1020987
ext, 'libpng', default_libraries=['png', 'z'],
1021988
alt_exec='libpng-config --ldflags')
1022-
Numpy().add_flags(ext)
989+
add_numpy_flags(ext)
1023990
return ext
1024991

1025992

@@ -1047,7 +1014,7 @@ def get_extension(self):
10471014
'extern/ttconv/ttutil.cpp'
10481015
]
10491016
ext = make_extension('matplotlib.ttconv', sources)
1050-
Numpy().add_flags(ext)
1017+
add_numpy_flags(ext)
10511018
ext.include_dirs.insert(0, 'extern')
10521019
return ext
10531020

@@ -1062,7 +1029,7 @@ def get_extension(self):
10621029
]
10631030

10641031
ext = make_extension('matplotlib._path', sources)
1065-
Numpy().add_flags(ext)
1032+
add_numpy_flags(ext)
10661033
LibAgg().add_flags(ext)
10671034
return ext
10681035

@@ -1078,7 +1045,7 @@ def get_extension(self):
10781045
'src/py_converters.cpp'
10791046
]
10801047
ext = make_extension('matplotlib._image', sources)
1081-
Numpy().add_flags(ext)
1048+
add_numpy_flags(ext)
10821049
LibAgg().add_flags(ext)
10831050

10841051
return ext
@@ -1094,7 +1061,7 @@ def get_extension(self):
10941061
'src/py_converters.cpp',
10951062
]
10961063
ext = make_extension('matplotlib._contour', sources)
1097-
Numpy().add_flags(ext)
1064+
add_numpy_flags(ext)
10981065
LibAgg().add_flags(ext, add_sources=False)
10991066
return ext
11001067

@@ -1106,7 +1073,7 @@ def get_extension(self):
11061073
sources = ['src/qhull_wrap.c']
11071074
ext = make_extension('matplotlib._qhull', sources,
11081075
define_macros=[('MPL_DEVNULL', os.devnull)])
1109-
Numpy().add_flags(ext)
1076+
add_numpy_flags(ext)
11101077
Qhull().add_flags(ext)
11111078
return ext
11121079

@@ -1121,7 +1088,7 @@ def get_extension(self):
11211088
"src/mplutils.cpp"
11221089
]
11231090
ext = make_extension('matplotlib._tri', sources)
1124-
Numpy().add_flags(ext)
1091+
add_numpy_flags(ext)
11251092
return ext
11261093

11271094

@@ -1137,7 +1104,7 @@ def get_extension(self):
11371104
"src/_backend_agg_wrapper.cpp"
11381105
]
11391106
ext = make_extension('matplotlib.backends._backend_agg', sources)
1140-
Numpy().add_flags(ext)
1107+
add_numpy_flags(ext)
11411108
LibAgg().add_flags(ext)
11421109
FreeType().add_flags(ext)
11431110
return ext
@@ -1158,7 +1125,7 @@ def get_extension(self):
11581125

11591126
ext = make_extension('matplotlib.backends._tkagg', sources)
11601127
self.add_flags(ext)
1161-
Numpy().add_flags(ext)
1128+
add_numpy_flags(ext)
11621129
LibAgg().add_flags(ext, add_sources=False)
11631130
return ext
11641131

0 commit comments

Comments
 (0)