-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow loading plugins from either scratchabit dir or working directory #7
Conversation
So, this patch tries to add loading plugins from a directory where scratchabit.py resides. Is that what you call "working directory"? I wouldn't call it such ;-). And funny thing, Python already should support that. I don't know how that works in presence of symlinks though. So, let's approach it from the other end - please describe the setup you have in mind, let's discuss whether it's the best setup, and then see how to support it. (Because loading executable stuff from arbitrary (or just too many) places is not source of confusion and security issues.) |
Hi Paul, By working directory I mean current working directory, os.getcwd(). What I'm trying to do: I'd like to keep my plugins dir in the same dir I'm using to keep scratchabit.py, then put that directory on my PATH. Then run scratchabit.py from anywhere on my system and have it load plugins correctly. At the moment I find I need to keep my .def files in the same directory as scratchabit. The patch I sent tries to keep the current behaviour as well (which I saw as finding plugins under cwd), so it looks in both places. The set(), abspath(), stuff is to remove duplicates - so not really necessary. It would be a much simpler patch without those two things. Angus -------- Original Message -------- So, this patch tries to add loading plugins from a directory where scratchabit.py resides. Is that what you call "working directory"? I wouldn't call it such ;-). And funny thing, Python already should support that. I don't know how that works in presence of symlinks though. So, let's approach it from the other end - please describe the setup you have in mind, let's discuss whether it's the best setup, and then see how to support it. (Because loading executable stuff from arbitrary (or just too many) places is not source of confusion and security issues.) Reply to this email directly or view it on GitHub: #7 (comment)Sent from my Android phone with K-9 Mail. Please excuse my brevity. |
Ok, so here's my userstory:
|
Python's analog of PATH is PYTHONPATH, and you can have the same behavior with setting that in environment. E.g., if you have scratchabit.py (somewhere else) in your PATH, and want to load plugins from current dir, run in it as:
No patching necessary. Not endorsed. Used at your own risk. |
I don't think I explained the reason for the pull request well enough. The behaviour of scratchabit without this patch is that any directory named 'plugins' has to be relative to cwd (or the plugin module has to live elsewhere on the python path to be found). At least that's been my experience. The only reason the original version of the patch supported looking for a plugins dir inside cwd is that I didn't want to break the existing behaviour, in case you wanted it that way. The user story you outlined matches my use case perfectly. I just pushed a new version of the patch, which only supports that use case. |
Right, now I got it. Yes, that's bug. |
# plugin dirs found in same directory as scratchabit | ||
plugin_dirs = [ "plugins", "plugins/cpu", "plugins/loader" ] | ||
for d in plugin_dirs: | ||
sys.path.append(os.path.join(sys.path[0], d)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using sys.path[0] looks a bit hacky, but __file__
isn't resolved for symlinks, so it would need to be done manually, which is boring. So, ok ;-).
Merged with minor changes, thanks! |
Hi Paul,
Small change I found useful when working outside the scratchabit directory itself.
Cheers,
Angus