launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24280
[Merge] ~cjwatson/launchpad:py3-backports into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-backports into launchpad:master.
Commit message:
Limit some external packages by Python version
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/378459
backports.lzma, contextlib2, and ipaddress are all backports of standard library additions in Python 3.3, so restrict these to Python < 3.3 and adjust imports where appropriate. Likewise, importlib-resources is a backport of a standard library addition in Python 3.7.
In principle we could apply the same treatment to scandir, which was added to the standard library in 3.5, but the import adjustments get pretty verbose. It's probably easiest to just drop this once we're on >= 3.5 everywhere.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-backports into launchpad:master.
diff --git a/lib/lp/code/model/branchmergeproposaljob.py b/lib/lp/code/model/branchmergeproposaljob.py
index cc6b20c..d6cd0ec 100644
--- a/lib/lp/code/model/branchmergeproposaljob.py
+++ b/lib/lp/code/model/branchmergeproposaljob.py
@@ -21,13 +21,15 @@ __all__ = [
'UpdatePreviewDiffJob',
]
-from contextlib import contextmanager
+try:
+ from contextlib import ExitStack
+except ImportError:
+ from contextlib2 import ExitStack
from datetime import (
datetime,
timedelta,
)
-from contextlib2 import ExitStack
from lazr.delegates import delegate_to
from lazr.enum import (
DBEnumeratedType,
diff --git a/lib/lp/code/model/diff.py b/lib/lp/code/model/diff.py
index b5a0cb1..d74c103 100644
--- a/lib/lp/code/model/diff.py
+++ b/lib/lp/code/model/diff.py
@@ -10,6 +10,10 @@ __all__ = [
'PreviewDiff',
]
+try:
+ from contextlib import ExitStack
+except ImportError:
+ from contextlib2 import ExitStack
from cStringIO import StringIO
from operator import attrgetter
import sys
@@ -23,7 +27,6 @@ from breezy.patches import (
Patch,
)
from breezy.plugins.difftacular.generate_diff import diff_ignore_branches
-from contextlib2 import ExitStack
from lazr.delegates import delegate_to
import simplejson
from sqlobject import (
diff --git a/lib/lp/scripts/runlaunchpad.py b/lib/lp/scripts/runlaunchpad.py
index daa6471..11e06e4 100644
--- a/lib/lp/scripts/runlaunchpad.py
+++ b/lib/lp/scripts/runlaunchpad.py
@@ -6,13 +6,15 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = ['start_launchpad']
-
+try:
+ from contextlib import ExitStack
+except ImportError:
+ from contextlib2 import ExitStack
import os
import signal
import subprocess
import sys
-from contextlib2 import ExitStack
import fixtures
from lazr.config import as_host_port
from rabbitfixture.server import RabbitServerResources
diff --git a/lib/lp/services/config/__init__.py b/lib/lp/services/config/__init__.py
index a223fc6..80b1d0c 100644
--- a/lib/lp/services/config/__init__.py
+++ b/lib/lp/services/config/__init__.py
@@ -12,6 +12,10 @@ __metaclass__ = type
import glob
+try:
+ from importlib import resources
+except ImportError:
+ import importlib_resources as resources
import logging
import os
import sys
@@ -20,7 +24,6 @@ from urlparse import (
urlunparse,
)
-import importlib_resources
from lazr.config import ImplicitTypeSchema
from lazr.config.interfaces import ConfigErrors
import ZConfig
@@ -241,8 +244,7 @@ class LaunchpadConfig:
def _setZConfig(self):
"""Modify the config, adding automatically generated settings"""
- with importlib_resources.path(
- 'zope.app.server', 'schema.xml') as schemafile:
+ with resources.path('zope.app.server', 'schema.xml') as schemafile:
schema = ZConfig.loadSchema(str(schemafile))
root_options, handlers = ZConfig.loadConfig(
schema, self.zope_config_file)
diff --git a/lib/lp/services/config/tests/test_config.py b/lib/lp/services/config/tests/test_config.py
index 44928e4..e219ab0 100644
--- a/lib/lp/services/config/tests/test_config.py
+++ b/lib/lp/services/config/tests/test_config.py
@@ -12,11 +12,14 @@ from doctest import (
ELLIPSIS,
NORMALIZE_WHITESPACE,
)
+try:
+ from importlib import resources
+except ImportError:
+ import importlib_resources as resources
import os
import unittest
from fixtures import TempDir
-import importlib_resources
from lazr.config import ConfigSchema
from lazr.config.interfaces import ConfigErrors
import scandir
@@ -30,7 +33,7 @@ from lp.services.config.fixture import ConfigUseFixture
EXCLUDED_CONFIGS = ['lpnet-template']
# Calculate some landmark paths.
-with importlib_resources.path('zope.app.server', 'schema.xml') as schema_file:
+with resources.path('zope.app.server', 'schema.xml') as schema_file:
schema = ZConfig.loadSchema(str(schema_file))
here = os.path.dirname(lp.services.config.__file__)
diff --git a/lib/lp/services/webservice/wadl.py b/lib/lp/services/webservice/wadl.py
index eb70668..f11e2e1 100644
--- a/lib/lp/services/webservice/wadl.py
+++ b/lib/lp/services/webservice/wadl.py
@@ -5,11 +5,13 @@
__metaclass__ = type
+try:
+ from importlib import resources
+except ImportError:
+ import importlib_resources as resources
import subprocess
import urlparse
-import importlib_resources
-
from lp.services.webapp.interaction import (
ANONYMOUS,
setupInteractionByEmail,
@@ -57,7 +59,7 @@ def generate_html(wadl_filename, suppress_stderr=True):
# 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.
- with importlib_resources.path(
+ with resources.path(
'lp.services.webservice', 'wadl-to-refhtml.xsl') as stylesheet:
if suppress_stderr:
stderr = subprocess.PIPE
diff --git a/setup.py b/setup.py
index 0ab1ce4..8f97448 100644
--- a/setup.py
+++ b/setup.py
@@ -146,12 +146,12 @@ setup(
'ampoule',
'auditorclient',
'auditorfixture',
- 'backports.lzma',
+ 'backports.lzma; python_version < "3.3"',
'beautifulsoup4[lxml]',
'breezy',
'bzr',
'celery',
- 'contextlib2',
+ 'contextlib2; python_version < "3.3"',
'cssselect',
'cssutils',
'defusedxml',
@@ -164,8 +164,8 @@ setup(
'fixtures',
'geoip2',
'gunicorn[gthread]',
- 'importlib-resources',
- 'ipaddress',
+ 'importlib-resources; python_version < "3.7"',
+ 'ipaddress; python_version < "3.3"',
'ipython',
'jsautobuild',
'launchpad-buildd',