CadQuery / CadQuery/cq-cli

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

Open
#36 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
30
Forks
10
PR merge metrics
No merged PRs in 30d

Description

I have a setup something like this:

```.py
# 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...
```

```.py
# 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= cq-cli /models/model.py`?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.