Skip to content

Commit c54fee7

Browse files
authored
Merge pull request #11 from GiacomoPope/use_ruff
Use ruff instead of black in ci
2 parents 3529cab + 87758e5 commit c54fee7

File tree

5 files changed

+31
-45
lines changed

5 files changed

+31
-45
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,23 @@ on:
77
pull_request:
88

99
jobs:
10-
code-format:
10+
lint_check_ruff:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
- uses: astral-sh/ruff-action@v3
1415
with:
15-
fetch-depth: 10
16-
- name: Verify git status
17-
run: |
18-
git status
19-
git remote -v
20-
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v5
16+
version: "latest"
17+
args: "check"
18+
19+
lint_format_ruff:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: astral-sh/ruff-action@v3
2224
with:
23-
python-version: "3.12"
24-
- name: Display Python version
25-
run: python -c "import sys; print(sys.version)"
26-
- name: Display installed python package versions
27-
run: |
28-
pip list || :
29-
- name: Install build dependencies
30-
run: |
31-
pip install -r requirements.txt
32-
- name: Install black
33-
run: |
34-
pip install black==24.4.2
35-
- name: Display installed python package versions
36-
run: |
37-
pip list || :
38-
- name: Check formatting
39-
run: |
40-
black --check .
25+
version: "latest"
26+
args: "format --check"
4127

4228
test:
4329
runs-on: ${{ matrix.os }}

benchmarks/benchmark_dilithium.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def benchmark_dilithium(Dilithium, name, count):
6060
fails += 1
6161

6262
print(f"Keygen median: {round(median(keygen_times), 3)}")
63-
print(f"Sign median: {round(median(sign_times),3)}")
64-
print(f"Sign average: {round(mean(sign_times),3)}")
65-
print(f"Verify median: {round(median(verify_times),3)}")
63+
print(f"Sign median: {round(median(sign_times), 3)}")
64+
print(f"Sign average: {round(mean(sign_times), 3)}")
65+
print(f"Verify median: {round(median(verify_times), 3)}")
6666
print(f"Fails: {fails}")
6767

6868

benchmarks/benchmark_ml_dsa.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def benchmark_ml_dsa(ML_DSA, name, count):
6060
fails += 1
6161

6262
print(f"Keygen median: {round(median(keygen_times), 3)}")
63-
print(f"Sign median: {round(median(sign_times),3)}")
64-
print(f"Sign average: {round(mean(sign_times),3)}")
65-
print(f"Verify median: {round(median(verify_times),3)}")
63+
print(f"Sign median: {round(median(sign_times), 3)}")
64+
print(f"Sign average: {round(mean(sign_times), 3)}")
65+
print(f"Verify median: {round(median(verify_times), 3)}")
6666
print(f"Fails: {fails}")
6767

6868

src/dilithium_py/drbg/aes256_ctr_drbg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, seed: Optional[bytes] = None, personalization: bytes = b""):
3030
self.__ctr_drbg_update(seed_material)
3131
self.reseed_ctr = 1
3232

33-
def __check_entropy_input(self, entropy_input: bytes) -> bytes:
33+
def __check_entropy_input(self, entropy_input: Optional[bytes] = None) -> bytes:
3434
"""
3535
If no entropy given, us os.urandom, else
3636
check that the input is of the right length.

src/dilithium_py/polynomials/polynomials.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ def bit_unpack_w(self, input_bytes, gamma_2):
199199
coefficients = self.__bit_unpack(input_bytes, 6)
200200
# Level 3 and 5 parameter set
201201
else:
202-
assert (
203-
gamma_2 == 261888
204-
), f"Expected gamma_2 to be either (q-1)/88 or (q-1)/32, got {gamma_2 = }"
202+
assert gamma_2 == 261888, (
203+
f"Expected gamma_2 to be either (q-1)/88 or (q-1)/32, got {gamma_2 = }"
204+
)
205205
coefficients = self.__bit_unpack(input_bytes, 4)
206206

207207
return self(coefficients)
@@ -212,9 +212,9 @@ def bit_unpack_z(self, input_bytes, gamma_1):
212212
altered_coeffs = self.__bit_unpack(input_bytes, 18)
213213
# Level 3 and 5 parameter set
214214
else:
215-
assert gamma_1 == (
216-
1 << 19
217-
), f"Expected gamma_1 to be either 2^17 or 2^19, got {gamma_1 = }"
215+
assert gamma_1 == (1 << 19), (
216+
f"Expected gamma_1 to be either 2^17 or 2^19, got {gamma_1 = }"
217+
)
218218
altered_coeffs = self.__bit_unpack(input_bytes, 20)
219219

220220
coefficients = [gamma_1 - c for c in altered_coeffs]
@@ -350,9 +350,9 @@ def bit_pack_w(self, gamma_2):
350350
if gamma_2 == 95232:
351351
return self.__bit_pack(self.coeffs, 6, 192)
352352
# Level 3 and 5 parameter set
353-
assert (
354-
gamma_2 == 261888
355-
), f"Expected gamma_2 to be either (q-1)/88 or (q-1)/32, got {gamma_2 = }"
353+
assert gamma_2 == 261888, (
354+
f"Expected gamma_2 to be either (q-1)/88 or (q-1)/32, got {gamma_2 = }"
355+
)
356356
return self.__bit_pack(self.coeffs, 4, 128)
357357

358358
def bit_pack_z(self, gamma_1):
@@ -361,9 +361,9 @@ def bit_pack_z(self, gamma_1):
361361
if gamma_1 == (1 << 17):
362362
return self.__bit_pack(altered_coeffs, 18, 576)
363363
# Level 3 and 5 parameter set
364-
assert gamma_1 == (
365-
1 << 19
366-
), f"Expected gamma_1 to be either 2^17 or 2^19, got: {gamma_1 = }"
364+
assert gamma_1 == (1 << 19), (
365+
f"Expected gamma_1 to be either 2^17 or 2^19, got: {gamma_1 = }"
366+
)
367367
return self.__bit_pack(altered_coeffs, 20, 640)
368368

369369
def make_hint(self, other, alpha):

0 commit comments

Comments
 (0)