Skip to content

Commit 36aabab

Browse files
authored
chore(clients): use the ruff python formatter (#3204)
1 parent 9f579db commit 36aabab

File tree

11 files changed

+67
-1555
lines changed

11 files changed

+67
-1555
lines changed

config/generation.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,18 @@ export const patterns = [
102102

103103
// Python
104104
'!snippets/python/pyproject.toml',
105-
'!snippets/python/poetry.lock',
106105
'clients/algoliasearch-client-python/**',
107106
'!clients/algoliasearch-client-python/algoliasearch/http/**',
108107
'!clients/algoliasearch-client-python/algoliasearch/py.typed',
109108
'clients/algoliasearch-client-python/algoliasearch/http/__init__.py',
110109
'!clients/algoliasearch-client-python/*',
111110
'clients/algoliasearch-client-python/pyproject.toml',
111+
'clients/algoliasearch-client-python/poetry.lock',
112112
'clients/algoliasearch-client-python/requirements.txt',
113113
'clients/algoliasearch-client-python/.gitignore',
114114

115115
'tests/output/python/requirements.txt',
116+
'tests/output/python/poetry.lock',
116117
'!tests/output/python/**/__init__.py',
117118

118119
// Ruby

playground/python/app/search.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@
1111
async def main():
1212
print("SearchClient version", __version__)
1313

14-
client = SearchClient(environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY"))
14+
client = SearchClient(
15+
environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY")
16+
)
1517
print("client initialized", client)
1618

1719
try:
1820
resp = await client.replace_all_objects(
1921
index_name="newoneeverytime",
20-
objects=[{"name": f"John Doe{i}", "objectID": f"fff2bd4d-bb17-4e21-a0c4-0a8ea5e363f2{i}" } for i in range(33)],
21-
batch_size=10
22+
objects=[
23+
{
24+
"name": f"John Doe{i}",
25+
"objectID": f"fff2bd4d-bb17-4e21-a0c4-0a8ea5e363f2{i}",
26+
}
27+
for i in range(33)
28+
],
29+
batch_size=10,
2230
)
2331

2432
print(resp)

playground/python/poetry.lock

Lines changed: 24 additions & 1510 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playground/python/pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ repository = "https://github.com/algolia/api-clients-automation"
1111
[tool.poetry.dependencies]
1212
python = "3.11.6"
1313
algoliasearch = { path = "../../clients/algoliasearch-client-python", develop = true }
14-
flake8 = "6.1.0"
15-
autoflake = "2.2.1"
16-
autopep8 = "2.0.4"
17-
black = "24.3.0"
18-
isort = "5.13.0"
14+
ruff = "0.4.9"
1915
python-dotenv = "1.0.0"
2016

2117
[tool.poetry.scripts]

scripts/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function formatter(language: string, cwd: string): Promise<void> {
5454
break;
5555
case 'python':
5656
await run(
57-
'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run autopep8 -r --in-place --aggressive . && poetry run autoflake -r --remove-unused-variables --remove-all-unused-imports --in-place . && poetry run isort . && poetry run black . && poetry run flake8 --ignore=E501,W503 .',
57+
'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run ruff check --fix && poetry run ruff format',
5858
{ cwd, language },
5959
);
6060
break;

snippets/python/pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@ repository = "https://github.com/algolia/api-clients-automation"
1010
[tool.poetry.dependencies]
1111
python = "3.11.6"
1212
algoliasearch = { path = "../../clients/algoliasearch-client-python", develop = true }
13-
flake8 = "6.1.0"
14-
autoflake = "2.2.1"
15-
autopep8 = "2.0.4"
16-
black = "24.3.0"
17-
isort = "5.13.0"
13+
ruff = "0.4.9"

templates/python/model_generic.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
239239
"{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
240240
{{/items.items.isPrimitiveType}}
241241
{{^items.items.isPrimitiveType}}
242-
"{{{baseName}}}": [
242+
"{{{baseName}}}": ([
243243
[{{{items.items.dataType}}}.from_dict(_inner_item) for _inner_item in _item]
244244
for _item in obj.get("{{{baseName}}}")
245-
] if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
245+
] if obj.get("{{{baseName}}}") is not None else None){{^-last}},{{/-last}}
246246
{{/items.items.isPrimitiveType}}
247247
{{/items.isArray}}
248248
{{^items.isArray}}
@@ -251,7 +251,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
251251
"{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
252252
{{/items.isEnumOrRef}}
253253
{{^items.isEnumOrRef}}
254-
"{{{baseName}}}": [{{{items.dataType}}}.from_dict(_item) for _item in obj.get("{{{baseName}}}")] if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
254+
"{{{baseName}}}": ([{{{items.dataType}}}.from_dict(_item) for _item in obj.get("{{{baseName}}}")] if obj.get("{{{baseName}}}") is not None else None){{^-last}},{{/-last}}
255255
{{/items.isEnumOrRef}}
256256
{{/items.isPrimitiveType}}
257257
{{#items.isPrimitiveType}}
@@ -264,7 +264,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
264264
{{^items.isEnumOrRef}}
265265
{{#items.isContainer}}
266266
{{#items.isMap}}
267-
"{{{baseName}}}": dict(
267+
"{{{baseName}}}": (dict(
268268
(_k, dict(
269269
(_ik, {{{items.items.dataType}}}.from_dict(_iv))
270270
for _ik, _iv in _v.items()
@@ -275,7 +275,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
275275
for _k, _v in obj.get("{{{baseName}}}").items()
276276
)
277277
if obj.get("{{{baseName}}}") is not None
278-
else None{{^-last}},{{/-last}}
278+
else None){{^-last}},{{/-last}}
279279
{{/items.isMap}}
280280
{{#items.isArray}}
281281
"{{{baseName}}}": dict(
@@ -289,12 +289,12 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
289289
{{/items.isArray}}
290290
{{/items.isContainer}}
291291
{{^items.isContainer}}
292-
"{{{baseName}}}": dict(
292+
"{{{baseName}}}": (dict(
293293
(_k, {{{items.dataType}}}.from_dict(_v))
294294
for _k, _v in obj.get("{{{baseName}}}").items()
295295
)
296296
if obj.get("{{{baseName}}}") is not None
297-
else None{{^-last}},{{/-last}}
297+
else None){{^-last}},{{/-last}}
298298
{{/items.isContainer}}
299299
{{/items.isEnumOrRef}}
300300
{{#items.isEnumOrRef}}
@@ -309,7 +309,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
309309
{{^isContainer}}
310310
{{^isPrimitiveType}}
311311
{{^isEnumOrRef}}
312-
"{{{baseName}}}": {{{dataType}}}.from_dict(obj.get("{{{baseName}}}")) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
312+
"{{{baseName}}}": ({{{dataType}}}.from_dict(obj.get("{{{baseName}}}")) if obj.get("{{{baseName}}}") is not None else None){{^-last}},{{/-last}}
313313
{{/isEnumOrRef}}
314314
{{#isEnumOrRef}}
315315
"{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
@@ -329,4 +329,4 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
329329

330330
{{/isAdditionalPropertiesTrue}}
331331
return _obj
332-
{{/hasChildren}}
332+
{{/hasChildren}}

templates/python/model_oneof.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
3737

3838
{{/isNullable}}
3939
error_messages = []
40-
match = 0
4140

4241
{{#composedSchemas.oneOf}}
4342
{{#isContainer}}

templates/python/pyproject.mustache

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,20 @@ async-timeout = ">= 4.0.3"
2222
pydantic = ">= 2"
2323

2424
[tool.poetry.group.dev.dependencies]
25-
flake8 = "7.0.0"
26-
autoflake = "2.3.1"
27-
autopep8 = "2.2.0"
28-
black = "24.4.2"
29-
isort = "5.13.2"
25+
ruff = "0.4.9"
3026

31-
[tool.flake8]
32-
max-line-length = 88
33-
ignore = ['E501']
27+
[tool.ruff]
28+
line-length = 88
3429

35-
[tool.isort]
36-
line_length=88
37-
include_trailing_comma=true
38-
multi_line_output=3
39-
force_grid_wrap=0
40-
combine_as_imports=true
30+
[tool.ruff.lint]
31+
select = ["E4", "E7", "E9", "F", "I"]
32+
ignore = ["E501"]
33+
34+
[tool.ruff.lint.isort]
35+
split-on-trailing-comma = false
36+
37+
[tool.ruff.format]
38+
quote-style = "double"
4139

4240
[build-system]
4341
requires = ["poetry-core"]
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
_config = {{#lambda.pascalcase}}{{clientPrefix}}Config{{/lambda.pascalcase}}("{{parametersWithDataTypeMap.appId.value}}", "{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region}},"{{parametersWithDataTypeMap.region.value}}"{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}});{{#hasCustomHosts}}_config.hosts = HostsCollection([{{#customHosts}}Host(url='{{host}}', scheme='http', port={{port}}){{^-last}},{{/-last}}{{/customHosts}}]){{/hasCustomHosts}};self._client = {{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}.create_with_config(config=_config{{#useEchoRequester}}, transporter=EchoTransporter(_config){{/useEchoRequester}})
1+
_config = {{#lambda.pascalcase}}{{clientPrefix}}Config{{/lambda.pascalcase}}("{{parametersWithDataTypeMap.appId.value}}", "{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region}},"{{parametersWithDataTypeMap.region.value}}"{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}})
2+
{{#hasCustomHosts}}
3+
{{#isError}} {{/isError}}_config.hosts = HostsCollection([{{#customHosts}}Host(url='{{host}}', scheme='http', port={{port}}){{^-last}},{{/-last}}{{/customHosts}}])
4+
{{/hasCustomHosts}}
5+
{{#isError}} {{/isError}}self._client = {{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}.create_with_config(config=_config{{#useEchoRequester}}, transporter=EchoTransporter(_config){{/useEchoRequester}})

tests/output/python/pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ repository = "https://github.com/algolia/api-clients-automation"
1010
[tool.poetry.dependencies]
1111
python = "3.11.6"
1212
algoliasearch = { path = "../../../clients/algoliasearch-client-python", develop = true }
13-
flake8 = "6.1.0"
14-
autoflake = "2.2.1"
15-
autopep8 = "2.0.4"
16-
black = "24.3.0"
17-
isort = "5.13.0"
13+
ruff = "0.4.9"
1814
pytest = "7.4.3"
1915
python-dotenv = "1.0.0"
2016
pytest-aiohttp = "1.0.5"

0 commit comments

Comments
 (0)