Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,38 @@ jobs:
run: |
valgrind --leak-check=full --track-origins=yes --error-exitcode=1 \
./build/tests/test_bethe_ext00

python_tests:
runs-on: ubuntu-latest
needs: build_and_test
strategy:
matrix:
python-version: ["3.9", "3.13"]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Comment thread
nbassler marked this conversation as resolved.
- name: Configure
run: cmake -S . -B build

- name: Build
run: cmake --build build --parallel

- name: Install Python package and dev dependencies
run: python -m pip install -e "python[dev]"

- name: Run ruff
if: ${{ matrix.python-version == '3.13' }}
working-directory: python
run: python -m ruff check .

- name: Run Python tests
working-directory: python
env:
LIBDEDX_SO: ${{ github.workspace }}/build/libdedx/libdedx.so
run: python -m pytest tests -q
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Custom ignores
.codex
*.bin

build/
build-release/
build-coverage/

Testing/

docs/doxygen/html/
.codex

python/.venv/
python/__pycache__/
python/.pytest_cache/
python/*.egg-info/
*.pyc

# Generated by CMake at configure time - do not commit
libdedx/dedx_config.h
Expand Down
3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"recommendations": [
"llvm-vs-code-extensions.vscode-clangd",
"ms-vscode.cmake-tools",
"twxs.cmake"
"ms-python.python"
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"editor.formatOnSave": true
},

// Python — add python/ to the analysis path so Pylance finds the libdedx package (__init__.py / __init__.pyi)
"python.analysis.extraPaths": ["python"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"python.testing.cwd": "${workspaceFolder}/python",
"python.testing.pytestArgs": ["tests"],

// Editor
"editor.rulers": [120],
"files.trimTrailingWhitespace": true,
Expand Down
57 changes: 41 additions & 16 deletions libdedx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,60 @@ set(dedx_data data/ASTAR.bin data/astarEng.dat data/mstarEng.dat data/pstarEng.b

set(dedx_data_bin data/ASTAR.bin data/astarEng.bin data/ICRU73.bin data/icru73Eng.bin data/ICRU73_NEW.bin data/icru73_newEng.bin data/MSTAR.bin data/mstarEng.bin data/PSTAR.bin data/ICRU_PSTAR.bin data/ICRU_ASTAR.bin data/pstarEng.bin data/betheEng.bin data/icru_astarEng.bin data/icru_pstarEng.bin data/compos.txt data/effective_charge.dat data/short_names data/composition data/gas_states.dat data/atima_compos)

add_library(dedx STATIC dedx_tools.c dedx_bethe.c dedx.c dedx_wrappers.c dedx_file_access.c dedx_file.c dedx_mpaul.c dedx_mstar.c dedx_spline.c dedx_split.c dedx_periodic_table.c tools/dedx_math.c dedx_validate.c)

target_include_directories(dedx PUBLIC
# Object library: compiled once with -fPIC so the objects feed both the
# static and the shared library without a second compilation pass.
add_library(dedx_objects OBJECT
dedx_tools.c dedx_bethe.c dedx.c dedx_wrappers.c dedx_file_access.c
dedx_file.c dedx_mpaul.c dedx_mstar.c dedx_spline.c dedx_split.c
dedx_periodic_table.c tools/dedx_math.c dedx_validate.c
)
set_property(TARGET dedx_objects PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(dedx_objects PUBLIC
"${PROJECT_SOURCE_DIR}/libdedx"
"${PROJECT_BINARY_DIR}"
)
# removed math_dedx.h
# removed dedx_atima.c

# Version passed as compile definitions, derived from git tag at configure time
target_compile_definitions(dedx PRIVATE
target_compile_definitions(dedx_objects PRIVATE
DEDX_VERSION_MAJOR=${DEDX_VERSION_MAJOR}
DEDX_VERSION_MINOR=${DEDX_VERSION_MINOR}
DEDX_VERSION_PATCH=${DEDX_VERSION_PATCH}
)

target_link_libraries(dedx)

# Static library — for C/CMake consumers; PUBLIC so include dirs propagate.
add_library(dedx STATIC)
target_link_libraries(dedx PUBLIC dedx_objects)
# Visual Studio does not need or want you to explicitly request linking the math library.
# You must avoid adding it as a link library when building for Windows.
# see https://stackoverflow.com/questions/54935559/linking-math-library-in-cmake-file-on-windows-and-linux
IF (NOT WIN32)
target_link_libraries (dedx m)
ENDIF()
if(NOT WIN32)
target_link_libraries(dedx PUBLIC m)
endif()

# Shared library — for Python ctypes and other dynamic consumers.
add_library(dedx_shared SHARED)
target_link_libraries(dedx_shared PUBLIC dedx_objects)
if(WIN32)
set_target_properties(dedx_shared PROPERTIES
OUTPUT_NAME dedx
ARCHIVE_OUTPUT_NAME dedx_shared
)
else()
set_target_properties(dedx_shared PROPERTIES OUTPUT_NAME dedx)
endif()
if(NOT WIN32)
target_link_libraries(dedx_shared PUBLIC m)
endif()

install(FILES dedx.h dedx_tools.h dedx_wrappers.h DESTINATION include)

install(TARGETS dedx dedx_shared
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

install (FILES dedx.h dedx_tools.h dedx_wrappers.h DESTINATION include)
install (TARGETS dedx DESTINATION lib)
if(WIN32)
install (FILES ${dedx_data_bin} DESTINATION data)
install(FILES ${dedx_data_bin} DESTINATION data)
else()
install (FILES ${dedx_data_bin} DESTINATION share/libdedx)
install(FILES ${dedx_data_bin} DESTINATION share/libdedx)
endif()
65 changes: 0 additions & 65 deletions python/CMakeLists.txt

This file was deleted.

17 changes: 0 additions & 17 deletions python/README

This file was deleted.

7 changes: 7 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# libdedx Python binding

This directory contains the `ctypes`-based Python binding for `libdedx`.

The Python module loads the native `libdedx` shared library at runtime.
Build and install the C library first, or set `LIBDEDX_SO` to the path of
the built shared library during development and testing.
141 changes: 0 additions & 141 deletions python/libdedx.c

This file was deleted.

Loading
Loading