Edgewall Software
Modify

Opened 15 years ago

Closed 15 years ago

#3009 closed enhancement (fixed)

Proposal to add the ability to load raw .py files as plugins

Reported by: Alec Thomas Owned by: Christopher Lenz
Priority: low Milestone: 0.10
Component: general Version: devel
Severity: minor Keywords: plugin
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

I believe it's a bit of a barrier for new plugin authors having to create .egg files. Chris proposed on #trac that .py files in the plugins directory be loaded as plugins and this patch implements the feature.

Attachments (3)

load-py-plugins.diff (3.2 KB ) - added by Alec Thomas 15 years ago.
Better loader. Uses the setuptools infrastructure if available.
load-py-plugins.2.diff (1.3 KB ) - added by Alec Thomas 15 years ago.
New version of old patch with logging as requested
load-py-plugins.3.diff (1.4 KB ) - added by Alec Thomas 15 years ago.
Cleaner version using imp.load_source and no longer fondling sys.path

Download all attachments as: .zip

Change History (12)

comment:1 by Alec Thomas, 15 years ago

Better patch coming soon.

by Alec Thomas, 15 years ago

Attachment: load-py-plugins.diff added

Better loader. Uses the setuptools infrastructure if available.

comment:2 by Alec Thomas, 15 years ago

This new patch uses setuptools to fake a plugin on the fly. Perhaps there is a better way to create the fake entry point, but I couldn't figure out how.

comment:3 by Christian Boos, 15 years ago

What's the point to masquerade those "light" plugins as eggs? I was going to suggest to simply add a line of self.log('Loading source file "%s" ... to the initial patch, in order to make clear what was going on.

I fear a little bit that your latest solution might confuse the users (especially someone who's reading the log and hasn't installed the .py files himself), but then, I'm certainly missing the advantages that this approach might have…

comment:4 by Alec Thomas, 15 years ago

My idea was to make the light plugins as plugin-like as possible, to avoid breakage. However it looks like there is even more mojo required (in the form of creating and registering a pkg_resources distribution finder of .py files), so it's probably not worth it.

Fake eggs have the advantage that (ideally) they would be completely transparent; they could be dependencies for other plugins, etc. It's probably overkill though, so I'll attach the basic loader patch again.

comment:5 by Alec Thomas, 15 years ago

One other point to note is that this breaks WebAdmin's plugin module. I believe this is due to the distribution finder being unable to locate the module because there is no registered finder for .py files.

comment:6 by Alec Thomas, 15 years ago

This patches WebAdmin to work with the .py plugins:

  • webadmin/plugin.py

     
    204204        path = module.__file__
    205205        if path.endswith('.pyc') or path.endswith('.pyo'):
    206206            path = path[:-1]
     207        file = path
    207208        if os.path.basename(path) == '__init__.py':
    208209            path = os.path.dirname(path)
    209210        path = _find_base_path(path, module.__name__)
     
    214215        else:
    215216            for dist in pkg_resources.find_distributions(path, only=True):
    216217                return dist
     218            plugins_dir = os.path.realpath(os.path.join(self.env.path,
     219                                                        'plugins'))
     220            if path == plugins_dir and file.endswith('.py'):
     221                module_name = os.path.basename(file[:-3])
     222                return pkg_resources.Distribution(project_name=module_name,
     223                                                  version='0.1',
     224                                                  location=path)
    217225
     226
    218227    def _get_pkginfo(self, dist):
    219228        attrs = ('author', 'author-email', 'license', 'home-page', 'summary',
    220229                 'description')

by Alec Thomas, 15 years ago

Attachment: load-py-plugins.2.diff added

New version of old patch with logging as requested

comment:7 by Christopher Lenz, 15 years ago

Owner: changed from Jonas Borgström to Christopher Lenz
Status: newassigned

Lovely :-)

by Alec Thomas, 15 years ago

Attachment: load-py-plugins.3.diff added

Cleaner version using imp.load_source and no longer fondling sys.path

comment:8 by Christopher Lenz, 15 years ago

Slightly modified patch applied in [3128]. WebAdmin update to follow…

comment:9 by Christopher Lenz, 15 years ago

Resolution: fixed
Status: assignedclosed

WebAdmin updated in [3129].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christopher Lenz.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christopher Lenz to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.