launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #22454
[Merge] lp:~cjwatson/launchpad/importlib-resources into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/importlib-resources into lp:launchpad.
Commit message:
Switch from pkg_resources to the faster importlib_resources.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/importlib-resources/+merge/345123
This is new hotness from Python 3.7, backported. "import importlib_resources; with importlib_resources.path(...): ..." is about 0.4s faster for me than "import pkg_resources; pkg_resources.resource_filename(...)" (0.2s vs. 0.62s). We probably won't get the full benefit until all our dependencies stop using pkg_resources, but we might as well make a start.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/importlib-resources into lp:launchpad.
=== modified file 'constraints.txt'
--- constraints.txt 2018-03-29 18:21:36 +0000
+++ constraints.txt 2018-05-05 11:54:56 +0000
@@ -261,6 +261,7 @@
idna==2.6
imagesize==0.7.1
importlib==1.0.2
+importlib-resources==0.5
incremental==17.5.0
ipaddress==1.0.18
ipython==0.13.2
@@ -302,6 +303,7 @@
ordereddict==1.1
oslo.config==1.3.0
paramiko==1.7.7.2
+pathlib2==2.3.2
pbr==0.11.1
pgbouncer==0.0.8
prettytable==0.7.2
@@ -330,6 +332,7 @@
rabbitfixture==0.3.6
requests==2.7.0
requests-toolbelt==0.6.2
+scandir==1.7
service-identity==17.0.0
setproctitle==1.1.7
setuptools-git==1.2
=== modified file 'lib/lp/services/config/__init__.py'
--- lib/lp/services/config/__init__.py 2017-10-05 12:51:27 +0000
+++ lib/lp/services/config/__init__.py 2018-05-05 11:54:56 +0000
@@ -20,6 +20,7 @@
urlunparse,
)
+import importlib_resources
from lazr.config import ImplicitTypeSchema
from lazr.config.interfaces import ConfigErrors
import ZConfig
@@ -240,10 +241,9 @@
def _setZConfig(self):
"""Modify the config, adding automatically generated settings"""
- import pkg_resources
- schemafile = pkg_resources.resource_filename(
- 'zope.app.server', 'schema.xml')
- schema = ZConfig.loadSchema(schemafile)
+ with importlib_resources.path(
+ 'zope.app.server', 'schema.xml') as schemafile:
+ schema = ZConfig.loadSchema(str(schemafile))
root_options, handlers = ZConfig.loadConfig(
schema, self.zope_config_file)
=== modified file 'lib/lp/services/config/tests/test_config.py'
--- lib/lp/services/config/tests/test_config.py 2017-12-19 17:22:23 +0000
+++ lib/lp/services/config/tests/test_config.py 2018-05-05 11:54:56 +0000
@@ -16,9 +16,9 @@
import unittest
from fixtures import TempDir
+import importlib_resources
from lazr.config import ConfigSchema
from lazr.config.interfaces import ConfigErrors
-import pkg_resources
import testtools
import ZConfig
@@ -29,8 +29,8 @@
EXCLUDED_CONFIGS = ['lpnet-template']
# Calculate some landmark paths.
-schema_file = pkg_resources.resource_filename('zope.app.server', 'schema.xml')
-schema = ZConfig.loadSchema(schema_file)
+with importlib_resources.path('zope.app.server', 'schema.xml') as schema_file:
+ schema = ZConfig.loadSchema(str(schema_file))
here = os.path.dirname(lp.services.config.__file__)
lazr_schema_file = os.path.join(here, 'schema-lazr.conf')
=== modified file 'lib/lp/services/webservice/wadl.py'
--- lib/lp/services/webservice/wadl.py 2011-12-24 17:49:30 +0000
+++ lib/lp/services/webservice/wadl.py 2018-05-05 11:54:56 +0000
@@ -1,14 +1,14 @@
# Copyright 2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
-"""APIs to generate the web sercice WADL and documentation HTML."""
+"""APIs to generate the web service WADL and documentation HTML."""
__metaclass__ = type
import subprocess
import urlparse
-import pkg_resources
+import importlib_resources
from lp.services.webapp.interaction import (
ANONYMOUS,
@@ -57,17 +57,17 @@
# stderr (like we want to do during test runs), we reassign the subprocess
# stderr file handle and then discard the output. Otherwise we let the
# subprocess inherit stderr.
- stylesheet = pkg_resources.resource_filename(
- 'lp.services.webservice', 'wadl-to-refhtml.xsl')
- if suppress_stderr:
- stderr = subprocess.PIPE
- else:
- stderr = None
- args = ('xsltproc', stylesheet, wadl_filename)
- process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=stderr)
-
- output = process.communicate()[0]
- if process.returncode != 0:
- raise subprocess.CalledProcessError(process.returncode, args)
-
- return output
+ with importlib_resources.path(
+ 'lp.services.webservice', 'wadl-to-refhtml.xsl') as stylesheet:
+ if suppress_stderr:
+ stderr = subprocess.PIPE
+ else:
+ stderr = None
+ args = ('xsltproc', str(stylesheet), wadl_filename)
+ process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=stderr)
+
+ output = process.communicate()[0]
+ if process.returncode != 0:
+ raise subprocess.CalledProcessError(process.returncode, args)
+
+ return output
=== modified file 'setup.py'
--- setup.py 2018-03-26 22:01:27 +0000
+++ setup.py 2018-05-05 11:54:56 +0000
@@ -161,6 +161,7 @@
'fixtures',
'html5browser',
'httmock',
+ 'importlib-resources',
'ipython',
'jsautobuild',
'launchpad-buildd',
Follow ups