Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(clients): use the ruff python formatter #3204

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/generation.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,18 @@ export const patterns = [

// Python
'!snippets/python/pyproject.toml',
'!snippets/python/poetry.lock',
'clients/algoliasearch-client-python/**',
'!clients/algoliasearch-client-python/algoliasearch/http/**',
'!clients/algoliasearch-client-python/algoliasearch/py.typed',
'clients/algoliasearch-client-python/algoliasearch/http/__init__.py',
'!clients/algoliasearch-client-python/*',
'clients/algoliasearch-client-python/pyproject.toml',
'clients/algoliasearch-client-python/poetry.lock',
'clients/algoliasearch-client-python/requirements.txt',
'clients/algoliasearch-client-python/.gitignore',

'tests/output/python/requirements.txt',
'tests/output/python/poetry.lock',
'!tests/output/python/**/__init__.py',

// Ruby
Expand Down
14 changes: 11 additions & 3 deletions playground/python/app/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@
async def main():
print("SearchClient version", __version__)

client = SearchClient(environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY"))
client = SearchClient(
environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY")
)
print("client initialized", client)

try:
resp = await client.replace_all_objects(
index_name="newoneeverytime",
objects=[{"name": f"John Doe{i}", "objectID": f"fff2bd4d-bb17-4e21-a0c4-0a8ea5e363f2{i}" } for i in range(33)],
batch_size=10
objects=[
{
"name": f"John Doe{i}",
"objectID": f"fff2bd4d-bb17-4e21-a0c4-0a8ea5e363f2{i}",
}
for i in range(33)
],
batch_size=10,
)

print(resp)
Expand Down
1,534 changes: 24 additions & 1,510 deletions playground/python/poetry.lock

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions playground/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ repository = "https://github.com/algolia/api-clients-automation"
[tool.poetry.dependencies]
python = "3.11.6"
algoliasearch = { path = "../../clients/algoliasearch-client-python", develop = true }
flake8 = "6.1.0"
autoflake = "2.2.1"
autopep8 = "2.0.4"
black = "24.3.0"
isort = "5.13.0"
ruff = "0.4.9"
python-dotenv = "1.0.0"

[tool.poetry.scripts]
Expand Down
2 changes: 1 addition & 1 deletion scripts/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function formatter(language: string, cwd: string): Promise<void> {
break;
case 'python':
await run(
'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 .',
'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run ruff check --fix && poetry run ruff format',
{ cwd, language },
);
break;
Expand Down
6 changes: 1 addition & 5 deletions snippets/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ repository = "https://github.com/algolia/api-clients-automation"
[tool.poetry.dependencies]
python = "3.11.6"
algoliasearch = { path = "../../clients/algoliasearch-client-python", develop = true }
flake8 = "6.1.0"
autoflake = "2.2.1"
autopep8 = "2.0.4"
black = "24.3.0"
isort = "5.13.0"
ruff = "0.4.9"
1 change: 0 additions & 1 deletion templates/python/model_oneof.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}

{{/isNullable}}
error_messages = []
match = 0

{{#composedSchemas.oneOf}}
{{#isContainer}}
Expand Down
26 changes: 12 additions & 14 deletions templates/python/pyproject.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ async-timeout = ">= 4.0.3"
pydantic = ">= 2"

[tool.poetry.group.dev.dependencies]
flake8 = "7.0.0"
autoflake = "2.3.1"
autopep8 = "2.2.0"
black = "24.4.2"
isort = "5.13.2"
ruff = "0.4.9"

[tool.flake8]
max-line-length = 88
ignore = ['E501']
[tool.ruff]
line-length = 88

[tool.isort]
line_length=88
include_trailing_comma=true
multi_line_output=3
force_grid_wrap=0
combine_as_imports=true
[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "I"]
ignore = ["E501"]

[tool.ruff.lint.isort]
split-on-trailing-comma = false

[tool.ruff.format]
quote-style = "double"

[build-system]
requires = ["poetry-core"]
Expand Down
6 changes: 5 additions & 1 deletion templates/python/tests/client/createClient.mustache
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
_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}})
_config = {{#lambda.pascalcase}}{{clientPrefix}}Config{{/lambda.pascalcase}}("{{parametersWithDataTypeMap.appId.value}}", "{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region}},"{{parametersWithDataTypeMap.region.value}}"{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}})
{{#hasCustomHosts}}
{{#isError}} {{/isError}}_config.hosts = HostsCollection([{{#customHosts}}Host(url='{{host}}', scheme='http', port={{port}}){{^-last}},{{/-last}}{{/customHosts}}])
{{/hasCustomHosts}}
{{#isError}} {{/isError}}self._client = {{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}.create_with_config(config=_config{{#useEchoRequester}}, transporter=EchoTransporter(_config){{/useEchoRequester}})
6 changes: 1 addition & 5 deletions tests/output/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ repository = "https://github.com/algolia/api-clients-automation"
[tool.poetry.dependencies]
python = "3.11.6"
algoliasearch = { path = "../../../clients/algoliasearch-client-python", develop = true }
flake8 = "6.1.0"
autoflake = "2.2.1"
autopep8 = "2.0.4"
black = "24.3.0"
isort = "5.13.0"
ruff = "0.4.9"
pytest = "7.4.3"
python-dotenv = "1.0.0"
pytest-aiohttp = "1.0.5"
Expand Down
Loading