Skip to content

Commit

Permalink
Fix linter errors (#1691)
Browse files Browse the repository at this point in the history
* ruff --fix

Signed-off-by: Mattt Zmuda <mattt@replicate.com>

* Update ruff pyproject settings

Signed-off-by: Mattt Zmuda <mattt@replicate.com>

* Update ruff lint command in Makefile

Signed-off-by: Mattt Zmuda <mattt@replicate.com>

---------

Signed-off-by: Mattt Zmuda <mattt@replicate.com>
  • Loading branch information
mattt authored May 24, 2024
1 parent bea12d8 commit de9b676
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ lint-go:

.PHONY: lint-python
lint-python:
$(RUFF) python/cog
$(RUFF) check python/cog
$(RUFF) format --check python
@$(PYTHON) -c 'import sys; sys.exit("Warning: python >=3.10 is needed (not installed) to pass linting (pyright)") if sys.version_info < (3, 10) else None'
$(PYRIGHT)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ reportUnusedExpression = "warning"
package-dir = { "" = "python" }

[tool.ruff]
select = [
lint.select = [
"E", # pycodestyle error
"F", # Pyflakes
"I", # isort
Expand All @@ -77,7 +77,7 @@ select = [
"B", # flake8-bugbear
"ANN", # flake8-annotations
]
ignore = [
lint.ignore = [
"E501", # Line too long
"S101", # Use of `assert` detected"
"S113", # Probable use of requests call without timeout
Expand All @@ -94,7 +94,7 @@ extend-exclude = [
"test-integration/test_integration/fixtures/*",
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"python/cog/server/http.py" = [
"S104", # Possible binding to all interfaces
]
Expand Down
18 changes: 9 additions & 9 deletions python/cog/command/ast_openapi_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def predict(
format = {"format": "uri"} if name in ("Path", "File") else {}
return {}, {"title": "Output", "type": OPENAPI_TYPES.get(name, name), **format}
# it must be a custom object
schema: "JSONDict" = {name: parse_class(find(tree, name))}
schema: JSONDict = {name: parse_class(find(tree, name))}
return schema, {
"title": "Output",
"$ref": f"#/components/schemas/{name}",
Expand All @@ -506,10 +506,10 @@ def predict(
def extract_info(code: str) -> "JSONDict":
"""Parse the schemas from a file with a predict function"""
tree = ast.parse(code)
properties: "JSONDict" = {}
inputs: "JSONDict" = {"title": "Input", "type": "object", "properties": properties}
required: "list[str]" = []
schemas: "JSONDict" = {}
properties: JSONDict = {}
inputs: JSONDict = {"title": "Input", "type": "object", "properties": properties}
required: list[str] = []
schemas: JSONDict = {}
for arg, default in parse_args(tree):
if arg.arg == "self":
continue
Expand All @@ -526,7 +526,7 @@ def extract_info(code: str) -> "JSONDict":
kws = {}
else:
raise ValueError("Unexpected default value", default)
input: "JSONDict" = {"x-order": len(properties)}
input: JSONDict = {"x-order": len(properties)}
# need to handle other types?
arg_type = OPENAPI_TYPES.get(get_annotation(arg.annotation), "string")
if get_annotation(arg.annotation) in ("Path", "File"):
Expand All @@ -553,15 +553,15 @@ def extract_info(code: str) -> "JSONDict":
inputs["required"] = list(required)
# List[Path], list[Path], str, Iterator[str], MyOutput, Output
return_schema, output = parse_return_annotation(tree, "predict")
schema: "JSONDict" = json.loads(BASE_SCHEMA)
components: "JSONDict" = {
schema: JSONDict = json.loads(BASE_SCHEMA)
components: JSONDict = {
"Input": inputs,
"Output": output,
**schemas,
**return_schema,
}
# trust me, typechecker, I know BASE_SCHEMA
x: "JSONDict" = schema["components"]["schemas"] # type: ignore
x: JSONDict = schema["components"]["schemas"] # type: ignore
x.update(components)
return schema

Expand Down
6 changes: 3 additions & 3 deletions python/tests/cog/test_files.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import requests
import io
import responses
from cog.files import put_file_to_signed_endpoint
from unittest.mock import Mock

import requests
from cog.files import put_file_to_signed_endpoint


def test_put_file_to_signed_endpoint():
mock_fh = io.BytesIO()
Expand Down
3 changes: 2 additions & 1 deletion python/tests/server/test_code_xforms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import pytest
import sys
import uuid

import cog.code_xforms as code_xforms
import pytest

g_module_dir = os.path.dirname(os.path.abspath(__file__))

Expand Down

0 comments on commit de9b676

Please sign in to comment.