Skip to content

Commit

Permalink
🔨 Use importlib (#403)
Browse files Browse the repository at this point in the history
* 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 <ronmarti18@gmail.com>

* 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 <felixonmars@archlinux.org>
  • Loading branch information
roniemartinez and felixonmars committed May 21, 2023
1 parent 67b660b commit bcdec8d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions latex2mathml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pkg_resources
from importlib import metadata

__version__ = pkg_resources.get_distribution("latex2mathml").version
__version__ = metadata.version("latex2mathml")

0 comments on commit bcdec8d

Please sign in to comment.