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 3 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
40 changes: 11 additions & 29 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 @@ -17,9 +18,8 @@
import sys

import pkg_resources
from setuptools import Command, find_packages, setup
from setuptools import Command, Extension, find_packages, setup

# versioning
import versioneer

cmdclass = versioneer.get_cmdclass()
Expand Down Expand Up @@ -48,22 +48,12 @@ 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
from Cython import Tempita
from Cython.Distutils.build_ext import build_ext as _build_ext
Copy link
Member

Choose a reason for hiding this comment

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

Hmm we should do this but might want to be careful - any idea what the difference is with the new build_ext command?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll look into this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at the cython source code. The new build_ext is just
setuptools.command.build_ext or distutils.command.build_ext. But I'm not sure how it differs from the old_build_ext.

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 +91,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 +394,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 +467,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 +489,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 Down