Fixes #10258 - Allow running scripts nested in modules/packages #10290
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #10258
The purpose of this FR is to allow a structure like this:
All scripts contain (with the numbers replaced):
The
__init__.pyfile in thetestscriptfoldercontains:This setup results in the following script list with the PR:
This is achieved by splitting import paths so that the module_name contains the base module only, while the script name contains the rest of the path. For Script3 the import path would look like:
testscriptfolder.testnestedfolder.script3which would be split to:The advantage is that scripts become much easier to manage as before the only way to have scripts grouped under the same module was to have them all in the same file. With long scripts this instantly becomes unwieldy.
I tested every combination I could come up with, and as far as I can tell defining custom names for the scripts still work. Defining custom names for the module still works (done in the
__init__.pyfile). Calling scripts from the API still works. Script ordering still works.I'm not sure if this is the right approach. As far as I can tell it doesn't break anything, but it's hard to guarantee that people haven't found crazy ways around the limitations of script loading. I would really like some feedback and help testing here. Maybe there's a better way to achieve better script organization that I'm missing.
Another limitation is that I haven't touched reports here.