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
[MRG] MNT Include all pxd files in the package #15626
Merged
adrinjalali
merged 6 commits into
scikit-learn:master
from
jeremiedbb:include-pxd-files
Nov 26, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6772684
include all pxd files in package
jeremiedbb 8b7272c
Merge branch 'master' into include-pxd-files
jeremiedbb 4c86cd8
_libsvm _liblinear to pxi + add a test
jeremiedbb 6d713da
simplify stuff + use pathlib
jeremiedbb 7eb0355
cln
jeremiedbb a0d2046
more cln
jeremiedbb File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Utility for testing presence and usability of .pxd files in the installation | ||
|
||
Usage: | ||
------ | ||
python check_pxd_in_installation.py path/to/install_dir/of/scikit-learn | ||
""" | ||
|
||
import os | ||
import sys | ||
import pathlib | ||
import tempfile | ||
import textwrap | ||
import subprocess | ||
|
||
|
||
sklearn_dir = pathlib.Path(sys.argv[1]) | ||
pxd_files = list(sklearn_dir.glob("**/*.pxd")) | ||
|
||
print("> Found pxd files:") | ||
for pxd_file in pxd_files: | ||
print(' -', pxd_file) | ||
|
||
print("\n> Trying to compile a cython extension cimporting all corresponding " | ||
"modules\n") | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
tmpdir = pathlib.Path(tmpdir) | ||
# A cython test file which cimports all modules corresponding to found | ||
# pxd files. | ||
# e.g. sklearn/tree/_utils.pxd becomes `cimport sklearn.tree._utils` | ||
with open(tmpdir / 'tst.pyx', 'w') as f: | ||
for pxd_file in pxd_files: | ||
to_import = str(pxd_file.relative_to(sklearn_dir)) | ||
to_import = to_import.replace(os.path.sep, '.') | ||
to_import = to_import.replace('.pxd', '') | ||
f.write('cimport sklearn.' + to_import + '\n') | ||
|
||
# A basic setup file to build the test file. | ||
# We set the language to c++ and we use numpy.get_include() because | ||
# some modules require it. | ||
with open(tmpdir / 'setup_tst.py', 'w') as f: | ||
f.write(textwrap.dedent( | ||
""" | ||
from distutils.core import setup | ||
from distutils.extension import Extension | ||
from Cython.Build import cythonize | ||
import numpy | ||
|
||
extensions = [Extension("tst", | ||
sources=["tst.pyx"], | ||
language="c++", | ||
include_dirs=[numpy.get_include()])] | ||
|
||
setup(ext_modules=cythonize(extensions)) | ||
""")) | ||
|
||
subprocess.run(["python", "setup_tst.py", "build_ext", "-i"], | ||
check=True, cwd=tmpdir) | ||
|
||
print("\n> Compilation succeeded !") |
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
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
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
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,5 +1,3 @@ | ||
cimport numpy as np | ||
|
||
################################################################################ | ||
# Includes | ||
|
||
|
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
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
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
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.
nice catch!