Skip to content

Commit

Permalink
Use ruff instead of flake8
Browse files Browse the repository at this point in the history
And remove py2-style type annotations, which ruff doesn't recognise
  • Loading branch information
David Robertson committed Apr 21, 2023
1 parent 2244322 commit dbaaf14
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 18 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencies = [
dev = [
"black==22.3.0",
"coverage~=5.5",
"flake8==3.9.0",
"ruff==0.0.262",
"isort~=5.0",
"mypy==0.812",
"mypy-zope==0.3.0",
Expand All @@ -90,6 +90,8 @@ dev = [
"typing-extensions>=3.7.4",
]

[tool.ruff]
line-length = 88

[project.urls]
homepage = "https://github.com/matrix-org/sygnal"
Expand Down
4 changes: 2 additions & 2 deletions scripts-dev/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Runs linting scripts over the local Sygnal checkout
# isort - sorts import statements
# black - opinionated code formatter
# flake8 - lints and finds mistakes
# ruff - lints and finds mistakes
# mypy - type checker

set -e
Expand Down Expand Up @@ -97,5 +97,5 @@ set -x

isort "${files[@]}"
python3 -m black "${files[@]}"
flake8 "${files[@]}"
ruff "${files[@]}"
mypy "${files[@]}"
10 changes: 0 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
[flake8]
# line length defaulted to by black
max-line-length = 88

# see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# for error codes. The ones we ignore are:
# W503: line break before binary operator
# W504: line break after binary operator
# E203: whitespace before ':' (which is contrary to pep8?)
# (this is a subset of those ignored in Synapse)
ignore=W503,W504,E203

[isort]
line_length = 88
Expand Down
7 changes: 4 additions & 3 deletions sygnal/helper/proxy/proxyagent_twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def __init__(
parsed_url = decompose_http_proxy_url(proxy_url_str)
self._proxy_auth = parsed_url.credentials

self.proxy_endpoint = HostnameEndpoint(
self.proxy_endpoint: Optional[HostnameEndpoint] = HostnameEndpoint(
reactor, parsed_url.hostname, parsed_url.port, **self._endpoint_kwargs
) # type: Optional[HostnameEndpoint]
)
else:
self.proxy_endpoint = None

Expand Down Expand Up @@ -124,11 +124,12 @@ def request(self, method, uri, headers=None, bodyProducer=None):
pool_key: tuple = (parsed_uri.scheme, parsed_uri.host, parsed_uri.port)
request_path = parsed_uri.originForm

endpoint: IStreamClientEndpoint
if parsed_uri.scheme == b"http" and self.proxy_endpoint:
# Cache *all* connections under the same key, since we are only
# connecting to a single destination, the proxy:
pool_key = ("http-proxy", self.proxy_endpoint)
endpoint = self.proxy_endpoint # type: IStreamClientEndpoint
endpoint = self.proxy_endpoint
request_path = uri
elif parsed_uri.scheme == b"https" and self.proxy_endpoint:
endpoint = HTTPConnectProxyEndpoint(
Expand Down
2 changes: 1 addition & 1 deletion tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,6 @@ def process_request(self, method: bytes, request_path: bytes, content: BinaryIO)
"""pretend that a request has arrived, and process it"""

# this is normally done by HTTPChannel, in its various lineReceived etc methods
req = self.site.requestFactory(self) # type: Request
req: Request = self.site.requestFactory(self)
req.content = content
req.requestReceived(method, request_path, b"1.1")
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ commands =
[testenv:check_codestyle]

commands =
flake8 sygnal/ tests/
ruff sygnal/ tests/
black --check --diff sygnal/ tests/
isort --check-only --diff sygnal/ tests/

Expand Down

0 comments on commit dbaaf14

Please sign in to comment.