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: Drop black and use ruff format #473

Merged
merged 1 commit into from
Nov 29, 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
4 changes: 2 additions & 2 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ jobs:
- name: Run mypy
run: |
poetry run mypy src tests
- name: Run black
- name: Run ruff format
run: |
poetry run black --check --verbose src tests
poetry run ruff format --check src tests
- name: Run reuse lint
run: |
poetry run reuse lint
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ zipapp:
lint:
mypy src tests
ruff check src tests
black --check src tests
ruff format --check src tests
reuse lint

.PHONY: fmt
fmt:
ruff check --fix-only src tests
black src tests
ruff format src tests

.PHONY: docs
docs:
Expand Down
779 changes: 392 additions & 387 deletions poetry.lock

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ exitcode = "^0.1.0"
psutil = "^5.9.4"

[tool.poetry.group.dev.dependencies]
black = ">=22.10,<24.0"
Sphinx = ">=5.2,<8.0"
mypy = "^1.0"
pylsp-mypy = "^0.6"
pylsp-rope = "^0.1"
pytest = "^7.1"
pytest-asyncio = ">=0.20,<0.22"
python-lsp-black = "^1.1"
python-lsp-server = "^1.5"
types-aiofiles = "^23.1"
types-psutil = "^5.9.5.10"
Expand All @@ -69,7 +67,7 @@ reuse = ">=1,<3"
construct-typing = ">=0.5.2,<0.7.0"
pytest-cov = "^4.0"
ruff = "^0.1.0"
python-lsp-ruff = "^1.1.0"
python-lsp-ruff = "^1.6.0"

[tool.poetry.scripts]
"gallia" = "gallia.cli:main"
Expand All @@ -92,6 +90,8 @@ ignore_missing_imports = true

[tool.ruff]
target-version = "py310"

[tool.ruff.lint]
select = [
# TODO: Enable this
# "B", # flake8-bugbear
Expand All @@ -113,8 +113,5 @@ ignore = [
"PLC1901", # empty string is falsey
]

[tool.black]
target-version = ['py310']

[tool.pytest.ini_options]
asyncio_mode = "auto"
4 changes: 3 additions & 1 deletion src/gallia/commands/discover/doip.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ async def enumerate_target_addresses( # noqa: PLR0913

except (ConnectionError, ConnectionResetError) as e:
# Whenever this triggers, but sometimes connections are closed not by us
logger.warn(f"[🫦] Sexy, but unexpected: {target_addr:#x} triggered {e}")
logger.warn(
f"[🫦] Sexy, but unexpected: {target_addr:#x} triggered {e}"
)
async with aiofiles.open(
self.artifacts_dir.joinpath("7_targets_with_errors.txt"), "a"
) as f:
Expand Down
16 changes: 8 additions & 8 deletions src/gallia/services/uds/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ async def read_dtc_information_report_mirror_memory_dtc_by_status_mask(
dtc_status_mask: int,
suppress_response: bool = False,
config: UDSRequestConfig | None = None,
) -> (service.NegativeResponse | service.ReportMirrorMemoryDTCByStatusMaskResponse):
) -> service.NegativeResponse | service.ReportMirrorMemoryDTCByStatusMaskResponse:
"""Read DTCs and their state from the UDS server's mirror memory.
This is an implementation of the UDS request for the reportMirrorMemoryDTCByStatusMask
sub-function of the
Expand Down Expand Up @@ -600,7 +600,7 @@ async def input_output_control_by_identifier(
control_option_record: bytes,
control_enable_mask_record: bytes = b"",
config: UDSRequestConfig | None = None,
) -> (service.NegativeResponse | service.InputOutputControlByIdentifierResponse):
) -> service.NegativeResponse | service.InputOutputControlByIdentifierResponse:
"""Controls input or output values on the server.
This is an implementation of the UDS request for the service InputOutputControlByIdentifier
(0x2F).
Expand Down Expand Up @@ -636,7 +636,7 @@ async def input_output_control_by_identifier_return_control_to_ecu(
data_identifier: int,
control_enable_mask_record: bytes = b"",
config: UDSRequestConfig | None = None,
) -> (service.NegativeResponse | service.InputOutputControlByIdentifierResponse):
) -> service.NegativeResponse | service.InputOutputControlByIdentifierResponse:
"""Gives the control over input / output parameters back to the ECU.
This is a convenience wrapper for the generic input_output_control_by_id() for the case
where an inputOutputControlParameter is used and is set to returnControlToECU.
Expand All @@ -662,7 +662,7 @@ async def input_output_control_by_identifier_reset_to_default(
data_identifier: int,
control_enable_mask_record: bytes = b"",
config: UDSRequestConfig | None = None,
) -> (service.NegativeResponse | service.InputOutputControlByIdentifierResponse):
) -> service.NegativeResponse | service.InputOutputControlByIdentifierResponse:
"""Sets the input / output parameters to the default value(s).
This is a convenience wrapper of the generic request for the case where an
inputOutputControlParameter is used and is set to resetToDefault.
Expand All @@ -686,7 +686,7 @@ async def input_output_control_by_identifier_freeze_current_state(
data_identifier: int,
control_enable_mask_record: bytes = b"",
config: UDSRequestConfig | None = None,
) -> (service.NegativeResponse | service.InputOutputControlByIdentifierResponse):
) -> service.NegativeResponse | service.InputOutputControlByIdentifierResponse:
"""Freezes the input / output parameters at their current state.
This is a convenience wrapper of the generic request for the case where an
inputOutputControlParameter is used and is set to freezeCurrentState.
Expand All @@ -712,7 +712,7 @@ async def input_output_control_by_identifier_short_term_adjustment(
control_states: bytes,
control_enable_mask_record: bytes = b"",
config: UDSRequestConfig | None = None,
) -> (service.NegativeResponse | service.InputOutputControlByIdentifierResponse):
) -> service.NegativeResponse | service.InputOutputControlByIdentifierResponse:
"""Sets the input / output parameters as specified in the controlOptionRecord.
This is a convenience wrapper of the generic request for the case
where an inputOutputControlParameter is used and is set to freezeCurrentState.
Expand Down Expand Up @@ -1040,7 +1040,7 @@ async def request(
self,
request: service.ReportMirrorMemoryDTCByStatusMaskRequest,
config: UDSRequestConfig | None = None,
) -> (service.NegativeResponse | service.ReportMirrorMemoryDTCByStatusMaskResponse):
) -> service.NegativeResponse | service.ReportMirrorMemoryDTCByStatusMaskResponse:
...

@overload
Expand Down Expand Up @@ -1081,7 +1081,7 @@ async def request(
self,
request: service.InputOutputControlByIdentifierRequest,
config: UDSRequestConfig | None = None,
) -> (service.NegativeResponse | service.InputOutputControlByIdentifierResponse):
) -> service.NegativeResponse | service.InputOutputControlByIdentifierResponse:
...

@overload
Expand Down
8 changes: 6 additions & 2 deletions src/gallia/services/uds/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ def randomize(self) -> None:
p_transition = self.p_session / len(level_sessions) / 2 ** (level + 0.5)
next_level_sessions = set()
available_sessions = [
i for i, l in enumerate(session_transitions) if len(l) > 0 # noqa: E741
i
for i, l in enumerate(session_transitions) # noqa: E741
if len(l) > 0
]

for session in level_sessions:
Expand Down Expand Up @@ -662,7 +664,9 @@ def input_output_control_by_identifier(
request.service_id, UDSErrorCodes.incorrectMessageLengthOrInvalidFormat
)

return request.RESPONSE_TYPE(request.data_identifier, rng.random_payload(min_len=1)) # type: ignore
return request.RESPONSE_TYPE(
request.data_identifier, rng.random_payload(min_len=1)
) # type: ignore

def clear_diagnostic_information(
self, request: service.ClearDiagnosticInformationRequest
Expand Down
Loading