6

Merge into devel : avoid-importing-bzr-plugins-from-site : Code : Launchpad itse...

 3 years ago
source link: https://code.launchpad.net/~cjwatson/launchpad/avoid-importing-bzr-plugins-from-site/+merge/335379
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Merge lp:~cjwatson/launchpad/avoid-importing-bzr-plugins-from-site into lp:launchpad

  1. avoid-importing-bzr-plugins-from-site
  2. Merge into devel

Proposed by Colin Watson on 2017-12-19

Status:

Merged Merged at revision: 18518 Proposed branch: lp:~cjwatson/launchpad/avoid-importing-bzr-plugins-from-site Merge into: lp:launchpad Diff against target: 78 lines (+16/-19)

To merge this branch: bzr merge lp:~cjwatson/launchpad/avoid-importing-bzr-plugins-from-site Related bugs:

Reviewer Review Type Date Requested Status Colin Watson Approve on 2017-12-19 Review via email: mail[email protected]

Commit message

Suppress Branch security proxies in lp.codehosting, not lp_sitecustomize.

The latter runs too early to be able to safely import Bazaar plugins.

Description of the change

Python doesn't set up sys.getfilesystemencoding() until shortly after it's finished importing site, so if we try to import Bazaar plugins from a sitecustomize hook then any initialisation calls they make to bzrlib.i18n.load_plugin_translations will fail, causing great confusion. Anything that needs Bazaar plugins is already supposed to import lp.codehosting, so this should be a safe rearrangement.

To post a comment you must log in.

review: Approve

Self-reviewing since this is a testfix and the test suite should catch anything overly interesting.

Preview Diff

1=== modified file 'lib/lp/codehosting/__init__.py'2--- lib/lp/codehosting/__init__.py 2017-09-27 02:12:20 +00003+++ lib/lp/codehosting/__init__.py 2017-12-19 13:14:50 +00004@@ -17,9 +17,11 @@5 import os6 7 import bzrlib8+from bzrlib.branch import Branch9 from bzrlib.plugin import load_plugins10 # This import is needed so that bzr's logger gets registered.11 import bzrlib.trace12+from zope.security import checker13 14 from lp.services.config import config15 16@@ -63,3 +65,16 @@17 18 19 load_bundled_plugin("weave_fmt")20+21+22+def dont_wrap_class_and_subclasses(cls):23+ checker.BasicTypes.update({cls: checker.NoProxy})24+ for subcls in cls.__subclasses__():25+ dont_wrap_class_and_subclasses(subcls)26+27+28+# Don't wrap Branch or its subclasses in Zope security proxies. Make sure29+# the various LoomBranch classes are present first.30+import bzrlib.plugins.loom.branch31+bzrlib.plugins.loom.branch32+dont_wrap_class_and_subclasses(Branch)3334=== modified file 'lib/lp_sitecustomize.py'35--- lib/lp_sitecustomize.py 2017-10-21 19:11:38 +000036+++ lib/lp_sitecustomize.py 2017-12-19 13:14:50 +000037@@ -8,8 +8,8 @@38 import itertools39 import logging40 import os41+import sys42 import warnings43-import sys44 45 from twisted.internet.defer import (46 Deferred,47@@ -127,23 +127,6 @@48 logging.getLogger('txn').addHandler(txn_handler)49 50 51-def dont_wrap_class_and_subclasses(cls):52- checker.BasicTypes.update({cls: checker.NoProxy})53- for subcls in cls.__subclasses__():54- dont_wrap_class_and_subclasses(subcls)55-56-57-def dont_wrap_bzr_branch_classes():58- from bzrlib.branch import Branch59- # Load bzr plugins60- import lp.codehosting61- lp.codehosting62- # Force LoomBranch classes to be listed as subclasses of Branch63- import bzrlib.plugins.loom.branch64- bzrlib.plugins.loom.branch65- dont_wrap_class_and_subclasses(Branch)66-67-68 def silence_warnings():69 """Silence warnings across the entire Launchpad project."""70 # pycrypto-2.0.1 on Python2.6:71@@ -190,7 +173,6 @@72 customizeMimetypes()73 silence_warnings()74 customize_logger()75- dont_wrap_bzr_branch_classes()76 checker.BasicTypes.update({defaultdict: checker.NoProxy})77 checker.BasicTypes.update({Deferred: checker.NoProxy})78 checker.BasicTypes.update({DeferredList: checker.NoProxy})

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK