Skip to content

Commit 89e719a

Browse files
authored
chore: bump ruff and ensure imports are sorted (#385)
* chore: upgrade ruff & sort imports
1 parent 02495ff commit 89e719a

25 files changed

+97
-89
lines changed

examples/async-chat.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
23
from ollama import AsyncClient
34

45

examples/async-generate.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
23
import ollama
34

45

examples/async-structured-outputs.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import asyncio
2+
13
from pydantic import BaseModel
4+
25
from ollama import AsyncClient
3-
import asyncio
46

57

68
# Define the schema for the response

examples/async-tools.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
2-
from ollama import ChatResponse
2+
33
import ollama
4+
from ollama import ChatResponse
45

56

67
def add_two_numbers(a: int, b: int) -> int:

examples/chat-stream.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from ollama import chat
22

3-
43
messages = [
54
{
65
'role': 'user',

examples/chat-with-history.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from ollama import chat
22

3-
43
messages = [
54
{
65
'role': 'user',

examples/generate-stream.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from ollama import generate
22

3-
43
for part in generate('llama3.2', 'Why is the sky blue?', stream=True):
54
print(part['response'], end='', flush=True)

examples/generate.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from ollama import generate
22

3-
43
response = generate('llama3.2', 'Why is the sky blue?')
54
print(response['response'])

examples/list.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from ollama import list
2-
from ollama import ListResponse
1+
from ollama import ListResponse, list
32

43
response: ListResponse = list()
54

examples/multimodal-chat.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ollama import chat
2+
23
# from pathlib import Path
34

45
# Pass in the path to the image

examples/multimodal-generate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import sys
21
import random
2+
import sys
3+
34
import httpx
45

56
from ollama import generate
67

7-
88
latest = httpx.get('https://xkcd.com/info.0.json')
99
latest.raise_for_status()
1010

examples/ps.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from ollama import ps, pull, chat
2-
from ollama import ProcessResponse
1+
from ollama import ProcessResponse, chat, ps, pull
32

43
# Ensure at least one model is loaded
54
response = pull('llama3.2', stream=True)

examples/pull.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from tqdm import tqdm
2-
from ollama import pull
32

3+
from ollama import pull
44

55
current_digest, bars = '', {}
66
for progress in pull('llama3.2', stream=True):

examples/structured-outputs-image.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from pathlib import Path
2-
from pydantic import BaseModel
32
from typing import Literal
3+
4+
from pydantic import BaseModel
5+
46
from ollama import chat
57

68

examples/structured-outputs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from ollama import chat
21
from pydantic import BaseModel
32

3+
from ollama import chat
4+
45

56
# Define the schema for the response
67
class FriendInfo(BaseModel):

examples/tools.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from ollama import chat
2-
from ollama import ChatResponse
1+
from ollama import ChatResponse, chat
32

43

54
def add_two_numbers(a: int, b: int) -> int:

ollama/__init__.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
from ollama._client import Client, AsyncClient
1+
from ollama._client import AsyncClient, Client
22
from ollama._types import (
3-
Options,
4-
Message,
5-
Image,
6-
Tool,
7-
GenerateResponse,
83
ChatResponse,
9-
EmbedResponse,
104
EmbeddingsResponse,
11-
StatusResponse,
12-
ProgressResponse,
5+
EmbedResponse,
6+
GenerateResponse,
7+
Image,
138
ListResponse,
14-
ShowResponse,
9+
Message,
10+
Options,
1511
ProcessResponse,
12+
ProgressResponse,
1613
RequestError,
1714
ResponseError,
15+
ShowResponse,
16+
StatusResponse,
17+
Tool,
1818
)
1919

2020
__all__ = [
21-
'Client',
2221
'AsyncClient',
23-
'Options',
24-
'Message',
25-
'Image',
26-
'Tool',
27-
'GenerateResponse',
2822
'ChatResponse',
23+
'Client',
2924
'EmbedResponse',
3025
'EmbeddingsResponse',
31-
'StatusResponse',
32-
'ProgressResponse',
26+
'GenerateResponse',
27+
'Image',
3328
'ListResponse',
34-
'ShowResponse',
29+
'Message',
30+
'Options',
3531
'ProcessResponse',
32+
'ProgressResponse',
3633
'RequestError',
3734
'ResponseError',
35+
'ShowResponse',
36+
'StatusResponse',
37+
'Tool',
3838
]
3939

4040
_client = Client()

ollama/_client.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import os
1+
import ipaddress
22
import json
3+
import os
34
import platform
4-
import ipaddress
5+
import sys
56
import urllib.parse
7+
from hashlib import sha256
68
from os import PathLike
79
from pathlib import Path
8-
from hashlib import sha256
9-
1010
from typing import (
1111
Any,
1212
Callable,
13+
Dict,
14+
List,
1315
Literal,
1416
Mapping,
1517
Optional,
@@ -18,21 +20,16 @@
1820
TypeVar,
1921
Union,
2022
overload,
21-
Dict,
22-
List,
2323
)
2424

25-
import sys
26-
2725
from pydantic.json_schema import JsonSchemaValue
2826

29-
3027
from ollama._utils import convert_function_to_tool
3128

3229
if sys.version_info < (3, 9):
33-
from typing import Iterator, AsyncIterator
30+
from typing import AsyncIterator, Iterator
3431
else:
35-
from collections.abc import Iterator, AsyncIterator
32+
from collections.abc import AsyncIterator, Iterator
3633

3734
from importlib import metadata
3835

@@ -46,13 +43,13 @@
4643
from ollama._types import (
4744
ChatRequest,
4845
ChatResponse,
49-
CreateRequest,
5046
CopyRequest,
47+
CreateRequest,
5148
DeleteRequest,
52-
EmbedRequest,
53-
EmbedResponse,
5449
EmbeddingsRequest,
5550
EmbeddingsResponse,
51+
EmbedRequest,
52+
EmbedResponse,
5653
GenerateRequest,
5754
GenerateResponse,
5855
Image,
@@ -70,7 +67,6 @@
7067
Tool,
7168
)
7269

73-
7470
T = TypeVar('T')
7571

7672

ollama/_types.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import json
22
from base64 import b64decode, b64encode
3-
from pathlib import Path
43
from datetime import datetime
5-
from typing import Any, Mapping, Optional, Union, Sequence, Dict, List
6-
7-
from pydantic.json_schema import JsonSchemaValue
8-
from typing_extensions import Annotated, Literal
4+
from pathlib import Path
5+
from typing import Any, Dict, List, Mapping, Optional, Sequence, Union
96

107
from pydantic import (
118
BaseModel,
@@ -14,6 +11,8 @@
1411
Field,
1512
model_serializer,
1613
)
14+
from pydantic.json_schema import JsonSchemaValue
15+
from typing_extensions import Annotated, Literal
1716

1817

1918
class SubscriptableBaseModel(BaseModel):

ollama/_utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import annotations
2-
from collections import defaultdict
2+
33
import inspect
4-
from typing import Callable, Union
54
import re
5+
from collections import defaultdict
6+
from typing import Callable, Union
67

78
import pydantic
9+
810
from ollama._types import Tool
911

1012

poetry.lock

+20-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+11-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pytest = ">=7.4.3,<9.0.0"
2121
pytest-asyncio = ">=0.23.2,<0.25.0"
2222
pytest-cov = ">=4.1,<6.0"
2323
pytest-httpserver = "^1.0.8"
24-
ruff = ">=0.1.8,<0.8.0"
24+
ruff = ">=0.9.1,<0.10.0"
2525

2626
[build-system]
2727
requires = ["poetry-core"]
@@ -36,8 +36,16 @@ quote-style = "single"
3636
indent-style = "space"
3737

3838
[tool.ruff.lint]
39-
select = ["E", "F", "B"]
40-
ignore = ["E501"]
39+
select = [
40+
"E", # pycodestyle errors
41+
"F", # pyflakes
42+
"B", # bugbear (likely bugs)
43+
"I", # sort imports
44+
"RUF022", # sort __all__
45+
]
46+
ignore = [
47+
"E501", # line too long
48+
]
4149

4250
[tool.pytest.ini_options]
4351
addopts = '--doctest-modules --ignore examples'

0 commit comments

Comments
 (0)