gsohler / openscad

OpenSCAD - The Programmers Solid 3D CAD Modeller
https://www.openscad.org
Other
14 stars 6 forks source link

python stub file for openscad module #25

Open fzellini opened 2 months ago

fzellini commented 2 months ago

For python, there are many IDEs better than integrated openscad editor, and, since openscad module is implemented as native library, stub file is needed for syntax checking and autocompletion.

gsohler commented 2 months ago

I like the idea of having python stub files(pyi). Everything which helps user experience will help to become popular. (and its even some sort of quick cheat sheet showing all the functions and paramters) Just now I am wondering, if i started to write the stub file, whats an easy editor to test them with ?

fzellini commented 2 months ago

with pycharm you can create and check stub files

fzellini commented 2 months ago

Seems very nice :-D Maybe a simple script that parse c++ code and generate python stub would help

# openscad.pyi
class PyOpenSCAD:
    def color (self, c:str, alpha: float, texture:str) -> PyOpenSCAD:
        ...
    def rotx (self, float) -> PyOpenSCAD:
        ...
    def translate (self, v:float | list[float]) -> PyOpenSCAD:
        ...

def cube( size:float | list[float], center: bool) -> PyOpenSCAD: ...

image

KlumpRasmus commented 2 months ago

I am using VS Code. It would be great with type-hints and autocompletion.

gsohler commented 2 months ago

already working on a stub file. hope to provide it today or tomorrow ...

gsohler commented 2 months ago

i have checked 1st version of the stubs file

its in

https://github.com/gsohler/openscad/blob/python/libraries/python/openscad.pyi

not yet installed PyCharm due to size reasons.

anybody want to test the file and send me improvements/corrections ?

fzellini commented 2 months ago

Nice work, there are unresolved reference to PyOpenSCAD and PyLibFive, and method parameters defined as "string" instead of "str". relatively to PyOpenSCAD class, the methods of that object should be the ones listed here under OO_METHOD_ENTRY right ?

gsohler commented 2 months ago

Hi fzellini. i think now python likes it. Yes, you exactly found the place, where i define pythonscad methods. once the functions are settled, i will copy over to methods.

gsohler commented 1 month ago

updated the stubs today. you are free to check now