Model file/script unable to load python file from parent directory
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Reproduce the failure with the shown /models/model.py and /my_utils.py layout, then inspect how cq-cli reads the script and passes it to cqgi.parse(). Compare that path with direct Python execution and cq-editor loading. Done means the parent-directory import works through cq-cli, with the chosen file or PYTHONPATH behavior established.
Written by the indexing model from the issue text.
Description
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?
- Dominant language
- Python
- Stars
- 30
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from CadQuery/cq-cli
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100