From 310091e8bb77485f1a01609162b805b1052a17a3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:41:21 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pyproject.toml | 2 +- python/CMakeLists.txt | 17 ++++++------- python/src/units_python.cpp | 49 +++++++++++++++++++++++++++---------- python/tests/test_units.py | 10 ++++---- 4 files changed, 50 insertions(+), 28 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bbb56ded..cf0323e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,4 +44,4 @@ test-requires = "pytest" # Needed for full C++17 support [tool.cibuildwheel.macos.environment] -MACOSX_DEPLOYMENT_TARGET = "10.14" \ No newline at end of file +MACOSX_DEPLOYMENT_TARGET = "10.14" diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0be06449..ce2753f1 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,7 +1,11 @@ cmake_minimum_required(VERSION 3.22...3.31) project(llnl-units LANGUAGES CXX) -find_package(Python 3.10 REQUIRED COMPONENTS Interpreter Development.Module OPTIONAL_COMPONENTS Development.SABIModule) +find_package( + Python 3.10 REQUIRED + COMPONENTS Interpreter Development.Module + OPTIONAL_COMPONENTS Development.SABIModule +) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE @@ -16,20 +20,15 @@ endif() # Detect the installed nanobind package and import it into CMake execute_process( - COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir + COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT ) find_package(nanobind CONFIG REQUIRED) -nanobind_add_module( - units_llnl - NB_STATIC - STABLE_ABI - src/units_python.cpp - ) +nanobind_add_module(units_llnl NB_STATIC STABLE_ABI src/units_python.cpp) target_link_libraries(units_llnl PUBLIC units::units) # Install directive for scikit-build-core -install(TARGETS units_llnl LIBRARY DESTINATION units_llnl) \ No newline at end of file +install(TARGETS units_llnl LIBRARY DESTINATION units_llnl) diff --git a/python/src/units_python.cpp b/python/src/units_python.cpp index 19abad28..eca7c1c9 100644 --- a/python/src/units_python.cpp +++ b/python/src/units_python.cpp @@ -100,9 +100,9 @@ NB_MODULE(units_llnl, mod) "check if two units are convertible to eachother") .def( "is_convertible_to", - [](const units::precise_unit& type1, - const char *desired_units) { - return type1.is_convertible( units::unit_from_string(std::string(desired_units))); + [](const units::precise_unit& type1, const char* desired_units) { + return type1.is_convertible( + units::unit_from_string(std::string(desired_units))); }, "check if the unit can be converted to the desired unit") .def( @@ -280,13 +280,23 @@ NB_MODULE(units_llnl, mod) const units::precise_unit& unitIn, const units::precise_unit& unitOut) { return units::convert(val, unitIn, unitOut); - },"value"_a,"unit_in"_a,"unit_out"_a, "value represented by one unit in terms of another"); - mod.def("convert", [](double val, const char* unitIn, const char* unitOut) { - return units::convert( - val, - units::unit_from_string(std::string(unitIn)), - units::unit_from_string(std::string(unitOut))); - },"value"_a,"unit_in"_a,"unit_out"_a,"generate a value represented by one unit in terms of another"); + }, + "value"_a, + "unit_in"_a, + "unit_out"_a, + "value represented by one unit in terms of another"); + mod.def( + "convert", + [](double val, const char* unitIn, const char* unitOut) { + return units::convert( + val, + units::unit_from_string(std::string(unitIn)), + units::unit_from_string(std::string(unitOut))); + }, + "value"_a, + "unit_in"_a, + "unit_out"_a, + "generate a value represented by one unit in terms of another"); mod.def( "convert_pu", [](double val, @@ -294,7 +304,12 @@ NB_MODULE(units_llnl, mod) const units::precise_unit& unitOut, double base_value) { return units::convert(val, unitIn, unitOut, base_value); - },"value"_a,"unit_in"_a,"unit_out"_a,"base_value"_a, "generate a value represented by one unit in terms of another if one of the units is in per-unit, the base_value is used in part of the conversion"); + }, + "value"_a, + "unit_in"_a, + "unit_out"_a, + "base_value"_a, + "generate a value represented by one unit in terms of another if one of the units is in per-unit, the base_value is used in part of the conversion"); mod.def( "convert_pu", [](double val, @@ -306,6 +321,14 @@ NB_MODULE(units_llnl, mod) units::unit_from_string(std::string(unitIn)), units::unit_from_string(std::string(unitOut)), base_value); - },"value"_a,"unit_in"_a,"unit_out"_a,"base_value"_a,"generate a value represented by one unit in terms of another if one of the units is in per-unit, the base_value is used in part of the conversion"); - mod.def("default_unit",&units::default_unit,"get the default unit to use for a particular type of measurement"); + }, + "value"_a, + "unit_in"_a, + "unit_out"_a, + "base_value"_a, + "generate a value represented by one unit in terms of another if one of the units is in per-unit, the base_value is used in part of the conversion"); + mod.def( + "default_unit", + &units::default_unit, + "get the default unit to use for a particular type of measurement"); } diff --git a/python/tests/test_units.py b/python/tests/test_units.py index 0770d6e8..3ba73fe9 100644 --- a/python/tests/test_units.py +++ b/python/tests/test_units.py @@ -11,7 +11,7 @@ def test_basic_unit(): u3=u1/u2 u4=u.unit('mph') assert(u3.is_convertible(u4)) - + def test_conditions(): u1=u.unit('m') u2=u.unit('error') @@ -20,10 +20,10 @@ def test_conditions(): assert(u2.is_error()) assert(u1.is_normal()) assert(not u2.is_normal()) - + assert(not u2.is_default()) - + assert(u1.is_valid()) - + assert(u1.is_finite()) - assert(not u3.is_finite()) \ No newline at end of file + assert(not u3.is_finite())