Forum

Author Topic: Please add Stubs for the Python standalone module  (Read 8969 times)

SFL_Beda

  • Newbie
  • *
  • Posts: 24
    • View Profile
Please add Stubs for the Python standalone module
« on: November 24, 2023, 04:52:03 PM »
Without stubs, there are is no autocomplete, type hinting etc. in Editors that can't scan the .so files themselves (like VSCode with pylance for example.)

I understand that it kind of works in PyCharm (also not very well to be honest) but not everybody is free to switch editor as they want to.

By adding stubs you could vastly improve the quality of life for developers using your python module.

PolarNick

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Please add Stubs for the Python standalone module
« Reply #1 on: November 24, 2023, 09:22:00 PM »
About auto-completion in PyCharm - it was not working for Metashape 2.0 (see screenshot pycharm_typehinting_MS20.png), but it seems to work properly for Metashape 2.1 (see screenshot pycharm_typehinting_MS21.png).

About VSCode - as a workaround - maybe it should work to generate stubs in PyCharm and then use generated binary skeletons in VSCode? (see screenshot pycharm_binary_skeleton_MS21.png)

SFL_Beda

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Please add Stubs for the Python standalone module
« Reply #2 on: November 27, 2023, 03:30:53 PM »
Thank you for the answer

I tried your suggestion in 2.03 and while it now shows me the Metashape datatypes like Metashape.Chunk I get the same issue as you on all variables that have been returned by a function (because the return datatype defaults to "any").

I guess I have to wait for stable release of 2.1

Seeing as those autogenerated stubs seem to work at least partially, maybe you could think about including them in the module in the future?
Copying them back and forth between Editors surely is not the best solution.

PolarNick

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Please add Stubs for the Python standalone module
« Reply #3 on: November 27, 2023, 03:51:09 PM »
> Seeing as those autogenerated stubs seem to work at least partially, maybe you could think about including them in the module in the future?

I don't know how to generate these stubs automatically (without PyCharm GUI) - so it is a big question how to integrate their generation in CI build system. It is possible to implement a custom stubs generator, but this requires a lot of time/efforts and currently is not planned.

SFL_Beda

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Please add Stubs for the Python standalone module
« Reply #4 on: November 27, 2023, 04:20:30 PM »
Maybe take a look at mypy stubgen for an open source tool that should have similar functionality and will be easier to integrate into a pipeline.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15282
    • View Profile
Re: Please add Stubs for the Python standalone module
« Reply #5 on: December 14, 2023, 01:23:43 PM »
Hello SFL_Beda,

Since pre-release version 2.1.0 build 17453 Metashape .whl includes .pyi stub:
https://www.agisoft.com/forum/index.php?topic=15894.0
Best regards,
Alexey Pasumansky,
Agisoft LLC

SFL_Beda

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Please add Stubs for the Python standalone module
« Reply #6 on: March 11, 2024, 05:03:36 PM »
Hi Alexey

I'm sorry for replying so late, I only just got the time to update to 2.1 .
The stubs work nicely and developing is much nicer this way.

Thank you very much for implementing this so quickly.

best regards

Beda