-
Notifications
You must be signed in to change notification settings - Fork 48
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
pep518: purge legacy numpy workaround in setup.py #361
Open
bjlittle
wants to merge
1
commit into
SciTools:main
Choose a base branch
from
bjlittle:pep518
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,16 +1,21 @@ | ||||||
import sys | ||||||
import warnings | ||||||
from distutils.sysconfig import get_config_var | ||||||
from os import environ | ||||||
from pathlib import Path | ||||||
from shutil import copy | ||||||
|
||||||
# safe to import numpy here thanks to pep518 | ||||||
import numpy as np | ||||||
from setuptools import Command, Extension, setup | ||||||
|
||||||
# Default to using cython, but use the .c files if it doesn't exist | ||||||
try: | ||||||
from Cython.Build import cythonize | ||||||
except ImportError: | ||||||
cythonize = False | ||||||
wmsg = "Cython unavailable, unable to cythonize cf-units extensions!" | ||||||
warnings.warn(wmsg) | ||||||
cythonize = None | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Previous was clearer in IMO |
||||||
|
||||||
COMPILER_DIRECTIVES = {} | ||||||
DEFINE_MACROS = None | ||||||
|
@@ -46,6 +51,7 @@ def get_include_dirs(): | |||||
include_dir = get_config_var("INCLUDEDIR") | ||||||
if include_dir is not None: | ||||||
include_dirs.append(include_dir) | ||||||
include_dirs.append(np.get_include()) | ||||||
return include_dirs | ||||||
|
||||||
|
||||||
|
@@ -97,28 +103,11 @@ def get_package_data(): | |||||
return package_data | ||||||
|
||||||
|
||||||
def numpy_build_ext(pars): | ||||||
from setuptools.command.build_ext import build_ext as _build_ext | ||||||
|
||||||
class build_ext(_build_ext): | ||||||
def finalize_options(self): | ||||||
# See https://github.com/SciTools/cf-units/issues/151 | ||||||
def _set_builtin(name, value): | ||||||
if isinstance(__builtins__, dict): | ||||||
__builtins__[name] = value | ||||||
else: | ||||||
setattr(__builtins__, name, value) | ||||||
|
||||||
_build_ext.finalize_options(self) | ||||||
_set_builtin("__NUMPY_SETUP__", False) | ||||||
import numpy | ||||||
|
||||||
self.include_dirs.append(numpy.get_include()) | ||||||
|
||||||
return build_ext(pars) | ||||||
|
||||||
cython_coverage_enabled = ( | ||||||
environ.get("CYTHON_COVERAGE", None) or FLAG_COVERAGE in sys.argv | ||||||
) | ||||||
|
||||||
if FLAG_COVERAGE in sys.argv or environ.get("CYTHON_COVERAGE", None): | ||||||
if cythonize and cython_coverage_enabled: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why has this changed from |
||||||
COMPILER_DIRECTIVES = {"linetrace": True} | ||||||
DEFINE_MACROS = [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")] | ||||||
if FLAG_COVERAGE in sys.argv: | ||||||
|
@@ -144,12 +133,10 @@ def _set_builtin(name, value): | |||||
udunits_ext, compiler_directives=COMPILER_DIRECTIVES, language_level=2 | ||||||
) | ||||||
|
||||||
cmdclass = {"clean_cython": CleanCython, "build_ext": numpy_build_ext} | ||||||
|
||||||
kwargs = dict( | ||||||
cmdclass=cmdclass, | ||||||
ext_modules=[udunits_ext], | ||||||
package_data=get_package_data(), | ||||||
) | ||||||
kwargs = { | ||||||
"cmdclass": {"clean_cython": CleanCython}, | ||||||
"ext_modules": [udunits_ext], | ||||||
"package_data": get_package_data(), | ||||||
} | ||||||
|
||||||
setup(**kwargs) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we want to have a build-time dependency on numpy, but an optional build-time dependency on Cython. Surely we can now move to a world where we unconditionally depend on Cython for building from source (and sdist)?