Skip to content

Model file/script unable to load python file from parent directory #36

@justbuchanan

Description

@justbuchanan

I have a setup something like this:

# file /models/model.py

# add parent dir to path so we can import my_utils
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))

from my_utils import *

# build a model...
# file /my_utils.py

# define some helper functions...

This works fine when loading /models/model.py in cq-editor and when loading the model with python /models/model.py. However, when using cq-cli to render the model, I get NameError: name '__file__' is not defined. Did you mean: '__name__'? (note that __name__ is "cqgi").

I haven't investigated this much yet, but I think this has to do with the way cq-cli is loading the model script by reading it as a text file, then passing it to cqgi.parse().

Any suggestions for what the best/right approach is here? Is it reasonable for cq-cli to set the __file__ variable to the script file's path? Or should I be doing something like PYTHONPATH=<parent directory> cq-cli /models/model.py?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions