Skip to content

chore: Switch from Black to Ruff for formatting #887

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

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .changeset/switch_from_black_to_ruff_for_formatting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
default: major
---

# Switch from Black to Ruff for formatting

`black` is no longer a runtime dependency, so if you have them set in custom `post_hooks` in a config file, you'll need to make sure they're being installed manually. [`ruff`](https://docs.astral.sh/ruff) is now installed and used by default instead.
6 changes: 3 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ jobs:
- name: Install Dependencies
run: poetry install

- name: Run Black
run: poetry run black . --check
- name: Check formatting
run: poetry run ruff format . --check

- name: Run safety
run: poetry export -f requirements.txt | poetry run safety check --bare --stdin

- name: Run mypy
run: poetry run mypy --show-error-codes openapi_python_client

- name: Run Ruff
- name: Lint
run: poetry run ruff check .

- name: Run pytest
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[![codecov](https://codecov.io/gh/openapi-generators/openapi-python-client/branch/main/graph/badge.svg)](https://codecov.io/gh/triaxtec/openapi-python-client)
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)
[![Generic badge](https://img.shields.io/badge/type_checked-mypy-informational.svg)](https://mypy.readthedocs.io/en/stable/introduction.html)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![PyPI version shields.io](https://img.shields.io/pypi/v/openapi-python-client.svg)](https://pypi.python.org/pypi/openapi-python-client/)
[![Downloads](https://static.pepy.tech/personalized-badge/openapi-python-client?period=total&units=international_system&left_color=blue&right_color=green&left_text=Downloads)](https://pepy.tech/project/openapi-python-client)

Expand Down Expand Up @@ -156,7 +155,7 @@ In the config file, there's an easy way to tell `openapi-python-client` to run a
```yaml
post_hooks:
- "ruff check . --fix"
- "black ."
- "ruff format ."
```

### use_path_prefixes_for_title_model_names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def _parse_not_required_one_of_models(data: object) -> Union["FreeFormModel", "M
not_required_one_of_models = _parse_not_required_one_of_models(d.pop("not_required_one_of_models", UNSET))

def _parse_not_required_nullable_one_of_models(
data: object,
data: object
) -> Union["FreeFormModel", "ModelWithUnionProperty", None, Unset, str]:
if data is None:
return data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def to_dict(self) -> Dict[str, Any]:
for (
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_b_item_data
) in prop:
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_b_item = (
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_b_item_data.to_dict()
)
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_b_item = componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_b_item_data.to_dict()

field_dict[prop_name].append(
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_b_item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def to_dict(self) -> Dict[str, Any]:
for (
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_a_item_data
) in prop:
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_a_item = (
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_a_item_data.to_dict()
)
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_a_item = componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_a_item_data.to_dict()

field_dict[prop_name].append(
componentsschemas_an_array_with_a_circular_ref_in_items_object_additional_properties_a_item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def to_dict(self) -> Dict[str, Any]:
for prop_name, prop in self.additional_properties.items():
field_dict[prop_name] = []
for componentsschemas_an_array_with_a_recursive_ref_in_items_object_additional_properties_item_data in prop:
componentsschemas_an_array_with_a_recursive_ref_in_items_object_additional_properties_item = (
componentsschemas_an_array_with_a_recursive_ref_in_items_object_additional_properties_item_data.to_dict()
)
componentsschemas_an_array_with_a_recursive_ref_in_items_object_additional_properties_item = componentsschemas_an_array_with_a_recursive_ref_in_items_object_additional_properties_item_data.to_dict()

field_dict[prop_name].append(
componentsschemas_an_array_with_a_recursive_ref_in_items_object_additional_properties_item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
for prop_name, prop_dict in d.items():

def _parse_additional_property(
data: object,
data: object
) -> Union["ModelWithAnyJsonPropertiesAdditionalPropertyType0", List[str], bool, float, int, str]:
try:
if not isinstance(data, dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()

def _parse_fruit(
data: object,
data: object
) -> Union["ModelWithUnionPropertyInlinedFruitType0", "ModelWithUnionPropertyInlinedFruitType1", Unset]:
if isinstance(data, Unset):
return data
Expand Down
13 changes: 0 additions & 13 deletions end_to_end_tests/golden-record/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ python-dateutil = "^2.8.0"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 120
target_version = ['py38', 'py39', 'py310', 'py311']
exclude = '''
(
/(
| \.git
| \.venv
| \.mypy_cache
)/
)
'''

[tool.ruff]
select = ["F", "I"]
line-length = 120
13 changes: 0 additions & 13 deletions integration-tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ pytest-asyncio = "^0.21.0"
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"

[tool.black]
line-length = 120
target_version = ['py38', 'py39', 'py310', 'py311']
exclude = '''
(
/(
| \.git
| \.venv
| \.mypy_cache
)/
)
'''

[tool.ruff]
select = ["F", "I"]
line-length = 120
2 changes: 1 addition & 1 deletion openapi_python_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Config(BaseModel):
use_path_prefixes_for_title_model_names: bool = True
post_hooks: List[str] = [
"ruff check --fix .",
"black .",
"ruff format .",
]
field_prefix: str = "field_"
http_timeout: int = 5
Expand Down
13 changes: 0 additions & 13 deletions openapi_python_client/templates/pyproject_no_poetry.toml.jinja
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
[tool.black]
line-length = 120
target_version = ['py38', 'py39', 'py310', 'py311']
exclude = '''
(
/(
| \.git
| \.venv
| \.mypy_cache
)/
)
'''

[tool.ruff]
select = ["F", "I"]
line-length = 120
Loading