CadQuery / CadQuery/cq-cli

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

Abierto
#36 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
30
Forks
10
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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`?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
cli
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.