From 07f68815dfd145287c5a5848bd1d4d12e9043365 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Mon, 11 Jul 2016 16:03:03 +0500 Subject: [PATCH] Allow installation of ML free version. Add an option to the install script, `--no-ml`, that when given will install Talon without ML support. Fixes #96 --- MANIFEST.in | 4 +--- setup.py | 31 ++++++++++++++++++++++++++++++- talon/__init__.py | 9 +++++++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 4f99104..9f78903 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,9 +1,7 @@ -recursive-include tests * -recursive-include talon * recursive-exclude tests *.pyc *~ recursive-exclude talon *.pyc *~ include train.data include classifier include LICENSE include MANIFEST.in -include README.rst \ No newline at end of file +include README.rst diff --git a/setup.py b/setup.py index 8be1da5..8253212 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,30 @@ from setuptools import setup, find_packages +from setuptools.command.install import install + + +class InstallCommand(install): + user_options = install.user_options + [ + ('no-ml', None, "Don't install without Machine Learning modules."), + ] + + boolean_options = install.boolean_options + ['no-ml'] + + def initialize_options(self): + install.initialize_options(self) + self.no_ml = None + + def finalize_options(self): + install.finalize_options(self) + if self.no_ml: + dist = self.distribution + dist.packages=find_packages(exclude=[ + 'tests', + 'tests.*', + 'talon.signature', + 'talon.signature.*', + ]) + for not_required in ['numpy', 'scipy', 'scikit-learn==0.16.1']: + dist.install_requires.remove(not_required) setup(name='talon', @@ -10,7 +36,10 @@ setup(name='talon', author_email='admin@mailgunhq.com', url='https://github.com/mailgun/talon', license='APACHE2', - packages=find_packages(exclude=['tests']), + cmdclass={ + 'install': InstallCommand, + }, + packages=find_packages(exclude=['tests', 'tests.*']), include_package_data=True, zip_safe=True, install_requires=[ diff --git a/talon/__init__.py b/talon/__init__.py index 13e46a8..de27ae6 100644 --- a/talon/__init__.py +++ b/talon/__init__.py @@ -1,7 +1,12 @@ from talon.quotations import register_xpath_extensions -from talon import signature +try: + from talon import signature + ML_ENABLED = True +except ImportError: + ML_ENABLED = False def init(): register_xpath_extensions() - signature.initialize() + if ML_ENABLED: + signature.initialize()