Opened 19 years ago
Closed 19 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)
Change History (12)
comment:1 by , 19 years ago
by , 19 years ago
Attachment: | load-py-plugins.diff added |
---|
Better loader. Uses the setuptools infrastructure if available.
comment:2 by , 19 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 , 19 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 , 19 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 , 19 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 , 19 years ago
This patches WebAdmin to work with the .py plugins:
-
webadmin/plugin.py
204 204 path = module.__file__ 205 205 if path.endswith('.pyc') or path.endswith('.pyo'): 206 206 path = path[:-1] 207 file = path 207 208 if os.path.basename(path) == '__init__.py': 208 209 path = os.path.dirname(path) 209 210 path = _find_base_path(path, module.__name__) … … 214 215 else: 215 216 for dist in pkg_resources.find_distributions(path, only=True): 216 217 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) 217 225 226 218 227 def _get_pkginfo(self, dist): 219 228 attrs = ('author', 'author-email', 'license', 'home-page', 'summary', 220 229 'description')
by , 19 years ago
Attachment: | load-py-plugins.2.diff added |
---|
New version of old patch with logging as requested
by , 19 years ago
Attachment: | load-py-plugins.3.diff added |
---|
Cleaner version using imp.load_source and no longer fondling sys.path
comment:9 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Better patch coming soon.