GithubHelp home page GithubHelp logo

Generate type stubs about skia-python HOT 4 OPEN

kyamagu avatar kyamagu commented on July 19, 2024 5
Generate type stubs

from skia-python.

Comments (4)

Nukiloco avatar Nukiloco commented on July 19, 2024 3

It has been some what annoying so far having to look back and forth between the documentation/api and my code just to know what returns and what methods the skia package gives. Will there be a fix for this soon?

from skia-python.

shuhei avatar shuhei commented on July 19, 2024 2

I tried pybind11-stubgen and mypy's stubgen from the issue description. I'll share some findings here even though I haven't figured out a working solution for everyone.

pybind11-stubgen skia didn't generate stubs due to errors.

$ pip install pybind11-stubgen
$ pybind11-stubgen skia
[2022-03-13 17:12:47,680] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,680] {__init__.py:135} ERROR - def search(self: skia.BBoxHierarchy, query: skia.Rect, results: std::__1::vector<int, std::__1::allocator<int> >) -> None: ...
[2022-03-13 17:12:47,680] {__init__.py:136} ERROR -                                                                    ^-- Invalid syntax
[2022-03-13 17:12:47,713] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,713] {__init__.py:135} ERROR - def drawLine(self: skia.Canvas, x0: float, y0: float, x1: float, y1`: float, paint: skia.Paint) -> None: ...
[2022-03-13 17:12:47,714] {__init__.py:136} ERROR -                                                                    ^-- Invalid syntax
[2022-03-13 17:12:47,875] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,875] {__init__.py:135} ERROR - def queryYUVAInfo(self: skia.Codec, supportedDataTypes: SkYUVAPixmapInfo::SupportedDataTypes) -> object: ...
[2022-03-13 17:12:47,875] {__init__.py:136} ERROR -                                                                         ^-- Invalid syntax
[2022-03-13 17:12:47,903] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,903] {__init__.py:135} ERROR - def page(self: skia.Document, width: float, height: float) ->  : ...
[2022-03-13 17:12:47,903] {__init__.py:136} ERROR -                                                                ^-- Invalid syntax
[2022-03-13 17:12:47,946] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,946] {__init__.py:135} ERROR - def MakeMock(colorType: skia.GrColorType, compression: SkImage::CompressionType) -> skia.GrBackendFormat: ...
[2022-03-13 17:12:47,946] {__init__.py:136} ERROR -                                                               ^-- Invalid syntax
[2022-03-13 17:12:47,947] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,947] {__init__.py:135} ERROR - def asMockCompressionType(self: skia.GrBackendFormat) -> SkImage::CompressionType: ...
[2022-03-13 17:12:47,947] {__init__.py:136} ERROR -                                                                  ^-- Invalid syntax
[2022-03-13 17:12:47,957] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,957] {__init__.py:135} ERROR - def compressedBackendFormat(self: skia.GrContext, compressionType: SkImage::CompressionType) -> skia.GrBackendFormat: ...
[2022-03-13 17:12:47,957] {__init__.py:136} ERROR -                                                                           ^-- Invalid syntax
[2022-03-13 17:12:47,958] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,958] {__init__.py:135} ERROR - def createCompressedBackendTexture(self: skia.GrContext, width: int, height: int, type: SkImage::CompressionType, color: skia.Color4f, mipMapped: skia.GrMipmapped, isProtected: skia.GrProtected = GrProtected.kNo) -> skia.GrBackendTexture: ...
[2022-03-13 17:12:47,958] {__init__.py:136} ERROR -                                                                                                ^-- Invalid syntax
[2022-03-13 17:12:47,958] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,958] {__init__.py:135} ERROR - def createCompressedBackendTexture(self: skia.GrContext, width: int, height: int, type: SkImage::CompressionType, data: buffer, mipMapped: skia.GrMipmapped, isProtected: skia.GrProtected = GrProtected.kNo) -> skia.GrBackendTexture: ...
[2022-03-13 17:12:47,958] {__init__.py:136} ERROR -                                                                                                ^-- Invalid syntax
[2022-03-13 17:12:47,967] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,967] {__init__.py:135} ERROR - def compressedBackendFormat(self: skia.GrContext_Base, arg0: SkImage::CompressionType) -> skia.GrBackendFormat: ...
[2022-03-13 17:12:47,967] {__init__.py:136} ERROR -                                                                     ^-- Invalid syntax
[2022-03-13 17:12:47,971] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,971] {__init__.py:135} ERROR - def __init__(self: skia.GrMockTextureInfo, colorType: skia.GrColorType, compressionType: SkImage::CompressionType, id: int) -> None: ...
[2022-03-13 17:12:47,971] {__init__.py:136} ERROR -                                                                                                 ^-- Invalid syntax
[2022-03-13 17:12:47,971] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:47,972] {__init__.py:135} ERROR - def compressionType(self: skia.GrMockTextureInfo) -> SkImage::CompressionType: ...
[2022-03-13 17:12:47,972] {__init__.py:136} ERROR -                                                              ^-- Invalid syntax
[2022-03-13 17:12:48,001] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:48,001] {__init__.py:135} ERROR - def MakeFromNV12TexturesCopy(context: skia.GrContext, yuvColorSpace: skia.YUVColorSpace, nv12Textures: std::__1::vector<GrBackendTexture, std::__1::allocator<GrBackendTexture> >, imageOrigin: skia.GrSurfaceOrigin, imageColorSpace: skia.ColorSpace = None) -> skia.Image: ...
[2022-03-13 17:12:48,001] {__init__.py:136} ERROR -                                                                                                           ^-- Invalid syntax
[2022-03-13 17:12:48,001] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:48,002] {__init__.py:135} ERROR - def MakeFromNV12TexturesCopyWithExternalBackend(context: skia.GrContext, yuvColorSpace: skia.YUVColorSpace, nv12Textures: std::__1::vector<GrBackendTexture, std::__1::allocator<GrBackendTexture> >, imageOrigin: skia.GrSurfaceOrigin, backendTexture: skia.GrBackendTexture, imageColorSpace: skia.ColorSpace = None) -> skia.Image: ...
[2022-03-13 17:12:48,002] {__init__.py:136} ERROR -                                                                                                                              ^-- Invalid syntax
[2022-03-13 17:12:48,009] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:48,009] {__init__.py:135} ERROR - def MakeFromYUVAPixmaps(context: skia.GrRecordingContext, yuvaPixmaps: skia.YUVColorSpace, yuvaTextures: std::__1::vector<SkPixmap, std::__1::allocator<SkPixmap> >, yuvaIndices: std::__1::vector<SkYUVAIndex, std::__1::allocator<SkYUVAIndex> >, imageSize: skia.ISize, imageOrigin: skia.GrSurfaceOrigin, buildMips: bool, limitToMaxTextureSize: bool = False, imageColorSpace: skia.ColorSpace = None) -> skia.Image: ...
[2022-03-13 17:12:48,009] {__init__.py:136} ERROR -                                                                                                             ^-- Invalid syntax
[2022-03-13 17:12:48,010] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:48,010] {__init__.py:135} ERROR - def MakeFromYUVATextures(context: skia.GrContext, yuvColorSpace: skia.YUVColorSpace, yuvaTextures: std::__1::vector<GrBackendTexture, std::__1::allocator<GrBackendTexture> >, yuvaIndices: std::__1::vector<SkYUVAIndex, std::__1::allocator<SkYUVAIndex> >, imageSize: skia.ISize, imageOrigin: skia.GrSurfaceOrigin, imageColorSpace: skia.ColorSpace = None) -> skia.Image: ...
[2022-03-13 17:12:48,010] {__init__.py:136} ERROR -                                                                                                       ^-- Invalid syntax
[2022-03-13 17:12:48,011] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:48,011] {__init__.py:135} ERROR - def MakeFromYUVATexturesCopy(context: skia.GrRecordingContext, yuvColorSpace: skia.YUVColorSpace, yuvaTextures: std::__1::vector<GrBackendTexture, std::__1::allocator<GrBackendTexture> >, yuvaIndices: std::__1::vector<SkYUVAIndex, std::__1::allocator<SkYUVAIndex> >, imageSize: skia.ISize, imageOrigin: skia.GrSurfaceOrigin, imageColorSpace: skia.ColorSpace = None) -> skia.Image: ...
[2022-03-13 17:12:48,011] {__init__.py:136} ERROR -                                                                                                                    ^-- Invalid syntax
[2022-03-13 17:12:48,011] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:48,011] {__init__.py:135} ERROR - def MakeFromYUVATexturesCopyWithExternalBackend(context: skia.GrRecordingContext, yuvColorSpace: skia.YUVColorSpace, yuvaTextures: std::__1::vector<GrBackendTexture, std::__1::allocator<GrBackendTexture> >, yuvaIndices: std::__1::vector<SkYUVAIndex, std::__1::allocator<SkYUVAIndex> >, imageSize: skia.ISize, imageOrigin: skia.GrSurfaceOrigin, backendTexture: skia.GrBackendTexture, imageColorSpace: skia.ColorSpace = None) -> skia.Image: ...
[2022-03-13 17:12:48,011] {__init__.py:136} ERROR -                                                                                                                                       ^-- Invalid syntax
[2022-03-13 17:12:48,177] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:48,177] {__init__.py:135} ERROR - def Offset(points: std::__1::vector<SkPoint, std::__1::allocator<SkPoint> >, offset: skia.Point) -> std::__1::vector<SkPoint, std::__1::allocator<SkPoint> >: ...
[2022-03-13 17:12:48,177] {__init__.py:136} ERROR -                       ^-- Invalid syntax
[2022-03-13 17:12:48,177] {__init__.py:131} ERROR - Generated stubs signature is degraded to `(*args, **kwargs) -> typing.Any` for
[2022-03-13 17:12:48,177] {__init__.py:135} ERROR - def Offset(points: std::__1::vector<SkPoint, std::__1::allocator<SkPoint> >, dx: float, dy: float) -> std::__1::vector<SkPoint, std::__1::allocator<SkPoint> >: ...
[2022-03-13 17:12:48,177] {__init__.py:136} ERROR -                       ^-- Invalid syntax
[2022-03-13 17:12:48,321] {__init__.py:957} INFO - Useful link: Avoiding C++ types in docstrings:
[2022-03-13 17:12:48,321] {__init__.py:958} INFO -       https://pybind11.readthedocs.io/en/latest/advanced/misc.html#avoiding-cpp-types-in-docstrings

stubgen looks more promising (sizmailov/pybind11-stubgen#31). I was able to generate type stubs that work more or less. I ran the following in my project root directory:

pip install mypy skia
stubgen -p skia -o . # Generates stubs in `./skia`
touch skia/py.typed # https://peps.python.org/pep-0561/
sed -i '' 's/Sk//g' skia/__init__.pyi # Removes the Sk prefix

The generated skia directory contains type stubs for skia. It could be put anywhere in sys.path like your project root or site-packages.

Now I got type stubs that are somewhat useful for autocompletion and basic type check, but they still have many issues:

  • a field called def: I just commented it out...
  • Static methods are generated as instance methods: I manually added @staticmethod and removed the first argument of the ones that I use, but this is not a scalable solution.
  • Many many Any

I hope this helps for someone who's willing to investigate it further.

from skia-python.

kyamagu avatar kyamagu commented on July 19, 2024

Yes, this would be great

from skia-python.

maliknajjar avatar maliknajjar commented on July 19, 2024

Intellisense/autocomplete doesnt work for me as well when working with the skia-python package on vscode .. please fix this probleme

from skia-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.