Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -52,3 +52,6 @@ benchmarks/bench_covertype_data/
*.prefs *.prefs
.pydevproject .pydevproject
.idea .idea

# Generated when running setup.py
sklearn/version.py
97 changes: 83 additions & 14 deletions setup.py
Expand Up @@ -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:
Expand All @@ -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
Copy link
Member

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?

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,
Copy link
Member

Choose a reason for hiding this comment

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

you can just use subprocess.check_output(cmd, env=env)

env=env).communicate()[0]
return out

try:
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
GIT_REVISION = out.strip().decode('ascii')
except OSError:
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible for subprocess.CalledProcessError or IOError to fire?

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'):
Copy link
Member

Choose a reason for hiding this comment

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

Please name it _version.py.

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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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


Expand Down
19 changes: 8 additions & 11 deletions sklearn/__init__.py
Expand Up @@ -15,27 +15,24 @@
import sys import sys
import re import re
import warnings import warnings
__version__ = '0.15-git'


# Make sure that DeprecationWarning within this package always gets printed # Make sure that DeprecationWarning within this package always gets printed
warnings.filterwarnings('always', category=DeprecationWarning, warnings.filterwarnings('always', category=DeprecationWarning,
module='^{0}\.'.format(re.escape(__name__))) module='^{0}\.'.format(re.escape(__name__)))


try: try:
# This variable is injected in the __builtins__ by the build # This builtins variable is defined by setup.py when building the project.
# process. It used to enable importing subpackages of sklearn when in_setup = __SKLEARN_SETUP__
# the binaries are not built
__SKLEARN_SETUP__
except NameError: except NameError:
__SKLEARN_SETUP__ = False in_setup = False


if __SKLEARN_SETUP__: if not in_setup:
sys.stderr.write('Partial import of sklearn during the build process.\n') # Trigger the build check only when run once the build is actually
# We are not importing the rest of the scikit during the build # complete.
# process, as it may not be compiled yet
else:
from . import __check_build from . import __check_build
from .base import clone from .base import clone
from .version import full_version as __version__



def test(*args, **kwargs): def test(*args, **kwargs):
import warnings import warnings
Expand Down