Convenience technique when organizing PythonScripts into folders
Alan Kilborn last edited by Alan Kilborn
So being someone that has a lot of Notepad++ Pythonscripts…I need to apply some organizational techniques to keep them, well, organized. What this means basically is that I like to create folders for them, based upon what they do.
I’ve probably taken this to a bit of an extreme(!), but here’s what my
Scriptsmenu looks like:
I’ve highlighted in yellow the entries that PythonScript has put there by default; the rest are mine and as you can see, a lot of new folders I’ve created here…(you can tell they are folders by the
>off to the right).
I’ve noticed that if I want to use a script from one of these folders in a script that lives in another folder, by default Notepad++ won’t be able to find it, example:
import NotepadGetStatusBarin one script can result in this error at runtime (this is a real-world example from the script I show HERE ):
Now sure, there are ways to avoid this problem by including path information on the import, but, ok, that’s annoying because I have to look up that path, and then what if I move some scripts around later based upon, I don’t know, maybe a better way of categorizing them?
What I’ve done to avoid this is to add a bit of code to my
startup.pyso that one script can “find” another, without the need for any additional specification.
The code looks like this:
import os # add scripts folder tree to the sys.path list # (makes it easy to call a script anywhere in the tree by using only the script's base name) for (root, dirs, files) in os.walk(notepad.getPluginConfigDir() + r'\PythonScript\scripts', topdown=False): if root not in sys.path: sys.path.append(root)
I’m showing this in the event that it helps someone else streamline their work and organize their scripts better, with minimal pain in the event they call one script from another.
Nick Brown last edited by
I also use the following to add any python libraries to the PythonScript plugin install as well
libDir = r'C:\\Notepad++\\plugins\\PythonScript\\lib' try: sys.path.index(libDir) except ValueError: sys.path.append(libDir)
Alan Kilborn last edited by
While we’re on this general subject, if I add this code in:
for p in sys.path: if not os.path.isdir(p): print(p)
I see this (but leading paths removed) in the console after Notepad++ starts up:
...\npp.126.96.36.199.portable.x64\plugins\Config\PythonScript\lib ...\npp.188.8.131.52.portable.x64\plugins\PythonScript\lib\lib-tk ...\npp.184.108.40.206.portable.x64\plugins\PythonScript\python27.zip ...\npp.220.127.116.11.portable.x64\DLLs ...\npp.18.104.22.168.portable.x64\lib ...\npp.22.214.171.124.portable.x64\lib\plat-win ...\npp.126.96.36.199.portable.x64\lib\lib-tk
Now, I don’t “install” PythonScript, and I don’t need Tk, so I don’t manually install that, but some of these others seem a bit oddball.
libones, right off of the main N++ folder…
Michael Vincent last edited by
but here’s what my Plugins > PythonScript > Scripts menu looks like:
WOW, that’s a lot of scripts! Do you “share” them anywhere - GitHub for example?
Alan Kilborn last edited by
Do you “share” them anywhere - GitHub for example?
Well, I share the ones that I think have general usage, or maybe something I’ve developed to answer a question here…and I share them, well, here on the Community.
I’ve thought about gists on Github, but haven’t gone there with them as yet.
PeterJones last edited by
I used to have all of my scripts in a private repo at some svn-based competitor to github that allowed free private repos. I would just check out that repo as my user scripts folder on any machine I’m working on, and automatically get all my scripts wherever I go.
As I started sharing more of my scripts, I played a bit with gists, but didn’t like that i had two copies of some scripts – one in the private repo and one in the gist.
I realized that I didn’t have any proprietary/private scripts (and if I did, I could put them in my system scripts folder instead), so I moved the repo to my github, so I can share any of them.
So it’s not Alan’s collection, but my collection is at https://github.com/pryrt/nppStuff/tree/main/pythonScripts … and the nppCommunity subdirectory is the ones I’ve developed for or snagged from this forum, mostly organized by topic-ID.