Commit 7dbec2d6 authored by Leo Pound Singer's avatar Leo Pound Singer

Speed up imports by using importlib instead of pkg_resources

Speed up imports by up to a second by replacing uses of `pkg_resources`
with the new Python standard library module `importlib.resources` (or,
for Python < 3.7, the backport `importlib_resources`). The old
`pkg_resources` module is known to be slow because it does a lot of
work on startup.

See, for example,
[pypa/setuptools#926](https://github.com/pypa/setuptools/issues/926) and
[pypa/setuptools#510](https://github.com/pypa/setuptools/issues/510).
parent fa04b179
Pipeline #123357 failed with stages
in 1 minute and 11 seconds
......@@ -2,7 +2,12 @@
## 2.0.1 (unreleased)
- No changes yet.
- Speed up imports by up to a second by replacing uses of `pkg_resources`
with the new Python standard library module `importlib.resources` (or, for
Python < 3.7, the backport `importlib_resources`). The old `pkg_resources`
module is known to be slow because it does a lot of work on startup. (See,
for example, https://github.com/pypa/setuptools/issues/926 and
https://github.com/pypa/setuptools/issues/510.)
## 2.0.0 (2020-03-11)
......
......@@ -32,6 +32,7 @@ classifiers =
[options]
packages = find:
install_requires =
importlib-resources;python_version<'3.7'
safe-netrc
slixmpp
......
......@@ -19,7 +19,12 @@ import getpass
import logging
import uuid
import pkg_resources
try:
from importlib import resources
except ImportError:
# FIXME: remove after dropping support for Python < 3.7
import importlib_resources as resources
from safe_netrc import netrc, NetrcParseError
import slixmpp
......@@ -169,7 +174,8 @@ class LVAlertClient(slixmpp.ClientXMPP):
self.register_plugin('xep_0060') # Activate PubSub plugin
self.add_event_handler("session_start", self._session_start)
self.ca_certs = pkg_resources.resource_filename(__name__, 'certs.pem')
with resources.path(__package__, 'certs.pem') as p:
self.ca_certs = str(p)
self._stopped = None
async def _session_start(self, event):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment