Skip to content

Commit

Permalink
python: isort everything via ruff
Browse files Browse the repository at this point in the history
This commit is based on doing two things:

  - selecting "i" rules for ruff in our `pyproject.toml`

  - running `ruff check --fix .`
  • Loading branch information
allisonkarlitskaya committed May 17, 2023
1 parent 9373c1c commit 355c0aa
Show file tree
Hide file tree
Showing 29 changed files with 37 additions and 64 deletions.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ disable = [
]

[tool.ruff]
select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
]
exclude = [
".git/",
"modules/",
Expand Down
1 change: 0 additions & 1 deletion src/build_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import subprocess
import tarfile
import zipfile

from typing import Dict, Iterable, Optional

from cockpit import __version__
Expand Down
4 changes: 1 addition & 3 deletions src/cockpit/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@
import ctypes
import json
import logging
import pwd
import os
import pwd
import shlex
import signal
import socket
import subprocess

from typing import Dict, Iterable, List, Tuple, Type

from cockpit._vendor.systemd_ctypes import bus, run_async

from . import polyfills

from .channel import ChannelRoutingRule
from .channels import CHANNEL_TYPES
from .config import Config, Environment
Expand Down
2 changes: 0 additions & 2 deletions src/cockpit/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

import asyncio
import logging

from typing import ClassVar, Dict, Generator, List, Optional, Sequence, Set, Tuple, Type

from .router import Endpoint, Router, RoutingRule


logger = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions src/cockpit/channels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
from .http import HttpChannel
from .metrics import InternalMetricsChannel
from .packages import PackagesChannel
from .stream import SubprocessStreamChannel, SocketStreamChannel
from .stream import SocketStreamChannel, SubprocessStreamChannel
from .trivial import EchoChannel, NullChannel


CHANNEL_TYPES = [
DBusChannel,
EchoChannel,
Expand Down
2 changes: 0 additions & 2 deletions src/cockpit/channels/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import logging
import os
import random

from typing import Dict

from .._vendor.systemd_ctypes import PathWatch
from .._vendor.systemd_ctypes.inotify import Event as InotifyEvent

from ..channel import Channel, ChannelError, GeneratorChannel

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/cockpit/channels/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import asyncio
import http.client
import logging
import ssl
import socket
import ssl
import threading

from ..channel import Channel
Expand Down
6 changes: 3 additions & 3 deletions src/cockpit/channels/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import asyncio
import json
import logging
import sys
import time
import logging
from typing import Dict, List, NamedTuple, Optional, Set, Tuple, Union
from collections import defaultdict
from typing import Dict, List, NamedTuple, Optional, Set, Tuple, Union

from ..channel import AsyncChannel, ChannelError
from ..samples import SAMPLERS, Sampler, Samples, SampleDescription
from ..samples import SAMPLERS, SampleDescription, Sampler, Samples

logger = logging.getLogger(__name__)

Expand Down
6 changes: 2 additions & 4 deletions src/cockpit/channels/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import logging
import os
import subprocess

from typing import Dict


from ..channel import ProtocolChannel, ChannelError
from ..transports import SubprocessTransport, SubprocessProtocol
from ..channel import ChannelError, ProtocolChannel
from ..transports import SubprocessProtocol, SubprocessTransport

logger = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion src/cockpit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import configparser
import logging
import os

from pathlib import Path

from ._vendor.systemd_ctypes import bus
Expand Down
4 changes: 1 addition & 3 deletions src/cockpit/internal_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
import logging
import os
import pwd

from typing import Dict, Optional

from ._vendor.systemd_ctypes import bus, pathwatch, inotify, Variant

from . import config
from ._vendor.systemd_ctypes import Variant, bus, inotify, pathwatch

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/cockpit/misc/bootloader.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# COCKPIT BOOTLOADER

from hashlib import sha256
import os
import sys
from hashlib import sha256


class Bootloader:
Expand Down
1 change: 0 additions & 1 deletion src/cockpit/misc/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import shlex
import sys
import time

from typing import BinaryIO, Iterable, Optional


Expand Down
4 changes: 1 addition & 3 deletions src/cockpit/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
import os
import re
import shutil

from pathlib import Path
from typing import ClassVar, Dict, List, Optional, Pattern, Tuple

from ._vendor.systemd_ctypes import bus

from . import config
from ._vendor.systemd_ctypes import bus

VERSION = '300'
logger = logging.getLogger(__name__)
Expand Down
5 changes: 2 additions & 3 deletions src/cockpit/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
import asyncio
import logging
import os

from typing import Callable, Dict, List, Optional, Sequence

from .protocol import CockpitProblem, CockpitProtocol, CockpitProtocolError
from .router import Endpoint, Router, RoutingRule
from .protocol import CockpitProtocol, CockpitProblem, CockpitProtocolError
from .transports import SubprocessTransport, SubprocessProtocol
from .transports import SubprocessProtocol, SubprocessTransport

logger = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions src/cockpit/polyfills.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def install():
# introduced in 3.9
if not hasattr(socket, 'recv_fds'):
import array

import _socket

def recv_fds(sock, bufsize, maxfds, flags=0):
Expand Down
2 changes: 0 additions & 2 deletions src/cockpit/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import json
import logging
import uuid

from typing import ClassVar, Dict, Optional

from ._vendor import systemd_ctypes


logger = logging.getLogger(__name__)


Expand Down
5 changes: 2 additions & 3 deletions src/cockpit/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import logging
import re
import socket

from typing import Dict, Optional, List, Tuple
from typing import Dict, List, Optional, Tuple

from ._vendor import ferny
from .router import RoutingRule, Router
from .peer import Peer, PeerError
from .router import Router, RoutingRule

logger = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions src/cockpit/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

import collections
import logging

from typing import Dict, List, Optional

from .protocol import CockpitProtocolServer, CockpitProtocolError
from .protocol import CockpitProtocolError, CockpitProtocolServer

logger = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions src/cockpit/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

import os
import re
from ._vendor.systemd_ctypes import Handle

from typing import Any, DefaultDict, Iterable, List, NamedTuple, Optional, Tuple

from ._vendor.systemd_ctypes import Handle

USER_HZ = os.sysconf(os.sysconf_names['SC_CLK_TCK'])
MS_PER_JIFFY = 1000 / (USER_HZ if (USER_HZ > 0) else 100)
Expand Down
7 changes: 3 additions & 4 deletions src/cockpit/superuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import asyncio
import logging
import getpass
import logging
import os

from typing import Dict, List, Optional, Sequence, Union

from ._vendor.systemd_ctypes import bus
from ._vendor import ferny
from ._vendor.systemd_ctypes import bus
from .peer import ConfiguredPeer, Peer, PeerError
from .router import Router, RoutingError, RoutingRule
from .peer import Peer, PeerError, ConfiguredPeer

logger = logging.getLogger(__name__)

Expand Down
2 changes: 0 additions & 2 deletions src/cockpit/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
import struct
import subprocess
import termios

from typing import Any, ClassVar, Deque, Dict, List, Optional, Sequence, Tuple


libc6 = ctypes.cdll.LoadLibrary('libc.so.6')


Expand Down
2 changes: 1 addition & 1 deletion test/pytest/mockpeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import os
import sys

from cockpit.transports import StdioTransport
from cockpit.protocol import CockpitProtocolServer
from cockpit.transports import StdioTransport


class MockPeer(CockpitProtocolServer):
Expand Down
1 change: 0 additions & 1 deletion test/pytest/mocktransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import os
import subprocess

from typing import Any, Dict, Iterable, Optional, Tuple

from cockpit.router import Router
Expand Down
12 changes: 5 additions & 7 deletions test/pytest/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
import asyncio
import json
import os
import pytest
import unittest
import unittest.mock
import sys
import tempfile

import unittest
import unittest.mock
from pathlib import Path
from typing import Dict

from cockpit._vendor.systemd_ctypes import bus, EventLoopPolicy
import pytest
from cockpit._vendor.systemd_ctypes import EventLoopPolicy, bus
from cockpit.bridge import Bridge
from cockpit.channels import CHANNEL_TYPES

from mocktransport import MockTransport, MOCK_HOSTNAME, settle_down
from mocktransport import MOCK_HOSTNAME, MockTransport, settle_down

asyncio.set_event_loop_policy(EventLoopPolicy())

Expand Down
5 changes: 2 additions & 3 deletions test/pytest/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

import json

import pytest

import cockpit.config
from cockpit.packages import parse_accept_language, Packages
import pytest
from cockpit.packages import Packages, parse_accept_language


@pytest.mark.parametrize("test_input,expected", [
Expand Down
6 changes: 2 additions & 4 deletions test/pytest/test_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
import os
import sys

import mockpeer
import pytest

from cockpit.peer import ConfiguredPeer, PeerRoutingRule
from cockpit.protocol import CockpitProtocolError
from cockpit.router import Router
from cockpit.peer import ConfiguredPeer, PeerRoutingRule

import mockpeer
from mocktransport import MockTransport, assert_no_subprocesses, settle_down

PEER_CONFIG = {
Expand Down
3 changes: 1 addition & 2 deletions test/pytest/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
import numbers
import os

import pytest

import cockpit.samples
import pytest


@pytest.fixture
Expand Down
1 change: 0 additions & 1 deletion test/pytest/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import subprocess
import unittest
import unittest.mock

from typing import Any, List, Optional, Tuple

import cockpit.transports
Expand Down

0 comments on commit 355c0aa

Please sign in to comment.