Skip to content

Commit

Permalink
chore: replaced flake8 with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Oct 8, 2023
1 parent ebef7d0 commit 9d01eeb
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 25 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
id: setup-python
Expand All @@ -18,11 +18,12 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
uses: abatilo/actions-poetry@v2

- name: Setup a local virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- name: Load cached virtualenv
id: cached-poetry-dependencies
Expand Down
11 changes: 6 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.275
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/pycqa/flake8
rev: 3.9.2 # pick a git hash / tag to point to
hooks:
- id: flake8
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ name = "fury"
url = "https://pypi.fury.io/skybrush/"
priority = "supplemental"

[tool.ruff]
ignore = ["B905", "C901", "E402", "E501"]
line-length = 80
select = ["B", "C", "E", "F", "W"]

[tool.coverage.paths]
source = ["src"]

Expand Down
3 changes: 2 additions & 1 deletion src/pyledctrl/compiler/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,8 @@ def from_seconds(cls, seconds: float):
"Cannot convert {0} seconds into an integer number of frames "
"at {1} FPS; this could be a problem in the ledctrl output".format(
seconds, cls.FPS
)
),
stacklevel=1,
)

return cls.from_frames(frame_count_as_int)
Expand Down
2 changes: 1 addition & 1 deletion src/pyledctrl/compiler/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def parse_color(string: str) -> Color:
string = string.lower().strip()
return known_colors[string]
except Exception:
raise InvalidColorError(string)
raise InvalidColorError(string) from None


known_colors: Dict[str, Color] = {
Expand Down
2 changes: 1 addition & 1 deletion src/pyledctrl/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def create_optimisation_stage(ast_stage):
)

# Create the optimization stages and the output stages for each AST
for index, ast_stage in enumerate(ast_stages):
for _index, ast_stage in enumerate(ast_stages):
optimisation_stage = create_optimisation_stage(ast_stage)
plan.add_step(optimisation_stage)

Expand Down
2 changes: 1 addition & 1 deletion src/pyledctrl/compiler/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _construct_globals(self) -> Dict[str, Any]:
"set_white": wrapper_for(bytecode.set_white),
"sleep": wrapper_for(bytecode.sleep),
}
aliases = dict(off="set_black", on="set_white", goto="jump")
aliases = {"off": "set_black", "on": "set_white", "goto": "jump"}
for alias, func in aliases.items():
result[alias] = result[func]

Expand Down
2 changes: 1 addition & 1 deletion src/pyledctrl/compiler/stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def _create_output(
try:
input = loads(input)
except Exception:
raise CompilerError("input must be a JSON object")
raise CompilerError("input must be a JSON object") from None

if not isinstance(input, dict):
raise CompilerError("input must be a JSON object")
Expand Down
6 changes: 3 additions & 3 deletions src/pyledctrl/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _execute_LoopBlock(self, node: LoopBlock) -> Iterable[ExecutorState]:
iterator = range(num_iterations)
else:
iterator = count()
for i in iterator:
for _i in iterator:
for state in self._execute(node.body):
yield state

Expand Down Expand Up @@ -325,8 +325,8 @@ def remove_duplicates(events):
"""Given a stream of timestamped events in ascending order, removes
duplicate events that refer to the same time instant, except the last one.
"""
for _, events in groupby(events, attrgetter("timestamp")):
yield last(events)
for _, grouped_events in groupby(events, attrgetter("timestamp")):
yield last(grouped_events)


def unroll(
Expand Down
2 changes: 1 addition & 1 deletion src/pyledctrl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def last(iterable: Iterable[T]) -> T:
ValueError: if the iterable is empty
"""
last = _last_default
for last in iterable:
for last in iterable: # noqa: B007
pass
if last is _last_default:
raise ValueError("iterable is empty")
Expand Down
4 changes: 0 additions & 4 deletions tox.ini

This file was deleted.

0 comments on commit 9d01eeb

Please sign in to comment.