Skip to content

Commit

Permalink
add ruff config
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Oct 14, 2023
1 parent cd376e3 commit ea4a87f
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 51 deletions.
3 changes: 1 addition & 2 deletions app/mypy_playground/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
from pathlib import Path
from typing import Any

from tornado.options import define, options
import tornado.web
from tornado.options import define, options

from mypy_playground import handlers
from mypy_playground.prometheus import PrometheusMixin
from mypy_playground.utils import ListPairOption


logger = logging.getLogger(__name__)
root_dir = Path(__file__).parents[1]
static_dir = root_dir / "static" / "_next"
Expand Down
5 changes: 1 addition & 4 deletions app/mypy_playground/gist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from tornado.httpclient import AsyncHTTPClient
from tornado.options import options


API_ENDPOINT = "https://api.github.com/gists"


Expand Down Expand Up @@ -33,10 +32,8 @@ async def create_gist(source: str) -> dict[str, str] | None:
return None

res_data = json.loads(res.body)
result = {
return {
"id": res_data["id"],
"url": res_data["html_url"],
"source": source, # NOTE: We should obtain from response?
}

return result
9 changes: 4 additions & 5 deletions app/mypy_playground/handlers.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import dataclasses
from http import HTTPStatus
import json
import logging
import traceback
from http import HTTPStatus
from typing import Any, cast

from prometheus_client import exposition
import tornado.escape
from tornado.options import options
import tornado.web
from prometheus_client import exposition
from tornado.options import options

from mypy_playground import gist
from mypy_playground.prometheus import PrometheusMixin
from mypy_playground.sandbox import run_typecheck_in_sandbox
from mypy_playground.sandbox.base import (
AbstractSandbox,
ARGUMENT_FLAGS,
AbstractSandbox,
)
from mypy_playground.sandbox.cloud_functions import CloudFunctionsSandbox
from mypy_playground.sandbox.docker import DockerSandbox


logger = logging.getLogger(__name__)
initial_code = """from typing import Iterator
Expand Down
8 changes: 4 additions & 4 deletions app/mypy_playground/prometheus.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from typing import Any, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING, Any, Optional

import tornado
from prometheus_client import Counter, Histogram, REGISTRY
from prometheus_client import REGISTRY, Counter, Histogram
from tornado.web import RequestHandler


_NAMESPACE = "mypy_play"
_SUB_SYSTEM = "http"


if TYPE_CHECKING:
import tornado

_Base = tornado.web.Application
else:
_Base = object
Expand Down
1 change: 0 additions & 1 deletion app/mypy_playground/sandbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from mypy_playground.sandbox.base import AbstractSandbox, Result


logger = logging.getLogger(__name__)


Expand Down
2 changes: 0 additions & 2 deletions app/mypy_playground/sandbox/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass

from typing import Any, Optional


ARGUMENT_FLAGS_NORMAL = (
"verbose",
"ignore-missing-imports",
Expand Down
6 changes: 3 additions & 3 deletions app/mypy_playground/sandbox/cloud_functions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import json
import time
import urllib.parse
from logging import getLogger
import time
from typing import Any, Optional

import google.auth.transport.requests
import google.oauth2.id_token
from tornado.httpclient import AsyncHTTPClient
from tornado.options import define, options

from mypy_playground.sandbox.base import AbstractSandbox, ARGUMENT_FLAGS, Result
from mypy_playground.sandbox.base import ARGUMENT_FLAGS, AbstractSandbox, Result
from mypy_playground.utils import DictOption

logger = getLogger(__name__)
Expand Down Expand Up @@ -68,7 +68,7 @@ async def run_typecheck(
args = ["--cache-dir", "/dev/null", "--no-site-packages"]
if python_version:
args += ["--python-version", f"{python_version}"]
for key, value in kwargs.items():
for key, _value in kwargs.items():
if key in ARGUMENT_FLAGS:
args.append(f"--{key}")

Expand Down
9 changes: 4 additions & 5 deletions app/mypy_playground/sandbox/docker.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from io import BytesIO
import logging
from pathlib import Path
import tarfile
import time
from io import BytesIO
from pathlib import Path
from typing import Any, Optional, cast

import aiodocker
from tornado.options import define, options

from mypy_playground.sandbox.base import AbstractSandbox, ARGUMENT_FLAGS, Result
from mypy_playground.sandbox.base import ARGUMENT_FLAGS, AbstractSandbox, Result
from mypy_playground.utils import DictOption


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -50,7 +49,7 @@ async def run_typecheck(
cmd = ["mypy", "--cache-dir", "/dev/null", "--no-site-packages"]
if python_version:
cmd += ["--python-version", f"{python_version}"]
for key, value in kwargs.items():
for key, _value in kwargs.items():
if key in ARGUMENT_FLAGS:
cmd.append(f"--{key}")
cmd.append(self.source_file_path.name)
Expand Down
4 changes: 2 additions & 2 deletions app/mypy_playground/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import Any, cast

import tomli
import tomllib
from tornado.options import options


Expand Down Expand Up @@ -73,7 +73,7 @@ def parse_toml_file(path: Path) -> None:
if not path.is_file():
return
with open(path, "rb") as f:
config = tomli.load(f)
config = tomllib.load(f)
for option_name in options._options:
value = config.get(option_name)
if value is None:
Expand Down
6 changes: 6 additions & 0 deletions app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ module = [
'google.*',
]
ignore_missing_imports = true

[tool.ruff]
select = ["E", "F", "I", "W", "UP"]

[tool.ruff.per-file-ignores]
"tests/*" = ["S101", "I001"]
1 change: 0 additions & 1 deletion app/requirements.dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ pytest-tornado
types-chardet
types-mock
types-setuptools
types-toml
20 changes: 10 additions & 10 deletions app/requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
#
# pip-compile requirements.dev.in
#
coverage[toml]==7.2.7
colorama==0.4.6
# via pytest
coverage[toml]==7.3.1
# via pytest-cov
iniconfig==2.0.0
# via pytest
mypy==1.4.1
mypy==1.5.1
# via -r requirements.dev.in
mypy-extensions==1.0.0
# via mypy
packaging==23.1
# via pytest
pluggy==1.2.0
pluggy==1.3.0
# via pytest
pytest==7.4.0
pytest==7.4.2
# via
# -r requirements.dev.in
# pytest-cov
Expand All @@ -27,7 +29,7 @@ pytest-cov==4.1.0
# via -r requirements.dev.in
pytest-mock==3.11.1
# via -r requirements.dev.in
pytest-randomly==3.12.0
pytest-randomly==3.15.0
# via -r requirements.dev.in
pytest-tornado==0.8.1
# via -r requirements.dev.in
Expand All @@ -37,13 +39,11 @@ tornado==6.3.3
# pytest-tornado
types-chardet==5.0.4.6
# via -r requirements.dev.in
types-mock==5.0.0.7
# via -r requirements.dev.in
types-setuptools==68.0.0.0
types-mock==5.1.0.2
# via -r requirements.dev.in
types-toml==0.10.8.6
types-setuptools==68.2.0.0
# via -r requirements.dev.in
typing-extensions==4.7.0
typing-extensions==4.8.0
# via
# -c requirements.txt
# mypy
Expand Down
1 change: 0 additions & 1 deletion app/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ dataclasses
google-auth
prometheus_client<1
requests # Until google-auth supports asyncio
tomli
tornado>=6,<7
16 changes: 6 additions & 10 deletions app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ aiohttp==3.8.5
# via aiodocker
aiosignal==1.3.1
# via aiohttp
async-timeout==4.0.2
async-timeout==4.0.3
# via aiohttp
attrs==23.1.0
# via aiohttp
cachetools==5.3.1
# via google-auth
certifi==2023.7.22
# via requests
charset-normalizer==3.1.0
charset-normalizer==3.2.0
# via
# aiohttp
# requests
dataclasses==0.6
# via -r requirements.in
frozenlist==1.3.3
frozenlist==1.4.0
# via
# aiohttp
# aiosignal
google-auth==2.21.0
google-auth==2.23.2
# via -r requirements.in
idna==3.4
# via
Expand All @@ -38,7 +38,7 @@ multidict==6.0.4
# via
# aiohttp
# yarl
prometheus-client==0.17.0
prometheus-client==0.17.1
# via -r requirements.in
pyasn1==0.5.0
# via
Expand All @@ -50,13 +50,9 @@ requests==2.31.0
# via -r requirements.in
rsa==4.9
# via google-auth
six==1.16.0
# via google-auth
tomli==2.0.1
# via -r requirements.in
tornado==6.3.3
# via -r requirements.in
typing-extensions==4.7.0
typing-extensions==4.8.0
# via aiodocker
urllib3==1.26.17
# via
Expand Down
4 changes: 3 additions & 1 deletion app/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ skipsdist = true

[gh-actions]
python =
3.11: mypy, pre-commit, py311
3.11: pytest, mypy, pre-commit, py311

[testenv]
deps =
-r {toxinidir}/requirements.txt
-r {toxinidir}/requirements.dev.txt
commands = pytest --cov=mypy_playground tests

[testenv:pytest]

[testenv:mypy]
commands = mypy .

Expand Down

0 comments on commit ea4a87f

Please sign in to comment.