enthought / envisage

Envisage is a Python-based framework for building applications whose functionalities can be extended by adding "plug-ins".
http://docs.enthought.com/envisage/
Other
82 stars 26 forks source link

Implement black and isort-based style checks #549

Closed mdickinson closed 1 year ago

mdickinson commented 1 year ago

This PR adds black and isort style formatting and checking, and requires future code changes to comply with black and isort styles.

Note: I'm installing the style-related packages from PyPI in etstool.py, so that etstool.py and the new workflow are installing the same package versions. I'm also fixing black to version 23.x so that we don't suddenly get style failures for the first Black release in 2024 (or later years) - see Black's stability policy here: https://black.readthedocs.io/en/stable/the_black_code_style/index.html#stability-policy

To do:

Closes #527

mdickinson commented 1 year ago

This is ready for review.

For reviewers: there are two commits. The first commit contains the manual changes; the second is entirely auto-generated using python etstool.py style fix.

mdickinson commented 1 year ago

For the record, I don't have strong feelings on the line length change here - if the consensus is that people would prefer not to change this, I'll revert and regenerate the changes.

mdickinson commented 1 year ago

Can isort do sorting with lowercase after captials?

It can - there's an order_by_type option. I tend to turn it off because I find the results are too surprising.

mdickinson commented 1 year ago

This will interfere with other open PRs, so I plan to merge the other PRs first (not including the changelog) PR and then redo the automated style fixes if necessary.

mdickinson commented 1 year ago

I did an evil force push to bring this up to date with main, since there didn't seem to be any sane way of merging; I've cherry-picked the relevant two commits (the non-autogenerated ones) and then regenerated the automated fixes on top using python etstool.py fix.

However, I ran into a snag: the current version of black will reformat some existing line-length-compliant docstrings in such a way that they introduce new line length violations, so I had to make manual fix-ups to those docstrings to get them into a state where (a) they passed the line length check, and (b) black won't reformat them to something that no longer passes the line length check.

Upstream PR that introduced this issue: https://github.com/psf/black/pull/3430 See particularly this comment: https://github.com/psf/black/pull/3430#issuecomment-1464371599