godot-python icon indicating copy to clipboard operation
godot-python copied to clipboard

Better editor integration - code formatting

Open touilleMan opened this issue 5 years ago • 1 comments

To integrate Python even further into the Godot's code editor, there is multiple callbacks to implements (see in pythonscript/_godot_editor.pxi)

1 - Code formatting with Black

https://github.com/touilleMan/godot-python/blob/72df9d1b38120aeec3c702004e14dcb82e95bde5/pythonscript/_godot_editor.pxi#L118-L142

The commented code is from the old version of Godot-Python which was using CFFI. But it's a good example on what should be done ^^

On top of that, I really think we should be using Black for this task. Whitout trying to allow any user choice on this (because choice make code more complex, and because Black is definitely the best code formatter anyway !)

The tricky part here is how do we provide Black ? I can see two possibilities:

Provide is as part of Godot-Python

This could be done by adding a pip install as part of the build phase:

see https://github.com/touilleMan/godot-python/blob/72df9d1b38120aeec3c702004e14dcb82e95bde5/platforms/x11-64/SCsub#L52-L53

However this means we make the build bigger:

$ python3 -m venv venv
[...]
$ cd venv && . ./bin/activate
(venv) $ du -sh .
6,7M	.
(venv) $ pip install black
[...]
(venv) $ du -sh .
14M	.

This is even worst given the asset store oblige to download all the supported platforms when installing a package, so given we support linux 32/64, windows 32/64 and MacOS, we end up with 8 * 5 == 40 more Mo...

Oblige the user to install Black himself

We could print a warning message (or open a popup in the Godot editor maybe) if the user try to use the formatting without installing black.

The error message would explain how to install it (using the pip command provided by the build).

This is obviously less user-friendly, however I think it's important for users to know how to use the build's pip command given a big reason to use Python is for it incredible ecosystem !

2 - Code linting

More or less the same kind of stuff to do, but with pylint (though unless black, I don't have strong opinion on the tool to use here)

3 - Autocompletion / code search

Jedi should do the job here (but like with pylint, no strong opinion on that...)

I guess we should provide a .pyi file (see https://www.python.org/dev/peps/pep-0484/#stub-files) of bindings and builtins (this should be easy to generate with our template system ^^) to allow autocomplete on them.

I'm not sure how to retreive the Godot class's documentation though:

rip it from the Godot's source code

see https://github.com/godotengine/godot/tree/master/doc/classes

I don't like it because xml is cumbersome to work with, and it would mean we need Godot source code to build Godot-Python (with is currently not the case thanks to GDNative in it own repo

rip it from Godot binary at build time

The dependency is better given we already have a rule to download the godot binary (though it is currently only use to run example/tests, but it's no big deal if it would be used for the build)

However I didn't see any way to get those information from the Godot API...

In the end, maybe the best solution would be to make a PR to Godot to add the documentation to the api.json format ;-)

4 - Stack debugging

I guess this could be implemented by using the `traceback standard library

touilleMan avatar Feb 03 '20 06:02 touilleMan

Hi, I am an entry level python programmer, currently completing my final project for graduation and I wanted to contribute to this as part of an assignment! Could you please assign it to me or let me know if it's available?

Mikers95 avatar May 30 '25 04:05 Mikers95