diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c3df7c22b..bc9b78f05 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy` - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.22 + rev: v0.16.1 hooks: - id: ruff-check args: [--fix] diff --git a/deps/methods.py b/deps/methods.py index e75f0d3f5..389204b91 100644 --- a/deps/methods.py +++ b/deps/methods.py @@ -4,24 +4,23 @@ def generate_memory_config_header(target, source, env): header_file_path = Path(str(target[0])) - header = [] - - header.append("// THIS FILE IS GENERATED. EDITS WILL BE LOST.") - header.append("") - - header += """ -// Copyright (C) 2015-2025 Jonathan Müller and foonathan/memory contributors -// SPDX-License-Identifier: Zlib - -#ifndef FOONATHAN_MEMORY_IMPL_IN_CONFIG_HPP -#error "do not include this file directly, use config.hpp" -#endif - -#include - -//=== options ===// -// clang-format off -""".split("\n") + header = [ + "// THIS FILE IS GENERATED. EDITS WILL BE LOST.", + "", + "", + "// Copyright (C) 2015-2025 Jonathan Müller and foonathan/memory contributors", + "// SPDX-License-Identifier: Zlib", + "", + "#ifndef FOONATHAN_MEMORY_IMPL_IN_CONFIG_HPP", + '#error "do not include this file directly, use config.hpp"', + "#endif", + "", + "#include ", + "", + "//=== options ===//", + "// clang-format off", + "", + ] for key, val in env.config_data.items(): if isinstance(val, bool) and val: @@ -40,78 +39,77 @@ def generate_memory_config_header(target, source, env): def generate_memory_container_size_header(target, source, env): header_file_path = Path(str(target[0])) - header = [] - - header.append("// THIS FILE IS GENERATED. EDITS WILL BE LOST.") - header.append("") - - header += """ -namespace detail -{ - template - struct alignment_type - { - using type = void; - static_assert(Alignment == Alignment); - }; - - template <> - struct alignment_type<1> - { - using type = char; - static_assert(alignof(type) == 1); - }; - - template <> - struct alignment_type<2> - { - using type = short; - static_assert(alignof(type) == 2); - }; - - template <> - struct alignment_type<4> - { - using type = int; - static_assert(alignof(type) == 4); - }; - - template <> - struct alignment_type<8> - { - using type = std::conditional_t; - static_assert(alignof(type) == 8); - }; - - template <> - struct alignment_type<16> - { - using type = - std::conditional_t::type>; - }; - - template - using alignment_type_t = alignment_type::type; - - template - static consteval std::size_t calculate_node_size_by_type() - { - static_assert(!std::is_same::value && (sizeof(InitialType) != sizeof(T))); - static_assert(sizeof(T) > sizeof(InitialType)); - - return sizeof(T) - (SubtractTSize ? sizeof(InitialType) : 0); - } - - template - static consteval std::size_t calculate_node_size() - { - return calculate_node_size_by_type, T, SubtractTSize>(); - } - - template - using allocator_type = std::allocator>; -} -""".split("\n") + header = [ + "// THIS FILE IS GENERATED. EDITS WILL BE LOST.", + "", + "", + "namespace detail", + "{", + " template ", + " struct alignment_type", + " {", + " using type = void;", + " static_assert(Alignment == Alignment);", + " };", + "", + " template <>", + " struct alignment_type<1>", + " {", + " using type = char;", + " static_assert(alignof(type) == 1);", + " };", + "", + " template <>", + " struct alignment_type<2>", + " {", + " using type = short;", + " static_assert(alignof(type) == 2);", + " };", + "", + " template <>", + " struct alignment_type<4>", + " {", + " using type = int;", + " static_assert(alignof(type) == 4);", + " };", + "", + " template <>", + " struct alignment_type<8>", + " {", + " using type = std::conditional_t;", + " static_assert(alignof(type) == 8);", + " };", + "", + " template <>", + " struct alignment_type<16>", + " {", + " using type =", + " std::conditional_t::type>;", + " };", + "", + " template ", + " using alignment_type_t = alignment_type::type;", + "", + " template ", + " static consteval std::size_t calculate_node_size_by_type()", + " {", + " static_assert(!std::is_same::value && (sizeof(InitialType) != sizeof(T)));", + " static_assert(sizeof(T) > sizeof(InitialType));", + "", + " return sizeof(T) - (SubtractTSize ? sizeof(InitialType) : 0);", + " }", + "", + " template ", + " static consteval std::size_t calculate_node_size()", + " {", + " return calculate_node_size_by_type, T, SubtractTSize>();", + " }", + "", + " template ", + " using allocator_type = std::allocator>;", + "}", + "", + ] containers = { "forward_list": [ diff --git a/misc/scripts/exp_lut_generator.py b/misc/scripts/exp_lut_generator.py index 05800fe9c..3d8c13d0e 100755 --- a/misc/scripts/exp_lut_generator.py +++ b/misc/scripts/exp_lut_generator.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import decimal import os +import sys from argparse import ArgumentParser from math import e -from typing import List BIT_COUNT = 64 MAX_VALUE = 2**BIT_COUNT @@ -16,17 +16,17 @@ def generate_exp_lut(divisor_base: int, divisor_power: int, exp_base: decimal.Decimal): divisor: int = divisor_base**divisor_power - exp_lut: List[int] = [] + exp_lut: list[int] = [] for index in range(BIT_COUNT): exponent: decimal.Decimal = (2**index) / divisor - value: int = int(decimal.Decimal(exp_base**exponent) * decimal.Decimal(divisor) + decimal.Decimal(0.5)) + value: int = int(decimal.Decimal(exp_base**exponent) * decimal.Decimal(divisor) + decimal.Decimal("0.5")) if value > MAX_VALUE: break exp_lut.append(value) lut_identifier: str = ( - f"{divisor_base}_{divisor_power}_EXP_{'e' if exp_base == e else ('%g' % exp_base).replace('.', 'p')}" + f"{divisor_base}_{divisor_power}_EXP_{'e' if exp_base == e else f'{exp_base:g}'.replace('.', 'p')}" ) lut_size: int = len(exp_lut) @@ -115,4 +115,4 @@ def generate_exp_lut(divisor_base: int, divisor_power: int, exp_base: decimal.De args = parser.parse_args() generate_exp_lut(args.base, args.power, args.exp) - exit(0) + sys.exit(0) diff --git a/misc/scripts/sin_lut_generator.py b/misc/scripts/sin_lut_generator.py index 35e65e45d..7e40fb995 100755 --- a/misc/scripts/sin_lut_generator.py +++ b/misc/scripts/sin_lut_generator.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import decimal import os +import sys from argparse import ArgumentParser DEFAULT_PRECISION = 16 @@ -71,7 +72,7 @@ def generate_sin_lut(precision: int, count_log2: int): sin_value: decimal.Decimal = decimal_sin(angle) # sin(angle) moved_sin: decimal.Decimal = sin_value * one rounded_sin: int = ( - int(moved_sin + decimal.Decimal(0.5)) if moved_sin > 0 else int(moved_sin - decimal.Decimal(0.5)) + int(moved_sin + decimal.Decimal("0.5")) if moved_sin > 0 else int(moved_sin - decimal.Decimal("0.5")) ) SinLut.append(rounded_sin) @@ -149,7 +150,7 @@ def generate_sin_lut(precision: int, count_log2: int): if args.precision < args.count: print("ERROR: invalid count ", args.count, " - can't be greater than precision (", args.precision, ")") - exit(-1) + sys.exit(-1) else: generate_sin_lut(args.precision, args.count) - exit(0) + sys.exit(0)