Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate type stub files for python API #41264

Closed
s-knibbs opened this issue Jan 29, 2021 · 8 comments
Closed

Generate type stub files for python API #41264

s-knibbs opened this issue Jan 29, 2021 · 8 comments
Labels
Feature Request Feedback Waiting on the submitter for answers PyQGIS Related to the PyQGIS API

Comments

@s-knibbs
Copy link
Contributor

Feature description.
It'd be useful to be able to use mypy to type check QGIS plugins. The QGIS api bindings don't currently include stub files (.pyi files) so the type checking is rather limited.

Additional context
It seems like sip is able to generate stub files as part of the build. This is used to generate stubs for PyQt5.

@Gustry Gustry added the PyQGIS Related to the PyQGIS API label Jan 30, 2021
@nyalldawson
Copy link
Collaborator

This is already done -- there's .pyi files created and included with all the PyQGIS libraries:

image

@nyalldawson
Copy link
Collaborator

So if anything this is a packaging issue, but we'd need to know what platform you're using and more details about how you installed qgis and are using the bindings.

@nyalldawson nyalldawson added the Feedback Waiting on the submitter for answers label Jan 31, 2021
@s-knibbs
Copy link
Contributor Author

s-knibbs commented Feb 1, 2021

I looked into this further. For some reason, the stub files don't get copied across to the installation directory in the qgis container image. I'm using qgis/qgis:release-3_16. I was able to get mypy to find them with the following:

stubgen -p qgis -o stubs
cp /QGIS/build/output/python/qgis/*.pyi stubs/qgis

Unfortunately, I found that there are some manual fixes required to get mypy to work because of the following error:

MYPYPATH=/stubs mypy some_plugin_file.py
/stubs/qgis/_core.pyi:112: error: cannot assign to None
Found 1 error in 1 file (errors prevented further checking)

I think for now, I'll just create a stubs package similar to PyQt5-stubs with these fixes applied.

@github-actions
Copy link

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale".
If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue.
In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue.
If there is no further activity on this issue, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 16, 2021
@LKajan
Copy link

LKajan commented May 6, 2021

At least the stub files are not packaged in when installing using the new osgeo4w installer.

Apparently no other than *.pyd files are copied by cmake when building on Windows if I can interpret https://github.com/qgis/QGIS/blob/master/cmake/SIPMacros.cmake#L170 correctly. Unfortunately I don't yet have enough competence on cmake to make a PR.

@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label May 6, 2021
@SrNetoChan
Copy link
Member

This would be helpful also for pylance in visual code studio. That way people could use installed QGIS Python folder for auto completion.

They are created during the build, but they don't seem to be packages or copied during installation.

@jef-n is this something we could include in installation? The files are not too heavy.

@jef-n jef-n closed this as completed in f8e2adb Jun 9, 2021
@SrNetoChan
Copy link
Member

@jef-n Thanks! Much appreciated.

manisandro pushed a commit to kadas-albireo/QGIS that referenced this issue Jun 14, 2021
@SrNetoChan
Copy link
Member

Hi @jef-n where can I find these .pyi files? I can't seem to find them either in Windows or Linux installations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Feedback Waiting on the submitter for answers PyQGIS Related to the PyQGIS API
Projects
None yet
Development

No branches or pull requests

5 participants