Skip to content

Commit

Permalink
Merge pull request #100 from learningequality/pycountry_optional
Browse files Browse the repository at this point in the history
Make pycountry optional.
  • Loading branch information
rtibbles authored Dec 19, 2021
2 parents fefdb53 + 3374936 commit 58c5961
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "0.1.36"
}
"version": "0.1.37"
}
11 changes: 9 additions & 2 deletions le_utils/constants/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -217,14 +220,18 @@ 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
- Using `alpha_2` lookup in `pycountry.languages` followed by lookup for a
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:
Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pycountry==17.5.14
pytest==3.7.1
attrs==20.3.0
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 58c5961

Please sign in to comment.