Skip to content

Commit 74ec2eb

Browse files
committed
Change code formatter to ruff
1 parent b53f223 commit 74ec2eb

8 files changed

+81
-148
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ The explanation below is copied from
110110
codebase is little more than a translation of that implementation:
111111
112112
> The following optimizations and variations on FastCDC are involved in the chunking algorithm:
113-
> * 31 bit integers to avoid 64 bit integers for the sake of the Javascript reference implementation.
113+
> * 31 bit integers to avoid 64-bit integers for the sake of the Javascript reference implementation.
114114
> * A right shift instead of a left shift to remove the need for an additional modulus operator, which would otherwise have been necessary to prevent overflow.
115115
> * Masks are no longer zero-padded since a right shift is used instead of a left shift.
116116
> * A more adaptive threshold based on a combination of average and minimum chunk size (rather than just average chunk size) to decide the pivot point at which to switch masks. A larger minimum chunk size now switches from the strict mask to the eager mask earlier.

build.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
The shared library can also be built manually using the command:
44
$ cythonize -X language_level=3 -a -i ./fastcdc/fastcdc_cy.pyx
55
"""
6+
67
from distutils.command.build_ext import build_ext
78

89

fastcdc/fastcdc_py.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def chunk_generator(stream, min_size, avg_size, max_size, fat, hf):
2525
read_size = max(1024 * 64, max_size)
2626
offset = 0
2727
while offset < len(stream):
28-
blob = stream[offset:offset + read_size]
28+
blob = stream[offset : offset + read_size]
2929
cp = cdc_offset(blob, min_size, avg_size, max_size, cs, mask_s, mask_l)
30-
raw = bytes(blob[:cp]) if fat else b''
31-
h = hf(blob[:cp]).hexdigest() if hf else ''
30+
raw = bytes(blob[:cp]) if fat else b""
31+
h = hf(blob[:cp]).hexdigest() if hf else ""
3232
yield Chunk(offset, cp, raw, h)
3333
offset += cp
3434

@@ -87,7 +87,7 @@ def center_size(average, minimum, source_size):
8787

8888

8989
def mask(bits):
90-
return 2 ** bits - 1
90+
return 2**bits - 1
9191

9292

9393
########################################################################################

fastcdc/original.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
True to the original port of https://github.com/nlfiedler/fastcdc-rs
44
"""
5+
56
import os
67
from dataclasses import dataclass
78
from mmap import mmap, ACCESS_READ
@@ -26,7 +27,6 @@ class Chunk:
2627

2728
@dataclass
2829
class FastCDC:
29-
3030
source: Union[ByteString, BinaryIO, Text]
3131
bytes_processed: int
3232
bytes_remaining: int

fastcdc/scan.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010

1111
@click.command(cls=DefaultHelp)
1212
@click.argument(
13-
"paths", type=click.Path(exists=True, file_okay=False, resolve_path=True), nargs=-1,
13+
"paths",
14+
type=click.Path(exists=True, file_okay=False, resolve_path=True),
15+
nargs=-1,
1416
)
1517
@click.option(
16-
"-r", "--recursive", help="Scan directory tree recursively.", is_flag=True,
18+
"-r",
19+
"--recursive",
20+
help="Scan directory tree recursively.",
21+
is_flag=True,
1722
)
1823
@click.option(
1924
"-s",

fastcdc/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def logarithm2(value: int) -> int:
3131
def mask(bits: int) -> int:
3232
assert bits >= 1
3333
assert bits <= 31
34-
return 2 ** bits - 1
34+
return 2**bits - 1
3535

3636

3737
class DefaultHelp(click.Command):
@@ -87,12 +87,12 @@ def iter_files(path, recursive=False):
8787
def get_memoryview(data):
8888
# Handle file path string and Path object
8989
if isinstance(data, (str, Path)):
90-
with open(data, 'rb') as f:
90+
with open(data, "rb") as f:
9191
mm = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
9292
return memoryview(mm)
9393

9494
# Handle file object opened in 'rb' mode
95-
if hasattr(data, 'fileno'):
95+
if hasattr(data, "fileno"):
9696
mm = mmap.mmap(data.fileno(), 0, access=mmap.ACCESS_READ)
9797
return memoryview(mm)
9898

poetry.lock

+49-134
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+15-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,23 @@ blake3 = { version = "^0.3", optional = true }
4343
[tool.poetry.extras]
4444
hashes = ["xxhash", "blake3"]
4545

46-
[tool.poetry.dev-dependencies]
47-
pytest = "*"
48-
black = "*"
46+
[tool.poetry.group.dev.dependencies]
4947
cython = "*"
48+
pytest = "*"
5049
pytest-benchmark = "*"
50+
poethepoet = "*"
51+
ruff = "*"
52+
53+
[tool.ruff]
54+
line-length = 88
55+
56+
[tool.ruff.format]
57+
line-ending = "lf"
58+
59+
[tool.poe.tasks]
60+
format-code = { cmd = "poetry run ruff format", help = "Code style formating with ruff" }
61+
test = { cmd = "poetry run pytest", help = "Run tests" }
62+
all = ["format-code", "test"]
5163

5264
[tool.poetry.build]
5365
generate-setup-file = true

0 commit comments

Comments
 (0)