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

Use importlib.metadata to get package version instead of pkg_resources.get_distribution to decrease memory consumption #227

Merged
merged 4 commits into from
Oct 6, 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
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ project_urls =
packages = find:
install_requires =
setuptools
importlib-metadata;python_version < '3.8'
python_requires = >=3.6
include_package_data = True
package_dir = =src
Expand Down
10 changes: 8 additions & 2 deletions src/humanize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Main package for humanize."""
import pkg_resources

from humanize.filesize import naturalsize
from humanize.i18n import activate, deactivate, thousands_separator
Expand All @@ -20,7 +19,14 @@
precisedelta,
)

__version__ = VERSION = pkg_resources.get_distribution(__name__).version
try:
# Python 3.8+
import importlib.metadata as importlib_metadata
except ImportError:
# <Python 3.7 and lower
import importlib_metadata

__version__ = importlib_metadata.version(__name__)


__all__ = [
Expand Down