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
[WIP] Do not import the sklearn package from setup.py #3015
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -8,8 +8,26 @@ | ||
import sys | import sys | ||
import os | import os | ||
import shutil | import shutil | ||
import subprocess | |||
from distutils.command.clean import clean as Clean | from distutils.command.clean import clean as Clean | ||
|
|
||
|
|||
DISTNAME = 'scikit-learn' | |||
DESCRIPTION = 'A set of python modules for machine learning and data mining' | |||
LONG_DESCRIPTION = open('README.rst').read() | |||
MAINTAINER = 'Andreas Mueller' | |||
MAINTAINER_EMAIL = 'amueller@ais.uni-bonn.de' | |||
URL = 'http://scikit-learn.org' | |||
LICENSE = 'new BSD' | |||
DOWNLOAD_URL = 'http://sourceforge.net/projects/scikit-learn/files/' | |||
|
|||
MAJOR = 0 | |||
MINOR = 15 | |||
MICRO = 0 | |||
ISRELEASED = False | |||
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) | |||
|
|||
|
|||
if sys.version_info[0] < 3: | if sys.version_info[0] < 3: | ||
import __builtin__ as builtins | import __builtin__ as builtins | ||
else: | else: | ||
|
@@ -20,20 +38,71 @@ | ||
# avoid attempting to load components that aren't built yet. | # avoid attempting to load components that aren't built yet. | ||
builtins.__SKLEARN_SETUP__ = True | builtins.__SKLEARN_SETUP__ = True | ||
|
|
||
DISTNAME = 'scikit-learn' | # Return the git revision as a string | ||
DESCRIPTION = 'A set of python modules for machine learning and data mining' | def git_version(): | ||
LONG_DESCRIPTION = open('README.rst').read() | def _minimal_ext_cmd(cmd): | ||
MAINTAINER = 'Andreas Mueller' | # construct minimal environment | ||
MAINTAINER_EMAIL = 'amueller@ais.uni-bonn.de' | env = {} | ||
URL = 'http://scikit-learn.org' | for k in ['SYSTEMROOT', 'PATH']: | ||
LICENSE = 'new BSD' | v = os.environ.get(k) | ||
DOWNLOAD_URL = 'http://sourceforge.net/projects/scikit-learn/files/' | if v is not None: | ||
env[k] = v | |||
# LANGUAGE is used on win32 | |||
env['LANGUAGE'] = 'C' | |||
env['LANG'] = 'C' | |||
env['LC_ALL'] = 'C' | |||
out = subprocess.Popen(cmd, stdout = subprocess.PIPE, | |||
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. you can just use |
|||
env=env).communicate()[0] | |||
return out | |||
|
|||
try: | |||
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD']) | |||
GIT_REVISION = out.strip().decode('ascii') | |||
except OSError: | |||
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. Is it possible for |
|||
GIT_REVISION = "Unknown" | |||
|
|||
return GIT_REVISION | |||
|
|||
|
|||
def get_version_info(): | |||
FULLVERSION = VERSION | |||
if os.path.exists('.git'): | |||
GIT_REVISION = git_version() | |||
else: | |||
GIT_REVISION = "Unknown" | |||
|
|||
if not ISRELEASED: | |||
FULLVERSION += '.dev-' + GIT_REVISION[:7] | |||
|
|||
return FULLVERSION, GIT_REVISION | |||
|
|||
|
|||
def write_version_py(filename='sklearn/version.py'): | |||
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. Please name it |
|||
content = """ | |||
# THIS FILE IS GENERATED FROM SETUP.PY | |||
short_version = '%(version)s' | |||
version = '%(version)s' | |||
full_version = '%(full_version)s' | |||
git_revision = '%(git_revision)s' | |||
release = %(isrelease)s | |||
|
|||
if not release: | |||
version = full_version | |||
""" | |||
FULLVERSION, GIT_REVISION = get_version_info() | |||
|
|||
a = open(filename, 'w') | |||
try: | |||
a.write(content % {'version': VERSION, | |||
'full_version' : FULLVERSION, | |||
'git_revision' : GIT_REVISION, | |||
'isrelease': str(ISRELEASED)}) | |||
finally: | |||
a.close() | |||
return FULLVERSION | |||
|
|
||
# We can actually import a restricted version of sklearn that | FULLVERSION = write_version_py() | ||
# does not need the compiled code | |||
import sklearn | |||
|
|
||
VERSION = sklearn.__version__ | |||
|
|
||
############################################################################### | ############################################################################### | ||
# Optional setuptools features | # Optional setuptools features | ||
|
@@ -101,7 +170,7 @@ def setup_package(): | ||
description=DESCRIPTION, | description=DESCRIPTION, | ||
license=LICENSE, | license=LICENSE, | ||
url=URL, | url=URL, | ||
version=VERSION, | version=FULLVERSION, | ||
download_url=DOWNLOAD_URL, | download_url=DOWNLOAD_URL, | ||
long_description=LONG_DESCRIPTION, | long_description=LONG_DESCRIPTION, | ||
classifiers=['Intended Audience :: Science/Research', | classifiers=['Intended Audience :: Science/Research', | ||
|
@@ -138,7 +207,7 @@ def setup_package(): | ||
except ImportError: | except ImportError: | ||
from distutils.core import setup | from distutils.core import setup | ||
|
|
||
metadata['version'] = VERSION | metadata['version'] = FULLVERSION | ||
else: | else: | ||
from numpy.distutils.core import setup | from numpy.distutils.core import setup | ||
|
|
||
|
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 is it necessary to synthesize the environment?