Context: Often demo examples are written assuming they are run from the command line. Sometimes these examples require importing components from outside of that file, e.g. here, here. However, when these examples are run from within the etsdemo, the sys.path is set for running the etsdemo application, and these imports would normally fail because they assume the local directory being on the path, which isn't true.
This inconsistency adds cognitive load to developers maintaining the examples: Developers need to keep in mind that the path is not what they typically expect.
The proposed solution would be to temporarily prepend to the sys.path the path of the directory containing the example file, similar to the behaviour when one runs the file from the command line.
This requires knowing exactly when the run context starts and ends, as the sys.path is a global state and it must be reverted back to how it was when the run context for an example terminates.
(Removing the demo tab will make determining the life-time of the run context a lot easier, see #1454)
Context: Often demo examples are written assuming they are run from the command line. Sometimes these examples require importing components from outside of that file, e.g. here, here. However, when these examples are run from within the etsdemo, the
sys.pathis set for running theetsdemoapplication, and these imports would normally fail because they assume the local directory being on the path, which isn't true.This inconsistency adds cognitive load to developers maintaining the examples: Developers need to keep in mind that the path is not what they typically expect.
The proposed solution would be to temporarily prepend to the
sys.paththe path of the directory containing the example file, similar to the behaviour when one runs the file from the command line.This requires knowing exactly when the run context starts and ends, as the
sys.pathis a global state and it must be reverted back to how it was when the run context for an example terminates.(Removing the demo tab will make determining the life-time of the run context a lot easier, see #1454)