Create .pyi file automatically from cython source?
Asked Answered
P

1

10

How can I create .pyi files from cython source code (.pyx)?

Polygraph answered 29/9, 2019 at 12:48 Comment(7)
I think there's been a few (1 2 3) people asking for this over the last few years, but nobody's actually done it yet... It's possible that someone may have a better answer, but I think the current status is "no, but it would probably be possible to integrate this with Cython if someone wants to write the code"Unequaled
This project does it: pypi.org/project/cythonbuilderGasholder
@IyadAhmed I think cythonbuilder generates HTML files, doesn't it?Whipperin
I tried it and it generated .pyi files ^^, maybe it had an option for HTML but didn't @Whipperin encounter it ^^Gasholder
@IyadAhmed you are right. cybuilder build command generates pyi by default. Maybe you can write an answer to this unanswered question?:)Whipperin
Ok will try to doGasholder
There are some more tools listed here: groups.google.com/g/cython-users/c/Dmlew1oNLywAlum
G
2

You can use the cythonbuilder package for that, https://pypi.org/project/cythonbuilder/

  1. Install cythonbuilder: pip install cythonbuilder
  2. Use the command cythonbuilder.exe build -y to automatically build all .pyx file in current working directory and generate .pyi files.

Example cythnobuilder project

Gasholder answered 17/3, 2023 at 12:47 Comment(2)
CythonBuilder did not fit naturally into my setup.py files. It needed some modification to support some cython types. All the parsing code is located in: github.com/mikehuls/cythonbuilder/blob/main/cythonbuilder/… It does not support all cython syntax but it was workable with a few updates. Eventually, I created my own parser with pyparsing. It is a bit overkill for creating stub files but allows for modifications. It supported most of cython stub related syntax. github.com/RaubCamaioni/CythonPEG/blob/main/cython_peg.pyNicotiana
Amazing work! ~~filler text to post comment~~Gasholder

© 2022 - 2024 — McMap. All rights reserved.