Skip to content

Commit

Permalink
chore: move to Ruff-format (#2777)
Browse files Browse the repository at this point in the history
* chore: move to Ruff-format

Signed-off-by: Henry Schreiner <[email protected]>

* chore: Ruff 0.1.3

Signed-off-by: Henry Schreiner <[email protected]>

---------

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 27, 2023
1 parent 74c18c1 commit a79b9ad
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 46 deletions.
16 changes: 2 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ repos:
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude_types: [svg]
- id: mixed-line-ending
Expand All @@ -21,22 +20,18 @@ repos:
- id: name-tests-test
args: ["--pytest-test-first"]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.0
hooks:
- id: black

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies: [pyyaml]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.2
rev: v0.1.3
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
Expand Down Expand Up @@ -66,13 +61,6 @@ repos:
types: [file, python]
files: ^tests/


- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.0
hooks:
Expand Down
4 changes: 1 addition & 3 deletions dev/generate-kernel-signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,7 @@ def f(grid, block, args):
file.write(
""" f.dir = [{}]
out[{}] = f
""".format(
", ".join(dirlist), ", ".join(special)
)
""".format(", ".join(dirlist), ", ".join(special))
)
else:
file.write(
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ ignore_errors = true
ignore_missing_imports = true

[tool.ruff]
typing-modules = ["awkward._typing"]
src = ["src"]
extend-exclude = [
"studies",
Expand All @@ -266,9 +265,9 @@ extend-exclude = [
"docs-*",
"src/awkward/_typeparser/generated_parser.py",
]

[tool.ruff.lint]
select = [
"E", "F", "W", # flake8
extend-select = [
"B", "B904", # flake8-bugbear
"I", # isort
"C4", # flake8-comprehensions
Expand All @@ -294,11 +293,13 @@ ignore = [
"PLW2901", # Outer for loop variable overwritten by inner assignment target
"PLW0603", # Using the global statement to update is discouraged
"PLC1901", # x == "" can be simplified to not x (empty string is falsey)
"ISC001", # Conflicts with the formatter in 0.1.2
]
unfixable = [
"T20", # Removes print statements
"F841", # Removes unused variables
]
typing-modules = ["awkward._typing"]
external = []
mccabe.max-complexity = 100

Expand Down
4 changes: 1 addition & 3 deletions src/awkward/_connect/numba/arrayview.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,7 @@ def add_statement(indent, name, arraytype, is_array):
"""
def contains_impl(obj, element):
{}
return False""".format(
"\n ".join(statements)
),
return False""".format("\n ".join(statements)),
"contains_impl",
)

Expand Down
7 changes: 4 additions & 3 deletions src/awkward/contents/regulararray.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ def _getitem_range(self, start: SupportsIndex, stop: IndexType) -> Content:
return self

zeros_length = index_nplike.index_as_shape_item(stop - start)
substart, substop = start * index_nplike.shape_item_as_index(
self._size
), stop * index_nplike.shape_item_as_index(self._size)
substart, substop = (
start * index_nplike.shape_item_as_index(self._size),
stop * index_nplike.shape_item_as_index(self._size),
)
return RegularArray(
self._content._getitem_range(substart, substop),
self._size,
Expand Down
6 changes: 2 additions & 4 deletions src/awkward/operations/ak_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def concatenate(arrays, axis=0, *, mergebool=True, highlevel=True, behavior=None
# Dispatch
if (
# Is an array with a known backend
backend_of(arrays, default=None)
is not None
backend_of(arrays, default=None) is not None
):
yield (arrays,)
else:
Expand All @@ -61,8 +60,7 @@ def _impl(arrays, axis, mergebool, highlevel, behavior):
# Simple single-array, axis=0 fast-path
if (
# Is an array with a known backend
backend_of(arrays, default=None)
is not None
backend_of(arrays, default=None) is not None
):
# Convert the array to a layout object
content = ak.operations.to_layout(
Expand Down
26 changes: 10 additions & 16 deletions tests/test_2682_custom_pickler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,19 @@ def test_default_pickler():


def test_noop_pickler(tmp_path):
assert (
pickle_complex_array_and_return_form(
"""
assert pickle_complex_array_and_return_form(
"""
def plugin(obj, protocol: int):
return NotImplemented""",
tmp_path,
)
== ak.forms.from_dict(
{"class": "ListOffsetArray", "offsets": "i64", "content": "int64"}
)
tmp_path,
) == ak.forms.from_dict(
{"class": "ListOffsetArray", "offsets": "i64", "content": "int64"}
)


def test_non_packing_pickler(tmp_path):
assert (
pickle_complex_array_and_return_form(
"""
assert pickle_complex_array_and_return_form(
"""
def plugin(obj, protocol):
import awkward as ak
if isinstance(obj, ak.Array):
Expand All @@ -92,11 +88,9 @@ def plugin(obj, protocol):
)
else:
return NotImplemented""",
tmp_path,
)
== ak.forms.from_dict(
{"class": "ListArray", "starts": "i64", "stops": "i64", "content": "int64"}
)
tmp_path,
) == ak.forms.from_dict(
{"class": "ListArray", "starts": "i64", "stops": "i64", "content": "int64"}
)


Expand Down

0 comments on commit a79b9ad

Please sign in to comment.