Skip to content

CLN: clean setup.py #37732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 17 additions & 53 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import argparse
from distutils.command.build import build
from distutils.sysconfig import get_config_vars
from distutils.version import LooseVersion
import multiprocessing
Expand All @@ -16,10 +17,10 @@
import shutil
import sys

import pkg_resources
from setuptools import Command, find_packages, setup
import numpy
Copy link

@agon-shabi agon-shabi Jan 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fangchenli I think the addition of this line has broken my package (internal to my organisation) - what happens if one tries to install pandas without numpy already installed?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using python 3.6, and it appears that there's no wheel for it on PyPI (only 3.7+) - that, in conjunction with this change means when I pip install pandas the source distribution is downloaded and its setup.py run to determine its dependencies (as opposed to having them statically defined, as would be in a wheel), and the whole thing falls over :/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, you should pin pandas version to <=1.1.5. pandas stopped py3.6 support starting from 1.2.0. pandas and many other numpy based scientific libraries are moving toward NEP29. So, if your work heavily depends on the numpy ecosystem, it might be a good time to think about moving to py3.7+.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that seems the most sensible approach for me in the short term - thanks for the information, evidently I missed a memo 🙏

from setuptools import Command, Extension, find_packages, setup
from setuptools.command.build_ext import build_ext as _build_ext

# versioning
import versioneer

cmdclass = versioneer.get_cmdclass()
Expand All @@ -37,9 +38,7 @@ def is_platform_mac():
min_cython_ver = "0.29.21" # note: sync with pyproject.toml

try:
import Cython

_CYTHON_VERSION = Cython.__version__
from Cython import Tempita, __version__ as _CYTHON_VERSION
from Cython.Build import cythonize

_CYTHON_INSTALLED = _CYTHON_VERSION >= LooseVersion(min_cython_ver)
Expand All @@ -48,22 +47,6 @@ def is_platform_mac():
_CYTHON_INSTALLED = False
cythonize = lambda x, *args, **kwargs: x # dummy func

# The import of Extension must be after the import of Cython, otherwise
# we do not get the appropriately patched class.
# See https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html # noqa
from distutils.extension import Extension # isort:skip
from distutils.command.build import build # isort:skip

if _CYTHON_INSTALLED:
from Cython.Distutils.old_build_ext import old_build_ext as _build_ext

cython = True
from Cython import Tempita as tempita
else:
from distutils.command.build_ext import build_ext as _build_ext

cython = False


_pxi_dep_template = {
"algos": ["_libs/algos_common_helper.pxi.in", "_libs/algos_take_helper.pxi.in"],
Expand Down Expand Up @@ -101,15 +84,15 @@ def render_templates(cls, pxifiles):

with open(pxifile) as f:
tmpl = f.read()
pyxcontent = tempita.sub(tmpl)
pyxcontent = Tempita.sub(tmpl)

with open(outfile, "w") as f:
f.write(pyxcontent)

def build_extensions(self):
# if building from c files, don't need to
# generate template output
if cython:
if _CYTHON_INSTALLED:
self.render_templates(_pxifiles)

super().build_extensions()
Expand Down Expand Up @@ -404,7 +387,7 @@ def run(self):
cmdclass.update({"clean": CleanCommand, "build": build})
cmdclass["build_ext"] = CheckingBuildExt

if cython:
if _CYTHON_INSTALLED:
suffix = ".pyx"
cmdclass["cython"] = CythonCommand
else:
Expand Down Expand Up @@ -477,18 +460,10 @@ def run(self):
directives["linetrace"] = True
macros = [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")]

# in numpy>=1.16.0, silence build warnings about deprecated API usage
# we can't do anything about these warnings because they stem from
# cython+numpy version mismatches.
# silence build warnings about deprecated API usage
# we can't do anything about these warnings because they stem from
# cython+numpy version mismatches.
macros.append(("NPY_NO_DEPRECATED_API", "0"))
if "-Werror" in extra_compile_args:
try:
import numpy as np
except ImportError:
pass
else:
if np.__version__ < LooseVersion("1.16.0"):
extra_compile_args.remove("-Werror")


# ----------------------------------------------------------------------
Expand All @@ -507,7 +482,7 @@ def maybe_cythonize(extensions, *args, **kwargs):
# See https://github.com/cython/cython/issues/1495
return extensions

elif not cython:
elif not _CYTHON_INSTALLED:
# GH#28836 raise a helfpul error message
if _CYTHON_VERSION:
raise RuntimeError(
Expand All @@ -516,25 +491,12 @@ def maybe_cythonize(extensions, *args, **kwargs):
)
raise RuntimeError("Cannot cythonize without Cython installed.")

numpy_incl = pkg_resources.resource_filename("numpy", "core/include")
# TODO: Is this really necessary here?
for ext in extensions:
if hasattr(ext, "include_dirs") and numpy_incl not in ext.include_dirs:
ext.include_dirs.append(numpy_incl)

# reuse any parallel arguments provided for compilation to cythonize
parser = argparse.ArgumentParser()
parser.add_argument("-j", type=int)
parser.add_argument("--parallel", type=int)
parser.add_argument("--parallel", "-j", type=int, default=1)
parsed, _ = parser.parse_known_args()

nthreads = 0
if parsed.parallel:
nthreads = parsed.parallel
elif parsed.j:
nthreads = parsed.j

kwargs["nthreads"] = nthreads
kwargs["nthreads"] = parsed.parallel
build_ext.render_templates(_pxifiles)
return cythonize(extensions, *args, **kwargs)

Expand Down Expand Up @@ -679,7 +641,8 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):

sources.extend(data.get("sources", []))

include = data.get("include")
include = data.get("include", [])
include.append(numpy.get_include())

obj = Extension(
f"pandas.{name}",
Expand Down Expand Up @@ -728,6 +691,7 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):
"pandas/_libs/src/ujson/python",
"pandas/_libs/src/ujson/lib",
"pandas/_libs/src/datetime",
numpy.get_include(),
],
extra_compile_args=(["-D_GNU_SOURCE"] + extra_compile_args),
extra_link_args=extra_link_args,
Expand Down