gecos-lab / PZero

GNU Affero General Public License v3.0
22 stars 2 forks source link

Code style & formatting #55

Closed andrea-bistacchi closed 2 weeks ago

andrea-bistacchi commented 1 year ago

Hi, as I progress in my review of existing code I find a mix of different styles, indentation, line termination, commenting using # vs """, etc.

I guess we better standardize and automate this. There are PyCharm plug-ins based on black, isort or prettier to do this.

Please propose a standard and we will set our IDE and stick to it. This also reduces cosmetic commits.

Regarding commenting, I would propose to use dockstrings (""" ... """) to explain the purpose of functions and classes (one dockstring for each function/class) and standard comments for all other comments.

Thanks!

mcbaguetti commented 1 year ago

I think black it's a good choice, Prettier is also nice but better for js/ts files than for python ones. Here's a quickstart https://black.readthedocs.io/en/stable/getting_started.html

andrea-bistacchi commented 1 year ago

Very good! Please give us some instructions in order to have a standard and be able to apply it consistently. This will also reduce commits related to cosmetic changes in the code.

mcbaguetti commented 1 year ago

Actually, I have installed black with conda install black and then you can run black <directories or file> to reformat all the code with the black style. I can check more advanced reformatting options

andrea-bistacchi commented 1 year ago

OK, if everybody is fine with this, we can add blackto the environment and conform to this style.

BTW, I guess this could be set as automatic in PyCharms,

gbene commented 1 year ago

Yes! I really like black.

andrea-bistacchi commented 1 year ago

ok, let's add it to the pzer onvironments and use it!

mcbaguetti commented 1 year ago

added it!

andrea-bistacchi commented 1 year ago

Maybe we can use this PyCharm plugin BlackConnect?

mcbaguetti commented 1 year ago

yes, I think it's a good option for PyCharm if you want to use black automatically on your computer

andrea-bistacchi commented 1 year ago

I installed black in the conda environment

conda activate pzero
conda install blackd

Then I installed the PyCharm Plugin BlackConnect with File > Plugins > search "black connect" > Install.

Then I edited BlackConnect settings from File > Settings > Tools > BlackConnect as follows:

image

Now I find BlackConnect under Tools:

image

But it does not appear to modify files.

Suggestions?

mcbaguetti commented 1 year ago

are you inside the main branch? Because I've already pushed the reformatting process with black inside the main branch. I did the same steps as you and it worked.

gbene commented 1 year ago

For me it works also on the AB_GUI_tests branch. I noticed that it took a bit the first time that I tested it. Maybe I suggest to remove the trigger on save since it could be a bit annoying while working on a given file (pycharm saves constantly so you'll have changing code structure while typing).

andrea-bistacchi commented 5 months ago

We must make this a standard in instructions for developers.

andrea-bistacchi commented 2 weeks ago

This is the standard now, as explained in https://github.com/gecos-lab/PZero/wiki/PZero-code-style-&-formatting.