SolidCode / SolidPython

A python frontend for solid modelling that compiles to OpenSCAD
1.1k stars 171 forks source link

use seems to not handle relative path correctly #168

Open jeff-dh opened 3 years ago

jeff-dh commented 3 years ago

When I change the examples/basic_scad_include.py file to use the demo_scad_use function instead of the demo_import_scad function SolidPython is -- at least in my environment -- not able to resolve scad_to_include.scad in certain situations.

Running basic_scad_include.py (with demo_scad_use enabled) from a directory that is not in sys.path results in the following trace:

jeff@nups ~/code $python3 SolidPython/solid/examples/basic_scad_include.py 
Traceback (most recent call last):
  File "SolidPython/solid/examples/basic_scad_include.py", line 31, in <module>
    a = demo_scad_use()
  File "SolidPython/solid/examples/basic_scad_include.py", line 26, in demo_scad_use
    return steps(5)
  File "<string>", line 4, in __init__
  File "/home/jeff/.local/lib/python3.6/site-packages/solid/solidpython.py", line 372, in __init__
    self.include_file_path = self._get_include_path(include_file_path)
  File "/home/jeff/.local/lib/python3.6/site-packages/solid/solidpython.py", line 396, in _get_include_path
    raise ValueError(f"Unable to find included SCAD file: {include_file_path} in sys.path")
ValueError: Unable to find included SCAD file: SolidPython/solid/examples/scad_to_include.scad in sys.path

The issue is caused by the ctor of the IncludedOpenSCADObject. It calls self._get_include_path to resolve the file but the self._get_include_path function -- for some reason -- tries to find the file using the Python-Path (sys.path) to resolve a *.scad file. This seems pretty strange to me and only works by accident if you call it from withing sys.path and/or SolidPython is installed in sys.path (I can't wrap my head around it which combinations it is exactly but these two factors seem to be the key).

Replacing the call to self._get_include_path with a call to objects._find_library seems to work but I'm not sure whether it's supposed to be that way and whether -- or not -- this might have side effects.

Note: when using import_scad everything is fine.