diff --git a/js/package.json b/js/package.json index d0a6b8a..d76d07c 100644 --- a/js/package.json +++ b/js/package.json @@ -27,5 +27,5 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "0.1.36" -} + "version": "0.1.37" +} \ No newline at end of file diff --git a/le_utils/constants/languages.py b/le_utils/constants/languages.py index 7539ddf..49962b1 100644 --- a/le_utils/constants/languages.py +++ b/le_utils/constants/languages.py @@ -5,7 +5,10 @@ from collections import defaultdict from collections import namedtuple -import pycountry +try: + import pycountry +except ImportError: + pycountry = None logger = logging.getLogger("le_utils") logger.setLevel(logging.INFO) @@ -217,7 +220,7 @@ def getlang_by_native_name(native_name): return _LANGUAGE_NATIVE_NAME_LOOKUP.get(simple_native_name, None) -def getlang_by_alpha2(code): +def getlang_by_alpha2(code): # noqa: C901 """ Lookup a Language object for language code `code` based on these strategies: - Special case rules for Hebrew and Chinese Hans/Hant scripts @@ -225,6 +228,10 @@ def getlang_by_alpha2(code): language with the same `name` in the internal representaion Returns `None` if no matching language is found. """ + if pycountry is None: + logger.warn("pycountry is not installed, cannot lookup language by alpha2") + return None + # First try exact match to a language code in the internal representaion exact_match = getlang(code) if exact_match: diff --git a/requirements-test.txt b/requirements-test.txt index 504de7e..b793b77 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,2 +1,3 @@ +pycountry==17.5.14 pytest==3.7.1 attrs==20.3.0 diff --git a/setup.py b/setup.py index 54a28c0..a954628 100644 --- a/setup.py +++ b/setup.py @@ -5,18 +5,19 @@ long_description = io.open("README.md", encoding="utf-8").read() -requirements = [ +lang_utils_requirements = [ "pycountry==17.5.14", ] setup( name="le-utils", packages=find_packages(), - version="0.1.36", + version="0.1.37", description="LE-Utils contains shared constants used in Kolibri, Ricecooker, and Kolibri Studio.", long_description=long_description, long_description_content_type="text/markdown", - install_requires=requirements, + install_requires=[], + extras_require={"lang_utils": lang_utils_requirements}, license="MIT", url="https://github.com/learningequality/le-utils", download_url="https://github.com/learningequality/le-utils/releases",