Merge lp:~mars/tarmac/fix-plugin-import into lp:tarmac

Proposed by Māris Fogels
Status: Rejected
Rejected by: Paul Hummer
Proposed branch: lp:~mars/tarmac/fix-plugin-import
Merge into: lp:tarmac
Diff against target: 29 lines (+5/-1)
1 file modified
tarmac/plugin.py (+5/-1)
To merge this branch: bzr merge lp:~mars/tarmac/fix-plugin-import
Reviewer Review Type Date Requested Status
Paul Hummer Disapprove
Review via email: mp+42954@code.launchpad.net

Description of the change

Hi,

This branch presents a quick and dirty fix to the Tarmac plugin activation code. It adds the Tarmac plugin directories to the system path so that Tarmac can import the plugins.

There may be a better way to do this, but I am leaving that better implementation for someone else to tackle. The code passed manual testing on my local system.

Maris

To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) wrote :

So, the idea here was to create a similar environment to the way bzr imports its plugins (from bzrlib.plugins import whatever). This patch breaks that idea. I think we need to dig deeper into the bzrlib plugin registration code to see why this is not working (I'm pretty sure it worked at some point, so maybe we broke it).

I appreciate that you've found the bug, and that you've proposed a fix. I think this breaks the api we want to use (even though that API is broken as well), so I'm not sure this is the correct way to do this.

review: Disapprove
Revision history for this message
dobey (dobey) wrote :

I think the code (probably in bzrlib too), needs to perhaps switch over to using imp.find_module() and imp.load_module(), to do the plug-in loading. Doing the exec 'import foo' is extra nasty. Even just doing __import__() instead would at least be better code, even if it doesn't solve this specific bug.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tarmac/plugin.py'
2--- tarmac/plugin.py 2010-09-02 15:18:07 +0000
3+++ tarmac/plugin.py 2010-12-07 15:04:10 +0000
4@@ -18,6 +18,7 @@
5
6 import imp
7 import os
8+import sys
9
10 from tarmac import plugins as _mod_plugins
11
12@@ -40,6 +41,9 @@
13
14 plugin_names = set()
15 for path in TARMAC_PLUGIN_PATHS:
16+ if path not in sys.path:
17+ sys.path.insert(0, path)
18+
19 try:
20 for _file in os.listdir(path):
21 full_path = os.path.join(path, _file)
22@@ -75,6 +79,6 @@
23
24 for name in plugin_names:
25 try:
26- exec 'import tarmac.plugins.%s' % name in {}
27+ exec 'import %s' % name in {}
28 except KeyboardInterrupt:
29 raise

Subscribers

People subscribed via source and target branches