7
7
"""
8
8
9
9
import argparse
10
+ from distutils .command .build import build
10
11
from distutils .sysconfig import get_config_vars
11
12
from distutils .version import LooseVersion
12
13
import multiprocessing
16
17
import shutil
17
18
import sys
18
19
19
- import pkg_resources
20
- from setuptools import Command , find_packages , setup
20
+ import numpy
21
+ from setuptools import Command , Extension , find_packages , setup
22
+ from setuptools .command .build_ext import build_ext as _build_ext
21
23
22
- # versioning
23
24
import versioneer
24
25
25
26
cmdclass = versioneer .get_cmdclass ()
@@ -37,9 +38,7 @@ def is_platform_mac():
37
38
min_cython_ver = "0.29.21" # note: sync with pyproject.toml
38
39
39
40
try :
40
- import Cython
41
-
42
- _CYTHON_VERSION = Cython .__version__
41
+ from Cython import Tempita , __version__ as _CYTHON_VERSION
43
42
from Cython .Build import cythonize
44
43
45
44
_CYTHON_INSTALLED = _CYTHON_VERSION >= LooseVersion (min_cython_ver )
@@ -48,22 +47,6 @@ def is_platform_mac():
48
47
_CYTHON_INSTALLED = False
49
48
cythonize = lambda x , * args , ** kwargs : x # dummy func
50
49
51
- # The import of Extension must be after the import of Cython, otherwise
52
- # we do not get the appropriately patched class.
53
- # See https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html # noqa
54
- from distutils .extension import Extension # isort:skip
55
- from distutils .command .build import build # isort:skip
56
-
57
- if _CYTHON_INSTALLED :
58
- from Cython .Distutils .old_build_ext import old_build_ext as _build_ext
59
-
60
- cython = True
61
- from Cython import Tempita as tempita
62
- else :
63
- from distutils .command .build_ext import build_ext as _build_ext
64
-
65
- cython = False
66
-
67
50
68
51
_pxi_dep_template = {
69
52
"algos" : ["_libs/algos_common_helper.pxi.in" , "_libs/algos_take_helper.pxi.in" ],
@@ -101,15 +84,15 @@ def render_templates(cls, pxifiles):
101
84
102
85
with open (pxifile ) as f :
103
86
tmpl = f .read ()
104
- pyxcontent = tempita .sub (tmpl )
87
+ pyxcontent = Tempita .sub (tmpl )
105
88
106
89
with open (outfile , "w" ) as f :
107
90
f .write (pyxcontent )
108
91
109
92
def build_extensions (self ):
110
93
# if building from c files, don't need to
111
94
# generate template output
112
- if cython :
95
+ if _CYTHON_INSTALLED :
113
96
self .render_templates (_pxifiles )
114
97
115
98
super ().build_extensions ()
@@ -404,7 +387,7 @@ def run(self):
404
387
cmdclass .update ({"clean" : CleanCommand , "build" : build })
405
388
cmdclass ["build_ext" ] = CheckingBuildExt
406
389
407
- if cython :
390
+ if _CYTHON_INSTALLED :
408
391
suffix = ".pyx"
409
392
cmdclass ["cython" ] = CythonCommand
410
393
else :
@@ -477,18 +460,10 @@ def run(self):
477
460
directives ["linetrace" ] = True
478
461
macros = [("CYTHON_TRACE" , "1" ), ("CYTHON_TRACE_NOGIL" , "1" )]
479
462
480
- # in numpy>=1.16.0, silence build warnings about deprecated API usage
481
- # we can't do anything about these warnings because they stem from
482
- # cython+numpy version mismatches.
463
+ # silence build warnings about deprecated API usage
464
+ # we can't do anything about these warnings because they stem from
465
+ # cython+numpy version mismatches.
483
466
macros .append (("NPY_NO_DEPRECATED_API" , "0" ))
484
- if "-Werror" in extra_compile_args :
485
- try :
486
- import numpy as np
487
- except ImportError :
488
- pass
489
- else :
490
- if np .__version__ < LooseVersion ("1.16.0" ):
491
- extra_compile_args .remove ("-Werror" )
492
467
493
468
494
469
# ----------------------------------------------------------------------
@@ -507,7 +482,7 @@ def maybe_cythonize(extensions, *args, **kwargs):
507
482
# See https://github.com/cython/cython/issues/1495
508
483
return extensions
509
484
510
- elif not cython :
485
+ elif not _CYTHON_INSTALLED :
511
486
# GH#28836 raise a helfpul error message
512
487
if _CYTHON_VERSION :
513
488
raise RuntimeError (
@@ -516,25 +491,12 @@ def maybe_cythonize(extensions, *args, **kwargs):
516
491
)
517
492
raise RuntimeError ("Cannot cythonize without Cython installed." )
518
493
519
- numpy_incl = pkg_resources .resource_filename ("numpy" , "core/include" )
520
- # TODO: Is this really necessary here?
521
- for ext in extensions :
522
- if hasattr (ext , "include_dirs" ) and numpy_incl not in ext .include_dirs :
523
- ext .include_dirs .append (numpy_incl )
524
-
525
494
# reuse any parallel arguments provided for compilation to cythonize
526
495
parser = argparse .ArgumentParser ()
527
- parser .add_argument ("-j" , type = int )
528
- parser .add_argument ("--parallel" , type = int )
496
+ parser .add_argument ("--parallel" , "-j" , type = int , default = 1 )
529
497
parsed , _ = parser .parse_known_args ()
530
498
531
- nthreads = 0
532
- if parsed .parallel :
533
- nthreads = parsed .parallel
534
- elif parsed .j :
535
- nthreads = parsed .j
536
-
537
- kwargs ["nthreads" ] = nthreads
499
+ kwargs ["nthreads" ] = parsed .parallel
538
500
build_ext .render_templates (_pxifiles )
539
501
return cythonize (extensions , * args , ** kwargs )
540
502
@@ -679,7 +641,8 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):
679
641
680
642
sources .extend (data .get ("sources" , []))
681
643
682
- include = data .get ("include" )
644
+ include = data .get ("include" , [])
645
+ include .append (numpy .get_include ())
683
646
684
647
obj = Extension (
685
648
f"pandas.{ name } " ,
@@ -728,6 +691,7 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):
728
691
"pandas/_libs/src/ujson/python" ,
729
692
"pandas/_libs/src/ujson/lib" ,
730
693
"pandas/_libs/src/datetime" ,
694
+ numpy .get_include (),
731
695
],
732
696
extra_compile_args = (["-D_GNU_SOURCE" ] + extra_compile_args ),
733
697
extra_link_args = extra_link_args ,
0 commit comments