Skip to content

Temporarily modify sys.path when executing example file in etsdemo #1455

@kitchoi

Description

@kitchoi

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions