Python editor module search path, scan subdirectories wish

would it be possible for it to search subdirectories. i imagine a lot of people would have their script repository organized into directories like myself and if you have a lot of folders it’s a pita. thank you.

2020-10-07 08_39_24-Window

Yeah, that would be cool, I have 70 subfolders in my scripts directory - I finally just made one folder for all the scripts that I actually use via toolbars/aliases and put copies in there… Just need to remember to replace the ones in that folder with new updated ones if I make any mods.

Hello,

It should be possible to automatically add subdirectories to your sys.path on startup. Python wold take the first file found without searching further down the path list

that’s what i was going to resort tobut i went ahead and added the 20 some odd folders.

yeah, 70 folders would be too many for my patience.

Can you detail a procedure for that?

that wouldn’t add it to Rhino’s path’s though would it?

Scripts inside of folders can be referenced using package syntax (folder namer . script name) Is that not working for you?

Yes, but if I understand correctly that means you need to specify a discreet path for each script. The idea was to be able to specify a top level folder in the script editor and have Rhino/Python search the subfolders - like Rhinoscript does for the folders specified in Options>Files>Search paths.

I mean you should be able to execute MySubdirectory.MyScript.py

OK, but that still means that you need to have a semi-discreet path specified (i.e. you need to know what subfolder it’s in). If everything is in a top-level folder and a search path in the editor is set for that folder you can just use

_NoEcho ! _-RunPythonScript "scriptname.py"

The idea is that if there were folders under the top level folder with scripts in them, the above would still work to find them.

1 Like

Changing this to recursively search would break python packages that people may write. I could add some magic wildcard llike a * at the end of the path, but I doubt more than two people would ever discover such a hidden feature.

they might if it’s in the documentation. however, after years i just learned that you can add paths there and run the scripts without the fullpath. so i can see your point.

Sometimes I just need to say no. I’m not going to add this feature. Python was designed with the concept of modules and packages where sets of scripts are grouped together inside a directory (package). I don’t want to make any change that breaks this behavior.

fair enough.

Ahh good question - I guess you would lose them again as soon as the script finishes…

Something like

sys.path.extend(set([x for x,_,_ in os.walk(os.getcwd())]))

Not tested :smiley:

1 Like