Advertisement
Guest User

hahlo

a guest
Jan 17th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.62 KB | None | 0 0
  1. #! /usr/bin/env python3
  2.  
  3. import os
  4. import sys
  5. import subprocess
  6. from setuptools import find_packages, Command
  7.  
  8. if sys.version_info < (3, 4):
  9.     sys.exit('Orange requires Python >= 3.4')
  10.  
  11. try:
  12.     from numpy.distutils.core import setup
  13.     have_numpy = True
  14. except ImportError:
  15.     from setuptools import setup
  16.     have_numpy = False
  17.  
  18. from distutils.command.build_ext import build_ext
  19.  
  20. NAME = 'Orange3'
  21.  
  22. VERSION = '3.3.9'
  23. ISRELEASED = True
  24. # full version identifier including a git revision identifier for development
  25. # build/releases (this is filled/updated in `write_version_py`)
  26. FULLVERSION = VERSION
  27.  
  28. DESCRIPTION = 'Orange, a component-based data mining framework.'
  29. README_FILE = os.path.join(os.path.dirname(__file__), 'README.md')
  30. LONG_DESCRIPTION = open(README_FILE).read()
  31. AUTHOR = 'Bioinformatics Laboratory, FRI UL'
  32. AUTHOR_EMAIL = 'info@biolab.si'
  33. URL = 'http://orange.biolab.si/'
  34. LICENSE = 'GPLv3+'
  35.  
  36. KEYWORDS = (
  37.     'data mining',
  38.     'machine learning',
  39.     'artificial intelligence',
  40. )
  41.  
  42. CLASSIFIERS = (
  43.     'Development Status :: 4 - Beta',
  44.     'Environment :: X11 Applications :: Qt',
  45.     'Environment :: Console',
  46.     'Environment :: Plugins',
  47.     'Programming Language :: Python',
  48.     'License :: OSI Approved :: '
  49.     'GNU General Public License v3 or later (GPLv3+)',
  50.     'Operating System :: POSIX',
  51.     'Operating System :: Microsoft :: Windows',
  52.     'Topic :: Scientific/Engineering :: Artificial Intelligence',
  53.     'Topic :: Scientific/Engineering :: Visualization',
  54.     'Topic :: Software Development :: Libraries :: Python Modules',
  55.     'Intended Audience :: Education',
  56.     'Intended Audience :: Science/Research',
  57.     'Intended Audience :: Developers',
  58. )
  59.  
  60. requirements = ['requirements-core.txt', 'requirements-gui.txt']
  61.  
  62. INSTALL_REQUIRES = sorted(set(
  63.     line.partition('#')[0].strip()
  64.     for file in (os.path.join(os.path.dirname(__file__), file)
  65.                  for file in requirements)
  66.     for line in open(file)
  67. ) - {''})
  68.  
  69.  
  70. ENTRY_POINTS = {
  71.     "orange.canvas.help": (
  72.         "html-index = Orange.widgets:WIDGET_HELP_PATH",
  73.     ),
  74.     "gui_scripts": (
  75.         "orange-canvas = Orange.canvas.__main__:main",
  76.     ),
  77. }
  78.  
  79.  
  80. # Return the git revision as a string
  81. def git_version():
  82.     """Return the git revision as a string.
  83.  
  84.    Copied from numpy setup.py
  85.    """
  86.     def _minimal_ext_cmd(cmd):
  87.         # construct minimal environment
  88.         env = {}
  89.         for k in ['SYSTEMROOT', 'PATH']:
  90.             v = os.environ.get(k)
  91.             if v is not None:
  92.                 env[k] = v
  93.         # LANGUAGE is used on win32
  94.         env['LANGUAGE'] = 'C'
  95.         env['LANG'] = 'C'
  96.         env['LC_ALL'] = 'C'
  97.         out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
  98.         return out
  99.  
  100.     try:
  101.         out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
  102.         GIT_REVISION = out.strip().decode('ascii')
  103.     except OSError:
  104.         GIT_REVISION = "Unknown"
  105.     return GIT_REVISION
  106.  
  107.  
  108. def write_version_py(filename='Orange/version.py'):
  109.     # Copied from numpy setup.py
  110.     cnt = """
  111. # THIS FILE IS GENERATED FROM ORANGE SETUP.PY
  112. short_version = '%(version)s'
  113. version = '%(version)s'
  114. full_version = '%(full_version)s'
  115. git_revision = '%(git_revision)s'
  116. release = %(isrelease)s
  117.  
  118. if not release:
  119.    version = full_version
  120.    short_version += ".dev"
  121. """
  122.     global FULLVERSION
  123.     FULLVERSION = VERSION
  124.     if os.path.exists('.git'):
  125.         GIT_REVISION = git_version()
  126.     elif os.path.exists('Orange/version.py'):
  127.         # must be a source distribution, use existing version file
  128.         import imp
  129.         version = imp.load_source("Orange.version", "Orange/version.py")
  130.         GIT_REVISION = version.git_revision
  131.     else:
  132.         GIT_REVISION = "Unknown"
  133.  
  134.     if not ISRELEASED:
  135.         FULLVERSION += '.dev0+' + GIT_REVISION[:7]
  136.  
  137.     a = open(filename, 'w')
  138.     try:
  139.         a.write(cnt % {'version': VERSION,
  140.                        'full_version': FULLVERSION,
  141.                        'git_revision': GIT_REVISION,
  142.                        'isrelease': str(ISRELEASED)})
  143.     finally:
  144.         a.close()
  145.  
  146.  
  147. def configuration(parent_package='', top_path=None):
  148.     if os.path.exists('MANIFEST'):
  149.         os.remove('MANIFEST')
  150.  
  151.     from numpy.distutils.misc_util import Configuration
  152.     config = Configuration(None, parent_package, top_path)
  153.  
  154.     # Avoid non-useful msg:
  155.     # "Ignoring attempt to set 'name' (from ... "
  156.     config.set_options(ignore_setup_xxx_py=True,
  157.                        assume_default_configuration=True,
  158.                        delegate_options_to_subpackages=True,
  159.                        quiet=True)
  160.  
  161.     config.add_subpackage('Orange')
  162.     return config
  163.  
  164.  
  165. PACKAGES = find_packages()
  166.  
  167. # Extra non .py, .{so,pyd} files that are installed within the package dir
  168. # hierarchy
  169. PACKAGE_DATA = {
  170.     "Orange": ["datasets/*.{}".format(ext)
  171.                for ext in ["tab", "csv", "basket", "info", "dst"]],
  172.     "Orange.canvas": ["icons/*.png", "icons/*.svg"],
  173.     "Orange.canvas.styles": ["*.qss", "orange/*.svg"],
  174.     "Orange.canvas.application.workflows": ["*.ows"],
  175.     "Orange.canvas.report": ["icons/*.svg", "*.html"],
  176.     "Orange.widgets": ["icons/*.png",
  177.                        "icons/*.svg",
  178.                        "_highcharts/*"],
  179.     "Orange.widgets.classify": ["icons/*.svg"],
  180.     "Orange.widgets.data": ["icons/*.svg",
  181.                             "icons/paintdata/*.png",
  182.                             "icons/paintdata/*.svg"],
  183.     "Orange.widgets.evaluate": ["icons/*.svg"],
  184.     "Orange.widgets.visualize": ["icons/*.svg"],
  185.     "Orange.widgets.regression": ["icons/*.svg"],
  186.     "Orange.widgets.unsupervised": ["icons/*.svg"],
  187.     "Orange.widgets.utils": ["_webview/*.js"],
  188.     "Orange.widgets.utils.plot": ["*.fs", "*.gs", "*.vs"],
  189.     "Orange.widgets.utils.plot.primitives": ["*.obj"],
  190.     "Orange.tests": ["xlsx_files/*.xlsx", "*.tab", "*.basket", "*.csv"]
  191. }
  192.  
  193.  
  194. class LintCommand(Command):
  195.     """A setup.py lint subcommand developers can run locally."""
  196.     description = "run code linter(s)"
  197.     user_options = []
  198.     initialize_options = finalize_options = lambda self: None
  199.  
  200.     def run(self):
  201.         """Lint current branch compared to a reasonable master branch"""
  202.         sys.exit(subprocess.call(r'''
  203.        set -eu
  204.        upstream="$(git remote -v |
  205.                    awk '/[@\/]github.com[:\/]biolab\/orange3[\. ]/{ print $1; exit }')"
  206.        git fetch -q $upstream master
  207.        best_ancestor=$(git merge-base HEAD refs/remotes/$upstream/master)
  208.        .travis/check_pylint_diff $best_ancestor
  209.        ''', shell=True, cwd=os.path.dirname(os.path.abspath(__file__))))
  210.  
  211. class CoverageCommand(Command):
  212.     """A setup.py coverage subcommand developers can run locally."""
  213.     description = "run code coverage"
  214.     user_options = []
  215.     initialize_options = finalize_options = lambda self: None
  216.  
  217.     def run(self):
  218.         """Check coverage on current workdir"""
  219.         sys.exit(subprocess.call(r'''
  220.        coverage run --source=Orange -m unittest -v Orange.tests
  221.        echo; echo
  222.        coverage report
  223.        coverage html &&
  224.            { echo; echo "See also: file://$(pwd)/htmlcov/index.html"; echo; }
  225.        ''', shell=True, cwd=os.path.dirname(os.path.abspath(__file__))))
  226.  
  227.  
  228.  
  229.  
  230. class build_ext_error(build_ext):
  231.     def initialize_options(self):
  232.         raise SystemExit(
  233.             "Cannot compile extensions. numpy is required to build Orange."
  234.         )
  235.  
  236.  
  237. def setup_package():
  238.     write_version_py()
  239.     cmdclass = {
  240.         'lint': LintCommand,
  241.         'coverage': CoverageCommand,
  242.     }
  243.  
  244.     if have_numpy:
  245.         extra_args = {
  246.             "configuration": configuration
  247.         }
  248.     else:
  249.         # substitute a build_ext command with one that raises an error when
  250.         # building. In order to fully support `pip install` we need to
  251.         # survive a `./setup egg_info` without numpy so pip can properly
  252.         # query our install dependencies
  253.         extra_args = {}
  254.         cmdclass["build_ext"] = build_ext_error
  255.     setup(
  256.         name=NAME,
  257.         version=FULLVERSION,
  258.         description=DESCRIPTION,
  259.         long_description=LONG_DESCRIPTION,
  260.         author=AUTHOR,
  261.         author_email=AUTHOR_EMAIL,
  262.         url=URL,
  263.         license=LICENSE,
  264.         keywords=KEYWORDS,
  265.         classifiers=CLASSIFIERS,
  266.         packages=PACKAGES,
  267.         package_data=PACKAGE_DATA,
  268.         install_requires=INSTALL_REQUIRES,
  269.         entry_points=ENTRY_POINTS,
  270.         zip_safe=False,
  271.         test_suite='Orange.tests.suite',
  272.         cmdclass=cmdclass,
  273.         **extra_args
  274.     )
  275.  
  276. if __name__ == '__main__':
  277.     setup_package()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement