forked from scikit-learn/scikit-learn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scikit-learn#5492 from arthurmensch/remove_cython
[MRG + 2] Removing generated C files, adding build cache to Travis
- Loading branch information
Showing
53 changed files
with
323 additions
and
543,795 deletions.
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 |
---|---|---|
|
@@ -53,3 +53,10 @@ benchmarks/bench_covertype_data/ | |
*.prefs | ||
.pydevproject | ||
.idea | ||
|
||
cythonize.dat | ||
*.c | ||
*.cpp | ||
|
||
!*/src/*.c | ||
!*/src/*.cpp |
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# Copyright (C) 2007-2009 Cournapeau David <[email protected]> | ||
# 2010 Fabian Pedregosa <[email protected]> | ||
# License: 3-clause BSD | ||
import subprocess | ||
|
||
descr = """A set of python modules for machine learning and data mining""" | ||
|
||
|
@@ -12,7 +13,6 @@ | |
from distutils.command.clean import clean as Clean | ||
from pkg_resources import parse_version | ||
|
||
|
||
if sys.version_info[0] < 3: | ||
import __builtin__ as builtins | ||
else: | ||
|
@@ -39,8 +39,10 @@ | |
# We can actually import a restricted version of sklearn that | ||
# does not need the compiled code | ||
import sklearn | ||
|
||
VERSION = sklearn.__version__ | ||
|
||
from sklearn._build_utils import cythonize | ||
|
||
# Optional setuptools features | ||
# We need to import setuptools early, if we want setuptools features, | ||
|
@@ -54,6 +56,7 @@ | |
]) | ||
if SETUPTOOLS_COMMANDS.intersection(sys.argv): | ||
import setuptools | ||
|
||
extra_setuptools_args = dict( | ||
zip_safe=False, # the package can run out of an .egg file | ||
include_package_data=True, | ||
|
@@ -69,20 +72,33 @@ class CleanCommand(Clean): | |
|
||
def run(self): | ||
Clean.run(self) | ||
# Remove c files if we are not within a sdist package | ||
cwd = os.path.abspath(os.path.dirname(__file__)) | ||
remove_c_files = not os.path.exists(os.path.join(cwd, 'PKG-INFO')) | ||
if remove_c_files: | ||
cython_hash_file = os.path.join(cwd, 'cythonize.dat') | ||
if os.path.exists(cython_hash_file): | ||
os.unlink(cython_hash_file) | ||
print('Will remove generated .c files') | ||
if os.path.exists('build'): | ||
shutil.rmtree('build') | ||
for dirpath, dirnames, filenames in os.walk('sklearn'): | ||
for filename in filenames: | ||
if (filename.endswith('.so') or filename.endswith('.pyd') | ||
or filename.endswith('.dll') | ||
or filename.endswith('.pyc')): | ||
if any(filename.endswith(suffix) for suffix in | ||
(".so", ".pyd", ".dll", ".pyc")): | ||
os.unlink(os.path.join(dirpath, filename)) | ||
continue | ||
extension = os.path.splitext(filename)[1] | ||
if remove_c_files and extension in ['.c', '.cpp']: | ||
pyx_file = str.replace(filename, extension, '.pyx') | ||
if os.path.exists(os.path.join(dirpath, pyx_file)): | ||
os.unlink(os.path.join(dirpath, filename)) | ||
for dirname in dirnames: | ||
if dirname == '__pycache__': | ||
shutil.rmtree(os.path.join(dirpath, dirname)) | ||
|
||
cmdclass = {'clean': CleanCommand} | ||
|
||
cmdclass = {'clean': CleanCommand} | ||
|
||
# Optional wheelhouse-uploader features | ||
# To automate release of binary packages for scikit-learn we need a tool | ||
|
@@ -94,6 +110,7 @@ def run(self): | |
WHEELHOUSE_UPLOADER_COMMANDS = set(['fetch_artifacts', 'upload_all']) | ||
if WHEELHOUSE_UPLOADER_COMMANDS.intersection(sys.argv): | ||
import wheelhouse_uploader.cmd | ||
|
||
cmdclass.update(vars(wheelhouse_uploader.cmd)) | ||
|
||
|
||
|
@@ -115,6 +132,7 @@ def configuration(parent_package='', top_path=None): | |
|
||
return config | ||
|
||
|
||
scipy_min_version = '0.9' | ||
numpy_min_version = '1.6.1' | ||
|
||
|
@@ -157,6 +175,12 @@ def get_numpy_status(): | |
return numpy_status | ||
|
||
|
||
def generate_cython(): | ||
cwd = os.path.abspath(os.path.dirname(__file__)) | ||
print("Cythonizing sources") | ||
cythonize.main(cwd) | ||
|
||
|
||
def setup_package(): | ||
metadata = dict(name=DISTNAME, | ||
maintainer=MAINTAINER, | ||
|
@@ -188,11 +212,13 @@ def setup_package(): | |
cmdclass=cmdclass, | ||
**extra_setuptools_args) | ||
|
||
if (len(sys.argv) >= 2 | ||
and ('--help' in sys.argv[1:] or sys.argv[1] | ||
in ('--help-commands', 'egg_info', '--version', 'clean'))): | ||
|
||
# For these actions, NumPy is not required. | ||
if len(sys.argv) == 1 or ( | ||
len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or | ||
sys.argv[1] in ('--help-commands', | ||
'egg_info', | ||
'--version', | ||
'clean'))): | ||
# For these actions, NumPy is not required, nor Cythonization | ||
# | ||
# They are required to succeed without Numpy for example when | ||
# pip is used to install Scikit-learn when Numpy is not yet present in | ||
|
@@ -206,10 +232,10 @@ def setup_package(): | |
else: | ||
numpy_status = get_numpy_status() | ||
numpy_req_str = "scikit-learn requires NumPy >= {0}.\n".format( | ||
numpy_min_version) | ||
numpy_min_version) | ||
scipy_status = get_scipy_status() | ||
scipy_req_str = "scikit-learn requires SciPy >= {0}.\n".format( | ||
scipy_min_version) | ||
scipy_min_version) | ||
|
||
instructions = ("Installation instructions are available on the " | ||
"scikit-learn website: " | ||
|
@@ -240,6 +266,26 @@ def setup_package(): | |
|
||
metadata['configuration'] = configuration | ||
|
||
if len(sys.argv) >= 2 and sys.argv[1] not in 'config': | ||
# Cythonize if needed | ||
|
||
print('Generating cython files') | ||
cwd = os.path.abspath(os.path.dirname(__file__)) | ||
if not os.path.exists(os.path.join(cwd, 'PKG-INFO')): | ||
# Generate Cython sources, unless building from source release | ||
generate_cython() | ||
|
||
# Clean left-over .so file | ||
for dirpath, dirnames, filenames in os.walk( | ||
os.path.join(cwd, 'sklearn')): | ||
for filename in filenames: | ||
extension = os.path.splitext(filename)[1] | ||
if extension in (".so", ".pyd", ".dll"): | ||
pyx_file = str.replace(filename, extension, '.pyx') | ||
print(pyx_file) | ||
if not os.path.exists(os.path.join(dirpath, pyx_file)): | ||
os.unlink(os.path.join(dirpath, filename)) | ||
|
||
setup(**metadata) | ||
|
||
|
||
|
Oops, something went wrong.