Skip to content

Run isort and pycln over entire repo - upgrade pre-commit config#2002

Merged
outofculture merged 6 commits intopyqtgraph:masterfrom
j9ac9k:test-noqa-isort
Nov 13, 2021
Merged

Run isort and pycln over entire repo - upgrade pre-commit config#2002
outofculture merged 6 commits intopyqtgraph:masterfrom
j9ac9k:test-noqa-isort

Conversation

@j9ac9k
Copy link
Copy Markdown
Member

@j9ac9k j9ac9k commented Sep 29, 2021

This PR makes some changes such that isort and pycln can be run over the entire repository safely, and also incorporates the entire repository as well.

Some things to note, import order is important with respect to pyopengl, that needs to be imported first, so on any file that uses that as an import, I have the following at the very top. isort knows not to reshuffle the order if I have the # noqa comment and it is before other imports.

from OpenGL.GL import *  # noqa

@j9ac9k
Copy link
Copy Markdown
Member Author

j9ac9k commented Sep 29, 2021

Static code-checker isn't necessarily happy but it's happier

image

@j9ac9k
Copy link
Copy Markdown
Member Author

j9ac9k commented Sep 29, 2021

I thought CodeQL would ignore the unused import if I had a # noqa next to it; but that does not appear to be the case (looking at you initExample unused import warning); doing another look at docs, it might need to be #noqa (without the space) ...trying that now.

@j9ac9k
Copy link
Copy Markdown
Member Author

j9ac9k commented Oct 1, 2021

On further reflection of this, I think removing whitespaces as part of this PR will likely cause merge conflicts w/ the remaining PRs so we probably want not want to include that as part of this PR.

@ksunden
Copy link
Copy Markdown
Contributor

ksunden commented Oct 1, 2021

We could consider taking the examples out of the CodeQL coverage (at least for now) When I've gone on my "rampage through codeQL identified problems" I've largely ignored the examples anyway, personally.

Thats just a matter of adding an "ignore" path to the action.

You can also ignore CodeQL problems via the web ui, that should cause them to not come back unless the lines are touched, I think.

@j9ac9k
Copy link
Copy Markdown
Member Author

j9ac9k commented Oct 1, 2021

We could consider taking the examples out of the CodeQL coverage (at least for now) When I've gone on my "rampage through codeQL identified problems" I've largely ignored the examples anyway, personally.

Thats just a matter of adding an "ignore" path to the action.

You can also ignore CodeQL problems via the web ui, that should cause them to not come back unless the lines are touched, I think.

...that's actually a really good idea.

@j9ac9k j9ac9k force-pushed the test-noqa-isort branch 2 times, most recently from fe9121e to a71b685 Compare October 8, 2021 05:16
@j9ac9k
Copy link
Copy Markdown
Member Author

j9ac9k commented Nov 1, 2021

@outofculture I updated this PR so that isort/pycln and such run w/o issue, removed the encoding bit, updated pre-commit (and even added pyproject.toml so we have some consistent settings). I rebased master on this branch recently as well.

The only thing I haven't done is change the Qt namespace bits, which of course take us back to how do we want to deal with the modules that changed their parent namespaces. If memory serves, @pijyoi made an argument a while back about minimizing the modifications we made to the parent modules (as they could impact user code outside of pyqtgraph).

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Nov 1, 2021

It's okay to do things like QtWidgets.QAction = QtGui.QAction because we have a fake QtWidgets and QtGui.

Not okay would be QMouseEvent.position = QMouseEvent.pos as that would be visible to other libraries

@j9ac9k
Copy link
Copy Markdown
Member Author

j9ac9k commented Nov 1, 2021

It's okay to do things like QtWidgets.QAction = QtGui.QAction because we have a fake QtWidgets and QtGui.

Not okay would be QMouseEvent.position = QMouseEvent.pos as that would be visible to other libraries

Thanks for the clarification 👍🏻

There are places throughout the library that the order of imports for
PyOpenGL and other OpenGL related modules is important. In all cases,
PyOpenGL should be imported first.  This change moves it to the top of
the file, and adds the # noqa comment so that isort does not rearrange
the ordering causing unintentional breakages.
This commit has the fixes for a variety of pre-commit hooks

1. end-of-file-fixer
2. fix-encoding-pragma --remove
3. mixed-line-ending --fix=lf

In addition, the following hooks were added

    -   id: check-merge-conflict
    -   id: check-toml
    -   id: debug-statements
    -   id: check-ast
Instead of importing from __init__.py specifying the file to import
from results in imports remaining robust after isort shuffles the order
of the imports
Change the order of results, with the isort config being in the
pyproject.toml file that is also added.

Furthermore, a pre-commit hook for isort has been added
@j9ac9k j9ac9k changed the title Test Expanding Scope of #1915 - For the love of god, do not merge Run isort and pycln over entire repo - upgrade pre-commit config Nov 13, 2021
@j9ac9k j9ac9k marked this pull request as ready for review November 13, 2021 05:46
@j9ac9k
Copy link
Copy Markdown
Member Author

j9ac9k commented Nov 13, 2021

Alright folks, merging this is going to cause some merge conflicts, sorry about that...shortly after merging this we'll merge #1915 ...which is also likely to cause some merge conflicts.

@outofculture outofculture merged commit 6124c95 into pyqtgraph:master Nov 13, 2021
@j9ac9k j9ac9k deleted the test-noqa-isort branch November 13, 2021 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants