Sync from SUSE:SLFO:Main python-fastnumbers revision c571156d9c103080dc47fbb835674641

This commit is contained in:
2025-03-28 16:38:19 +01:00
parent 9edaf45be6
commit ba39deaa67
3 changed files with 123 additions and 5 deletions

110
fix-compiler-errors.patch Normal file
View File

@@ -0,0 +1,110 @@
From 5522116cd03a14e72caee50e64902df7b5543028 Mon Sep 17 00:00:00 2001
From: Seth Morton <seth.m.morton@gmail.com>
Date: Mon, 21 Oct 2024 21:55:42 -0700
Subject: [PATCH] Update CI configuration
---
dev/formatting.py | 2 +-
include/fastnumbers/third_party/ipow.hpp | 6 ++++--
setup.py | 8 ++++++++
src/cpp/parser.cpp | 3 +++
tox.ini | 13 +++++++++++--
5 files changed, 27 insertions(+), 5 deletions(-)
--- a/dev/formatting.py
+++ b/dev/formatting.py
@@ -52,6 +52,6 @@ any_cpp_formatting = any(
# "Roll up" what happened into a single exit code.
all_return_zero = all(ret.returncode == 0 for ret in [black_ret, clang_format_ret])
if any_cpp_formatting or not all_return_zero:
- sys.exit("Not all files are formatted correctly. Run 'tox -e format'.")
+ sys.exit("Not all files are formatted correctly. Run 'tox run -e format'.")
else:
sys.exit(0)
--- a/include/fastnumbers/third_party/ipow.hpp
+++ b/include/fastnumbers/third_party/ipow.hpp
@@ -58,8 +58,10 @@ inline T1 ipow(T1 base, T2 exp) {
return 1;
}
- if (base == -1) {
- return 1 - 2 * (exp & 1);
+ if constexpr(std::is_signed_v<T1>) {
+ if (base == -1) {
+ return 1 - 2 * (exp & 1);
+ }
}
return 0;
--- a/setup.py
+++ b/setup.py
@@ -9,6 +9,7 @@ from setuptools import Extension, find_p
# Compilation arguments are platform-dependent
+link_args = ["-lm"]
if sys.platform == "win32":
compile_args = [
"/std:c++17",
@@ -19,6 +20,8 @@ if sys.platform == "win32":
if "FN_DEBUG" in os.environ or "FN_COV" in os.environ:
compile_args.append("/Od")
compile_args.append("/Z7")
+ if "FN_WARNINGS_AS_ERRORS" in os.environ:
+ compile_args.append("/WX")
else:
compile_args = [
"-std=c++17",
@@ -31,6 +34,11 @@ else:
if "FN_DEBUG" in os.environ or "FN_COV" in os.environ:
compile_args.append("-Og")
compile_args.append("-g")
+ if "FN_COV" in os.environ:
+ compile_args.append("--coverage")
+ link_args.append("--coverage")
+ if "FN_WARNINGS_AS_ERRORS" in os.environ:
+ compile_args.append("-Werror")
ext = [
--- a/src/cpp/parser.cpp
+++ b/src/cpp/parser.cpp
@@ -460,4 +460,7 @@ NumberFlags CharacterParser::get_number_
case StringType::INTLIKE_FLOAT:
return flag_wrap(NumberType::Float | NumberType::IntLike);
}
+
+ /* Is not reachable, but silences compiler warnings. */
+ return NumberType::INVALID;
}
--- a/tox.ini
+++ b/tox.ini
@@ -4,10 +4,11 @@
# and then run "tox" from this directory.
[tox]
-envlist = py37, py38, py39, py310, py311, py12
+envlist = lint, mypy, py37, py38, py39, py310, py311, py12
# Other valid environments are:
# format
-# format-check
+# lint
+# mypy
# docs
# bump
# clean
@@ -50,6 +51,14 @@ deps =
clang-format
commands = {envpython} dev/formatting.py
+# Check code quality.
+[testenv:lint]
+setenv =
+ FN_WARNINGS_AS_ERRORS=1
+deps =
+ ruff
+ clang-format
+
# Type checking
[testenv:mypy]
deps =

View File

@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Nov 22 18:57:14 UTC 2024 - Matej Cepl <mcepl@cepl.eu>
- Add fix-compiler-errors.patch with upstream fixes for compiler
errors.
- Use %pytest_arch instead of home made calling of pytest.
-------------------------------------------------------------------
Fri Dec 29 18:35:47 UTC 2023 - Dirk Müller <dmueller@suse.com>

View File

@@ -1,7 +1,7 @@
#
# spec file for package python-fastnumbers
#
# Copyright (c) 2023 SUSE LLC
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -24,6 +24,9 @@ Summary: Drop-in replacement for Python's int and float
License: MIT
URL: https://github.com/SethMMorton/fastnumbers
Source: https://files.pythonhosted.org/packages/source/f/fastnumbers/fastnumbers-%{version}.tar.gz
# PATCH-FIX-UPSTREAM fix-compiler-errors.patch mcepl@suse.com
# Code from gh#SethMMorton/fastnumbers@5522116cd03a and gh#SethMMorton/fastnumbers@8d2104e5cd93
Patch0: fix-compiler-errors.patch
BuildRequires: %{python_module devel}
BuildRequires: %{python_module pip}
BuildRequires: %{python_module typing-extensions}
@@ -58,7 +61,7 @@ fastnumbers is a Python module with three objectives:
an input could be converted to int or float.
%prep
%setup -q -n fastnumbers-%{version}
%autosetup -p1 -n fastnumbers-%{version}
%build
%if 0%{?suse_version} <= 1500
@@ -73,9 +76,7 @@ export CFLAGS="%{optflags} -Wno-error=return-type"
%python_expand %fdupes %{buildroot}%{$python_sitearch}
%check
%{python_expand export PYTHONPATH=%{buildroot}%{$python_sitearch}
pytest-%{$python_bin_suffix}
}
%pytest_arch
%files %{python_files}
%doc README.rst