From bcdec8dbe8512e9ef1757302090d832752854a3d Mon Sep 17 00:00:00 2001 From: Ronie Martinez Date: Sun, 21 May 2023 12:51:00 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Use=20importlib=20(#403)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove usage of pkg_resources pkg_resources is expensive to load, which takes more than 400ms here. Let's use importlib.metadata from stdlib for Python 3.8+, and fallback to importlib_metadata for Python 3.7. Note that `setuptools` was a missing runtime dependency before this change. This accelerates startup time significantly: Before: ``` $ time latex2mathml -V latex2mathml 3.73.1 real 0m0.728s user 0m0.607s sys 0m0.113s ``` After: ``` $ time latex2mathml -V latex2mathml 3.73.1 real 0m0.156s user 0m0.121s sys 0m0.037s ``` * Update version range for importlib-metadata Co-authored-by: Ronie Martinez * Update poetry.lock * Remove usage of pkg_resources pkg_resources is expensive to load, which takes more than 400ms here. Let's use importlib.metadata from stdlib for Python 3.8+, and fallback to importlib_metadata for Python 3.7. Note that `setuptools` was a missing runtime dependency before this change. This accelerates startup time significantly: Before: ``` $ time latex2mathml -V latex2mathml 3.73.1 real 0m0.728s user 0m0.607s sys 0m0.113s ``` After: ``` $ time latex2mathml -V latex2mathml 3.73.1 real 0m0.156s user 0m0.121s sys 0m0.037s ``` # Conflicts: # latex2mathml/converter.py # pyproject.toml --------- Co-authored-by: Felix Yan --- latex2mathml/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/latex2mathml/__init__.py b/latex2mathml/__init__.py index 3754f18..80aa6c9 100644 --- a/latex2mathml/__init__.py +++ b/latex2mathml/__init__.py @@ -1,3 +1,3 @@ -import pkg_resources +from importlib import metadata -__version__ = pkg_resources.get_distribution("latex2mathml").version +__version__ = metadata.version("latex2mathml")