Skip to content

Commit a10fcc8

Browse files
authored
Use ruff for imports and formatting (#317)
1 parent bd99707 commit a10fcc8

File tree

18 files changed

+61
-148
lines changed

18 files changed

+61
-148
lines changed

.github/workflows/lint.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ruff, isort, black and mypy checks
1+
name: ruff and mypy checks
22

33
on:
44
push:
@@ -27,27 +27,19 @@ jobs:
2727
2828
- name: Ruff Linting AstraPy
2929
run: |
30-
poetry run ruff astrapy
30+
poetry run ruff check astrapy
3131
3232
- name: Ruff Linting Tests
3333
run: |
34-
poetry run ruff tests
34+
poetry run ruff check tests
3535
36-
- name: Isort Linting AstraPy
36+
- name: Ruff formatting astrapy
3737
run: |
38-
poetry run isort --check astrapy --profile black
39-
40-
- name: Isort Linting Tests
41-
run: |
42-
poetry run isort --check tests --profile black
43-
44-
- name: Black linting astrapy
45-
run: |
46-
poetry run black --check astrapy
38+
poetry run ruff format --check astrapy
4739
48-
- name: Black linting tests
40+
- name: Ruff formatting tests
4941
run: |
50-
poetry run black --check tests
42+
poetry run ruff format --check tests
5143
5244
- name: Run MyPy AstraPy
5345
run: |

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 24.2.0 # Replace with your desired version or use 'stable'
4-
hooks:
5-
- id: black
6-
args: ['--quiet']
7-
2+
- repo: local
3+
hooks:
4+
- id: check
5+
name: check
6+
language: system
7+
entry: make format-fix

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ FMT_FLAGS ?= --check
99
format: format-src format-tests
1010

1111
format-tests:
12-
poetry run ruff tests
13-
poetry run isort tests $(FMT_FLAGS) --profile black
14-
poetry run black tests $(FMT_FLAGS)
12+
poetry run ruff check tests
13+
poetry run ruff format tests $(FMT_FLAGS)
1514
poetry run mypy tests
1615

1716
format-src:
18-
poetry run ruff astrapy
19-
poetry run isort astrapy $(FMT_FLAGS) --profile black
20-
poetry run black astrapy $(FMT_FLAGS)
17+
poetry run ruff check astrapy
18+
poetry run ruff format astrapy $(FMT_FLAGS)
2119
poetry run mypy astrapy
2220

2321
format-fix: format-fix-src format-fix-tests

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Linter, style and typecheck should all pass for a PR:
242242
make format
243243
```
244244

245-
With `make format-fix` the style and imports are autofixed (by `black` and `isort` resp.)
245+
With `make format-fix` the style and imports are autofixed (by `ruff`)
246246

247247
Features must be thoroughly covered in tests (see `tests/idiomatic/*` for
248248
naming convention and module structure).

astrapy/collection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ def insert_many(
937937
with ThreadPoolExecutor(max_workers=_concurrency) as executor:
938938

939939
def _chunk_insertor(
940-
document_chunk: List[Dict[str, Any]]
940+
document_chunk: List[Dict[str, Any]],
941941
) -> Dict[str, Any]:
942942
im_payload = {
943943
"insertMany": {
@@ -5397,7 +5397,6 @@ async def bulk_write(
53975397
logger.info(f"finished a bulk write on '{self.name}'")
53985398
return full_bw_result
53995399
else:
5400-
54015400
sem = asyncio.Semaphore(_concurrency)
54025401

54035402
async def _concurrent_execute_as_either(

astrapy/core/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def is_list_of_floats(vector: Iterable[Any]) -> bool:
341341

342342

343343
def convert_to_ejson_date_object(
344-
date_value: Union[datetime.date, datetime.datetime]
344+
date_value: Union[datetime.date, datetime.datetime],
345345
) -> Dict[str, int]:
346346
return {"$date": int(time.mktime(date_value.timetuple()) * 1000)}
347347

@@ -355,7 +355,7 @@ def convert_to_ejson_objectid_object(objectid_value: ObjectId) -> Dict[str, str]
355355

356356

357357
def convert_ejson_date_object_to_datetime(
358-
date_object: Dict[str, int]
358+
date_object: Dict[str, int],
359359
) -> datetime.datetime:
360360
return datetime.datetime.fromtimestamp(date_object["$date"] / 1000.0)
361361

@@ -365,7 +365,7 @@ def convert_ejson_uuid_object_to_uuid(uuid_object: Dict[str, str]) -> UUID:
365365

366366

367367
def convert_ejson_objectid_object_to_objectid(
368-
objectid_object: Dict[str, str]
368+
objectid_object: Dict[str, str],
369369
) -> ObjectId:
370370
return ObjectId(objectid_object["$objectId"])
371371

@@ -402,7 +402,7 @@ def _normalize_payload_value(path: List[str], value: Any) -> Any:
402402

403403

404404
def normalize_for_api(
405-
payload: Union[Dict[str, Any], None]
405+
payload: Union[Dict[str, Any], None],
406406
) -> Union[Dict[str, Any], None]:
407407
"""
408408
Normalize a payload for API calls.

astrapy/cursors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def _maybe_valid_list_index(key_block: str) -> Optional[int]:
7373
def _create_document_key_extractor(
7474
key: str,
7575
) -> Callable[[Dict[str, Any]], Iterable[Any]]:
76-
7776
key_blocks0: List[IndexPairType] = [
7877
(kb_str, _maybe_valid_list_index(kb_str)) for kb_str in key.split(".")
7978
]

astrapy/info.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def as_dict(self) -> Dict[str, Any]:
152152

153153
@staticmethod
154154
def from_dict(
155-
raw_dict: Optional[Dict[str, Any]]
155+
raw_dict: Optional[Dict[str, Any]],
156156
) -> Optional[CollectionDefaultIDOptions]:
157157
"""
158158
Create an instance of CollectionDefaultIDOptions from a dictionary
@@ -201,7 +201,7 @@ def as_dict(self) -> Dict[str, Any]:
201201

202202
@staticmethod
203203
def from_dict(
204-
raw_dict: Optional[Dict[str, Any]]
204+
raw_dict: Optional[Dict[str, Any]],
205205
) -> Optional[CollectionVectorServiceOptions]:
206206
"""
207207
Create an instance of CollectionVectorServiceOptions from a dictionary
@@ -252,7 +252,7 @@ def as_dict(self) -> Dict[str, Any]:
252252

253253
@staticmethod
254254
def from_dict(
255-
raw_dict: Optional[Dict[str, Any]]
255+
raw_dict: Optional[Dict[str, Any]],
256256
) -> Optional[CollectionVectorOptions]:
257257
"""
258258
Create an instance of CollectionVectorOptions from a dictionary

astrapy/transform_payload.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def is_list_of_floats(vector: Iterable[Any]) -> bool:
4646

4747

4848
def convert_to_ejson_date_object(
49-
date_value: Union[datetime.date, datetime.datetime]
49+
date_value: Union[datetime.date, datetime.datetime],
5050
) -> Dict[str, int]:
5151
return {"$date": int(time.mktime(date_value.timetuple()) * 1000)}
5252

@@ -60,7 +60,7 @@ def convert_to_ejson_objectid_object(objectid_value: ObjectId) -> Dict[str, str]
6060

6161

6262
def convert_ejson_date_object_to_datetime(
63-
date_object: Dict[str, int]
63+
date_object: Dict[str, int],
6464
) -> datetime.datetime:
6565
return datetime.datetime.fromtimestamp(date_object["$date"] / 1000.0)
6666

@@ -70,7 +70,7 @@ def convert_ejson_uuid_object_to_uuid(uuid_object: Dict[str, str]) -> UUID:
7070

7171

7272
def convert_ejson_objectid_object_to_objectid(
73-
objectid_object: Dict[str, str]
73+
objectid_object: Dict[str, str],
7474
) -> ObjectId:
7575
return ObjectId(objectid_object["$objectId"])
7676

@@ -105,7 +105,7 @@ def normalize_payload_value(path: List[str], value: Any) -> Any:
105105

106106

107107
def normalize_for_api(
108-
payload: Union[Dict[str, Any], None]
108+
payload: Union[Dict[str, Any], None],
109109
) -> Union[Dict[str, Any], None]:
110110
"""
111111
Normalize a payload for API calls.

astrapy/user_agents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def compose_user_agent_string(
5050

5151

5252
def compose_full_user_agent(
53-
callers: List[Tuple[Optional[str], Optional[str]]]
53+
callers: List[Tuple[Optional[str], Optional[str]]],
5454
) -> Optional[str]:
5555
user_agent_strings = [
5656
ua_string

0 commit comments

Comments
 (0)