65
67
addressed by using lazy import or lazy hook registration.
71
self.preserved_env_vars = {}
72
for name in ('BZR_DISABLE_PLUGINS', 'BZR_PLUGINS_AT'):
73
self.preserved_env_vars[name] = os.environ.get(name)
74
super(TestImportTariffs, self).setUp()
68
76
def start_bzr_subprocess_with_import_check(self, args, stderr_file=None):
69
77
"""Run a bzr process and capture the imports.
71
79
This is fairly expensive because we start a subprocess, so we aim to
72
80
cover representative rather than exhaustive cases.
74
# We use BZR_PLUGIN_PATH and BZR_PLUGINS_AT to explicitly set the
75
# subprocess to use the same plugins as this process. Plugins without
76
# filesystem paths (perhaps they are in a zip package or frozen python
77
# exe?) cannot be loaded this way so are omitted.
78
loaded_plugin_info = [
79
(name, plugin.path(default_to_None=True))
80
for (name, plugin) in plugins().items()]
82
'%s@%s' % (name, path)
83
for (name, path) in loaded_plugin_info if path is not None]
84
82
# We use PYTHON_VERBOSE rather than --profile-imports because in
85
83
# experimentation the profile-imports output seems to not always show
86
84
# the modules you'd expect; this can be debugged but python -v seems
87
85
# more likely to always show everything. And we use the environment
88
86
# variable rather than 'python -v' in the hope it will work even if
89
87
# bzr is frozen and python is not explicitly specified. -- mbp 20100208
90
env_changes = dict(PYTHONVERBOSE='1', BZR_PLUGIN_PATH="-site:-core",
91
BZR_PLUGINS_AT=':'.join(plugins_at))
88
# We use BZR_PLUGIN_PATH to explicitly set the subprocess to use the
89
# same plugins as this process.
90
plugin_path = os.pathsep.join(
91
['-core', '-site'] + _mod_plugins.__path__)
92
env_changes = dict(PYTHONVERBOSE='1', BZR_PLUGIN_PATH=plugin_path)
93
env_changes.update(self.preserved_env_vars)
92
94
trace.mutter('Setting env for bzr subprocess: %r', env_changes)
93
95
kwargs = dict(env_changes=env_changes,
94
96
allow_plugins=(not are_plugins_disabled()))