From cedb2090df67bc5b30d6f7e392cbdb7e4f2a2336 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 27 Mar 2017 11:24:56 +0300 Subject: [PATCH] Don't install enum34 when it's not required Having enum34 breaks Python 3.6 in some cases. h/t https://hynek.me/articles/conditional-python-dependencies/ --- enumfields/enums.py | 10 +++++++--- setup.py | 15 +++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/enumfields/enums.py b/enumfields/enums.py index 3260b21..5324071 100644 --- a/enumfields/enums.py +++ b/enumfields/enums.py @@ -1,7 +1,11 @@ import inspect -from enum import Enum as BaseEnum -from enum import EnumMeta as BaseEnumMeta -from enum import _EnumDict + +try: + from enum import Enum as BaseEnum + from enum import EnumMeta as BaseEnumMeta + from enum import _EnumDict +except ImportError: # pragma: no cover + raise ImportError('Missing the enum module. Please install enum34.') from django.utils.encoding import python_2_unicode_compatible diff --git a/setup.py b/setup.py index f581ac9..c76e70f 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,11 @@ #!/usr/bin/env python import os -from setuptools import setup, find_packages -from setuptools.command.test import test as TestCommand import sys +from setuptools import find_packages, setup +from setuptools.command.test import test as TestCommand + def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() @@ -25,11 +26,6 @@ def run_tests(self): errno = pytest.main(self.test_args) sys.exit(errno) -install_requires = ['six'] -try: - import enum -except ImportError: - install_requires.append('enum34') setup( name='django-enumfields', @@ -57,10 +53,13 @@ def run_tests(self): "Programming Language :: Python :: 3.5", 'Topic :: Internet :: WWW/HTTP', ], - install_requires=install_requires, + install_requires=['six'], tests_require=[ 'pytest-django<3.0', 'Django', ], + extras_require={ + ':python_version<"3.4"': ['enum34'], + }, cmdclass={'test': PyTest}, )