From 514d3c6bcd8615e3d521f8d59a089dece4d3b0d1 Mon Sep 17 00:00:00 2001 From: Vishal Pankaj Chandratreya <19171016+tfpf@users.noreply.github.com> Date: Thu, 25 Apr 2024 22:00:09 +0530 Subject: [PATCH] Formatted Python code using Ruff. (#16) Also formatted C code in the README using Clang formatter. --- README.md | 5 +++-- benchmarks/benchmarks.py | 7 ++++--- examples/Python/thread-safe.py | 4 ++-- setup.py | 24 +++++++++++++----------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index fed7e1b..c8484e0 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,11 @@ Put the following code in a file `example.c`: #include #include -int main(void) +int +main(void) { hdrbg_init(0); - for(int i = 0; i < 10; ++i) + for (int i = 0; i < 10; ++i) { long long unsigned r = hdrbg_rand(NULL); printf("%llu\n", r); diff --git a/benchmarks/benchmarks.py b/benchmarks/benchmarks.py index 45378f0..6b6f937 100755 --- a/benchmarks/benchmarks.py +++ b/benchmarks/benchmarks.py @@ -1,10 +1,11 @@ #! /usr/bin/env python3 import math -import hdrbg import time import timeit +import hdrbg + def benchmark(stmt, number, passes=32): delay = math.inf @@ -12,7 +13,7 @@ def benchmark(stmt, number, passes=32): delay_ = timeit.timeit(stmt=stmt, number=number, timer=time.perf_counter_ns) delay = min(delay, delay_) result = delay / number / 1000 - print(f'{stmt.__name__:>20} {result:8.2f} µs') + print(f"{stmt.__name__:>20} {result:8.2f} µs") def main(): @@ -23,5 +24,5 @@ def main(): benchmark(hdrbg.real, 800) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/examples/Python/thread-safe.py b/examples/Python/thread-safe.py index 9c004f5..83a3126 100755 --- a/examples/Python/thread-safe.py +++ b/examples/Python/thread-safe.py @@ -5,7 +5,7 @@ print(hdrbg.fill(64).hex()) for _ in range(4): - print(hdrbg.rand(), end=' ') + print(hdrbg.rand(), end=" ") for _ in range(4): - print(hdrbg.real(), end=' ') + print(hdrbg.real(), end=" ") print() diff --git a/setup.py b/setup.py index f92f49e..6f83162 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,15 @@ -from setuptools import Extension, find_packages, setup +from setuptools import Extension, setup -ext_modules = [Extension( - name='hdrbg', - sources=['lib/pyhdrbg.c', 'lib/hdrbg.c', 'lib/sha256.c', 'lib/extras.c'], - include_dirs=['include'], - py_limited_api=True, -)] -kwargs = dict( - package_dir={'': 'lib'}, - ext_modules=ext_modules, -) +ext_modules = [ + Extension( + name="hdrbg", + sources=["lib/pyhdrbg.c", "lib/hdrbg.c", "lib/sha256.c", "lib/extras.c"], + include_dirs=["include"], + py_limited_api=True, + ) +] +kwargs = { + "package_dir": {"": "lib"}, + "ext_modules": ext_modules, +} setup(**kwargs)