-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Fix i18n _get_default_locale_path #204
base: main
Are you sure you want to change the base?
Fix i18n _get_default_locale_path #204
Conversation
af19aaf
to
ff870da
Compare
Fixes python-humanize#105 Use importlib.resources available since Python 3.9 to find the location of the locale folder containing the translations.
ff870da
to
9627694
Compare
I tried to use The tests cover when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
Let's do some tuning to speed up with lazy imports, which can be important for CLIs where you want a quick response time.
Using https://github.com/nschloe/tuna we can visualise the import times:
python -m pip install tuna
python -c "import humanize" && python -X importtime -c "import humanize" 2> import.log && tuna import.log
Here's main
:
Here's this PR:
With the suggestions:
return None | ||
|
||
with importlib.resources.as_file(importlib.resources.files(package)) as pkg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with importlib.resources.as_file(importlib.resources.files(package)) as pkg: | |
import importlib.resources | |
with importlib.resources.as_file(importlib.resources.files(package)) as pkg: |
import importlib.resources | ||
import os | ||
import pathlib | ||
from threading import local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import importlib.resources | |
import os | |
import pathlib | |
from threading import local | |
from threading import local | |
from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
import os | |
import pathlib |
Fixes #105
Changes proposed in this pull request:
importlib.resources
available since Python 3.9 to find the location of the locale folder containing the translations.