Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pycountry optional. #100

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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