New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#9634] Add an isort configuration #1132
Conversation
an example from
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ isort, it's great.
I ran it recursively and skimmed the (enormous) diff. Most changes seemed reasonable enough.
I will note that isort
can't be applied blindly:
- I saw some test failures when I did so.
- The resulting whitespace doesn't necessarily pass twistedchecker.
We should still merge this, though. It gets all isort
-using developers on the same page. isort
is useful even if we don't lint on it.
setup.cfg
Outdated
not_skip = __init__.py | ||
sections = FUTURE,STDLIB,ZOPE,OPENSSL,THIRDPARTY,FIRSTPARTY,TESTS,LOCALFOLDER | ||
default_section = THIRDPARTY | ||
known_first_party = twisted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should twisted be in localfolder? Existing files are not consistent about this, e.g. when I run isort with this config on trunk this file's imports are broken apart:
--- a/src/twisted/application/runner/test/test_exit.py
+++ b/src/twisted/application/runner/test/test_exit.py
@@ -5,12 +5,11 @@
Tests for L{twisted.application.runner._exit}.
"""
-from twisted.python.compat import NativeStringIO
-from ...runner import _exit
-from .._exit import exit, ExitStatus
-
import twisted.trial.unittest
+from twisted.python.compat import NativeStringIO
+from ...runner import _exit
+from .._exit import ExitStatus, exit
class ExitTests(twisted.trial.unittest.TestCase):
vs. this file, where they were always separate:
--- a/src/twisted/application/runner/test/test_pidfile.py
+++ b/src/twisted/application/runner/test/test_pidfile.py
@@ -5,27 +5,30 @@
Tests for L{twisted.application.runner._pidfile}.
"""
-from functools import wraps
import errno
-from os import getpid, name as SYSTEM_NAME
+from functools import wraps
from io import BytesIO
+from os import getpid, name as SYSTEM_NAME
from zope.interface import implementer
from zope.interface.verify import verifyObject
+import twisted.trial.unittest
from twisted.python.filepath import IFilePath
from twisted.python.runtime import platform
+from twisted.trial.unittest import SkipTest
from ...runner import _pidfile
from .._pidfile import (
- IPIDFile, PIDFile, NonePIDFile,
- AlreadyRunningError, InvalidPIDFileError, StalePIDFileError,
+ AlreadyRunningError,
+ InvalidPIDFileError,
+ IPIDFile,
+ NonePIDFile,
NoPIDFound,
+ PIDFile,
+ StalePIDFileError,
)
-import twisted.trial.unittest
-from twisted.trial.unittest import SkipTest
-
def ifPlatformSupported(f):
"""
Either seems okay to me. We really shouldn't mix these styles in the same file, after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will note that isort can't be applied blindly:
I saw some test failures when I did so.
This is really concerning to me and suggests that there is something incorrect about the configuration. Before landing this, could we perhaps address the test failures with some exclusions so it can be applied blindly?
setup.cfg
Outdated
@@ -0,0 +1,11 @@ | |||
[isort] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest putting this config into pyproject.toml
instead…
I don't think that it suggests anything about the configuration. It suggests that there are import cycles or ordering dependencies within Twisted. This isn't new information — we've seen a trickle of such issues, like #8267 and #7096. I do not think that we should expand the scope of this ticket to include fixing these issues. The ticket says "add an isort config" and this PR does that. It is a useful improvement that will improve the developer experience. It has merit on those terms and should be merged. |
This PR produces working output when applied across the board, with the following caveats:
You can see the test runs and the diff at #1139. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up again!
it requires ignoring a few files, and moving
t.p.compat
to the top because it sometimes has side-effects by patchingsocket
(lol)
Perhaps we should add an import of twisted.python.compat
to src/twisted/__init__.py
so that these patches are consistently applied regardless of which module user code imports? (Not that I think that need be in this PR.)
tox.ini
Outdated
{withcov}: coverage | ||
|
||
{coverage-prepare,codecov-publish}: coverage | ||
; Coverage 5.0 does not work with codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for investigating and fixing this!
https://twistedmatrix.com/trac/ticket/9634#ticket