IIT-EnergySystemModels / openTEPES

Open Generation, Storage, and Transmission Operation and Expansion Planning Model with RES and ESS (openTEPES)
https://opentepes.readthedocs.io/en/latest/index.html
GNU Affero General Public License v3.0
39 stars 23 forks source link

Autoformatting python source code #58

Open kdheepak opened 5 months ago

kdheepak commented 5 months ago

Hi! Firstly, thanks for developing and maintaining this project!

I wanted to check if you'd be interested in using an autoformatter for your source code?

At the moment, there's a number of lines that exceed conventional and unconventional character limits in Python projects (80 characters, 120 characters or even 150 characters per line) e.g.:

https://github.com/IIT-EnergySystemModels/openTEPES/blob/9dd774b3bf6f3b0f9da2f3e7c7a7efe209fb5522/openTEPES/openTEPES_InputData.py#L566-L568

This requires scrolling left to right on GitHub and in other text editors (where soft wrapping lines are not enabled) and makes it harder (in my humble opinion) to read some parts of the code.

There's also a number of lines where manual formatting of the spaces is used for aligning the code:

https://github.com/IIT-EnergySystemModels/openTEPES/blob/9dd774b3bf6f3b0f9da2f3e7c7a7efe209fb5522/openTEPES/openTEPES_InputData.py#L407-L429

I really like how much consistency you've enforced in aligning the whitespace like this, it makes it easy to visually parse the structure of various sub-expressions in the code.

However, manually aligning the whitespace can be time-consuming. Changing a parameter name, or adding or removing an existing one will require a modeller to manually align these parameters again in order to continue maintaining consistency. This will increase the diff every time a modeller makes a contribution.

Furthermore, if a modeller were to make changes that they wish to contribute back to this project, the manual alignment of code like this can increase the chances of conflicts that would need to be resolved.

Would you consider using an autoformatter (black, ruff, yapf, autopep etc are commonly used ones) such that it autoformats the code when you save or when you commit code to a project? A number of these formatters have various options you can configure too, that you can tweak to your liking.

In my humble opinion, it would make it more easier to anyone to upstream changes or contributions.

But no worries if you choose not to adopt autoformatting! I know that the current style can make it very easy to read the code and there are certainly clear benefits to the current approach that you'd lose if you were to choose to adopt an autoformatter.

If you think this is not a direction you'd like to take the project, feel free to close the issue :)

arght commented 5 months ago

Thanks for your comments. We will check the potential use of autoformatter for improving the code aspect while facilitating the contributions.