Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0bed008
first mv: py
sbromberger Dec 17, 2025
8cfb80d
update requirements
sbromberger Dec 17, 2025
c743501
cleanup
sbromberger Dec 17, 2025
9a14b50
ruff linting
sbromberger Dec 17, 2025
543f4a5
ruff linting
sbromberger Dec 17, 2025
ca274ac
ruff formatting
sbromberger Dec 17, 2025
0c9fbe3
Copied dev container from clippy-cpp
rogerpearce Dec 18, 2025
b371cd7
commented out reqirments.
rogerpearce Dec 18, 2025
9415b67
Copying good files from clippy-cpp repo.
rogerpearce Dec 18, 2025
acc4adf
moved and renamed tests to examples
sbromberger Dec 19, 2025
4089420
moved python tests to project root/test dir
sbromberger Dec 19, 2025
7d51f21
modified pr workflow
sbromberger Dec 19, 2025
6bba7df
modified pr workflow
sbromberger Dec 19, 2025
29110fb
modified pr workflow
sbromberger Dec 19, 2025
8c7dcf4
modified pr workflow
sbromberger Dec 19, 2025
75d3cb4
modified pr workflow
sbromberger Dec 19, 2025
82a297a
modified pr workflow
sbromberger Dec 19, 2025
fbec3ed
Old examples, SimpleExamples now build. Not tested yet.
rogerpearce Dec 19, 2025
c035785
Added teest from SimpleExamples.howdy()
rogerpearce Dec 19, 2025
e5e3f4a
removed SimpleExamples, added another test
sbromberger Dec 19, 2025
d49333e
runtime errors now throw, and added a test
sbromberger Dec 19, 2025
3ff61b4
remove cpp test dir
sbromberger Dec 19, 2025
9164a7d
ruff fixes
sbromberger Dec 19, 2025
62f028d
remove spurious cerr
sbromberger Dec 19, 2025
d27d985
update README
sbromberger Dec 19, 2025
0607162
update pr.yml
sbromberger Dec 19, 2025
2b03252
remove ccache in pr.yml
sbromberger Dec 19, 2025
f1d14af
add -y to apt
sbromberger Dec 19, 2025
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
22 changes: 22 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04
FROM mcr.microsoft.com/devcontainers/cpp:dev-ubuntu-24.04

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"

# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/

RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh

# [Optional] Uncomment this section to install additional vcpkg ports.
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install clangd"

# [Optional] Uncomment this section to install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
RUN apt update && export DEBIAN_FRONTEND=noninteractive && apt -y install clangd-19 clang-tidy-19 python3-pip
RUN update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-19 100
RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-19 100
21 changes: 21 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile"
},
"containerEnv": {
"CLIPPY_BACKEND_PATH": "${containerWorkspaceFolder}/build/test"
},
"customizations": {
"vscode": {
"extensions": [
"llvm-vs-code-extensions.vscode-clangd",
"ms-python.python"
// add other extensions as needed
]
}
},
//"postCreateCommand": "pip install --break-system-packages -r ${containerWorkspaceFolder}/test/requirements.txt"
}
59 changes: 59 additions & 0 deletions .devcontainer/reinstall-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
set -e

CMAKE_VERSION=${1:-"none"}

if [ "${CMAKE_VERSION}" = "none" ]; then
echo "No CMake version specified, skipping CMake reinstallation"
exit 0
fi

# Cleanup temporary directory and associated files when exiting the script.
cleanup() {
EXIT_CODE=$?
set +e
if [[ -n "${TMP_DIR}" ]]; then
echo "Executing cleanup of tmp files"
rm -Rf "${TMP_DIR}"
fi
exit $EXIT_CODE
}
trap cleanup EXIT


echo "Installing CMake..."
apt-get -y purge --auto-remove cmake
mkdir -p /opt/cmake

architecture=$(dpkg --print-architecture)
case "${architecture}" in
arm64)
ARCH=aarch64 ;;
amd64)
ARCH=x86_64 ;;
*)
echo "Unsupported architecture ${architecture}."
exit 1
;;
esac

CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)

echo "${TMP_DIR}"
cd "${TMP_DIR}"

curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O

sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license

ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest
38 changes: 21 additions & 17 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
if [ -f py/requirements.txt ]; then pip install -r py/requirements.txt; fi
if [ -f py/requirements-dev.txt ]; then pip install -r py/requirements-dev.txt; fi

- name: Lint with flake8
- name: Lint with ruff
run: |
flake8 src/clippy --count --show-source --statistics --max-line-length=120
cd py
ruff check src/clippy --output-format=concise --statistics --line-length=120


- name: MyPy
run: |
cd py
mypy src/clippy --ignore-missing-imports

- name: Install Boost
Expand All @@ -40,33 +42,35 @@ jobs:
# OPTIONAL: Specify a platform version
# platform_version: 18.04
# OPTIONAL: Specify a custom install location
boost_install_dir: /home/runner/work/boost
# boost_install_dir: /home/runner/work/boost
# OPTIONAL: Specify a toolset
toolset: gcc
# OPTIONAL: Specify an architecture
# arch: x86

# - name: Setup ccache
# uses: hendrikmuhs/[email protected]
# with:
# key: ${{ github.job }}-${{ runner.os }}
# max-size: 500M # limit cache size
- name: Build backend
id: build-backend
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
run: |
echo BOOST_ROOT is $BOOST_ROOT /end/
sudo apt install doxygen
TMPDIR=$(mktemp -d)
git clone https://github.com/LLNL/clippy-cpp --branch ${{ github.head_ref }} $TMPDIR || git clone https://github.com/LLNL/clippy-cpp --branch master $TMPDIR
mkdir -p $TMPDIR/build
cd $TMPDIR/build && cmake -DMODERN_CMAKE_BUILD_TESTING=ON -DBUILD_TESTING=ON -DBOOST_ROOT=$BOOST_ROOT .. && make
ls -l $TMPDIR/build/test
BACKEND=$TMPDIR/build/test
echo "BACKEND=$BACKEND" >> $GITHUB_ENV
sudo apt install -y doxygen
CPPDIR=cpp
mkdir -p $CPPDIR/build
cd $CPPDIR/build && cmake -DMODERN_CMAKE_BUILD_TESTING=ON -DBUILD_TESTING=ON -DBOOST_ROOT=$BOOST_ROOT .. && make
ls -l examples
BACKEND=$CPPDIR/build/examples
# echo "BACKEND=$BACKEND" >> $GITHUB_ENV

- name: Pytest
env:
CLIPPY_BACKEND_PATH: ${{ env.BACKEND }}
run: |
echo "backend = $BACKEND"
pytest .
cd test
./run_tests.sh
# - name: Pytest
# run: |
# coverage run --source clippy/ -m pytest && coverage report -m --fail-under 99
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
__pycache__
**/build
venv
*.core
build
setup.cfg
.vscode
*.egg-info
.coverage
**/attic
build
*/.cache
.cache/
61 changes: 30 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,50 @@ environment – at the REPL, for example, or within a notebook – without the n
complex HPC behavior and arcane job submission commands.

## Installation of Python Code
There are three ways to use the Python code:
1. Install from PyPI:
```console
$ pip install .
$ pip install llnl-clippy
```

## Building C++ Examples on LC
2. Install from the cloned repository:
```console
$ cd py/src && pip install .
```

3. Via `PYTHONPATH` (see below)

## Building C++ Examples

```console
$ . /usr/workspace/llamag/spack/share/spack/setup-env.sh
$ git clone https://github.com/LLNL/clippy-cpp.git
$ spack load gcc
$ spack load boost
$ cd clippy-cpp
$ mkdir build
$ cd build
$ cmake ../
$ cd cpp && mkdir build && cd build
$ cmake ..
$ make
$ cd ../.. #back to root project directory
```

## Running Current C++ Examples
## Running Current C++ Examples (after building)
### From the repository root (using `PYTHONPATH`):
```python
$ CLIPPY_BACKEND_PATH=/path/to/binaries ipython3
$ PYTHONPATH=py/src:$PYTHONPATH CLIPPY_BACKEND_PATH=$(pwd)/cpp/build/examples ipython

In [1]: from clippy import *
In [1]: from clippy import ExampleBag

╭────────────────────────────────────╮
│ It looks like you want to use HPC. │
│ Would you like help with that? │
╰────────────────────────────────────╯
╭──╮
⊙ ⊙│╭
││ ││
│╰─╯│
╰───╯
In [2]: b = ExampleBag()

In [3]: b.insert(5).insert(6).insert(7) # can chain methods
Out[3]: <clippy.backends.fs.ExampleBag at 0x107d50830>

In [4]: b.insert(5).insert(8)
Out[4]: <clippy.backends.fs.ExampleBag at 0x107d50830>

In [2]: c = ClippyBag() # creates a bag datastructure.
In [5]: b.size()
Out[5]: 5

In [3]: c.insert("foo").insert("bar") # mutating methods can be chained

Out[3]: foo bar
In [6]: b.remove_if(b.value > 6) # removes 2 elements
Out[6]: <clippy.backends.fs.ExampleBag at 0x107d50830>

In [4]: c.size() # nonmutating methods return the appropriate output.
Out[4]: 2
In [7]: b.size()
Out[7]: 3

```
## Authors
Expand Down
96 changes: 96 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2020 Lawrence Livermore National Security, LLC and other CLIPPy
# Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: MIT


cmake_minimum_required(VERSION 3.26)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(ALLOW_DUPLICATE_CUSTOM_TARGETS TRUE)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()

project(CLIPPy
VERSION 0.5
DESCRIPTION "Command Line Interface Plus Python"
LANGUAGES CXX)

include(FetchContent)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Only do these if this is the main project, and not if it is included through add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Let's ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF)

# Let's nicely support folders in IDE's
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Testing only available if this is the main app
# Note this needs to be done in the main CMakeLists
# since it calls enable_testing, which must be in the
# main CMakeLists.
# include(CTest)

# Docs only available if this is the main app
find_package(Doxygen)
if(Doxygen_FOUND)
#add_subdirectory(docs)
else()
message(STATUS "Doxygen not found, not building docs")
endif()
endif()


#
# Boost
# Download and build Boost::json
set(BOOST_URL
"https://github.com/boostorg/boost/releases/download/boost-1.87.0/boost-1.87.0-cmake.tar.gz"
CACHE STRING "URL to fetch Boost tarball")


set(BOOST_INCLUDE_LIBRARIES json lexical_cast range)
set(BUILD_SHARED_LIBS ON)
FetchContent_Declare(
Boost
URL ${BOOST_URL})
FetchContent_MakeAvailable(Boost)


#
# JSONLogic
set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/boost-install) # needed for jsonlogic

FetchContent_Declare(jsonlogic
GIT_REPOSITORY https://github.com/LLNL/jsonlogic.git
GIT_TAG v0.2.0
SOURCE_SUBDIR cpp
)
# set(jsonlogic_INCLUDE_DIR ${jsonlogic_SOURCE_DIR}/cpp/include/jsonlogic)
FetchContent_MakeAvailable(jsonlogic)
message(STATUS "jsonlogic source dir: ${jsonlogic_SOURCE_DIR}")



### Require out-of-source builds
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
endif()

include_directories("${PROJECT_SOURCE_DIR}/include")

option(TEST_WITH_SLURM "Run tests with Slurm" OFF)

# Testing & examples are only available if this is the main app
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
add_subdirectory(examples)
endif()
11 changes: 11 additions & 0 deletions cpp/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 3,
"configurePresets": [
{
"name": "cfg",
"generator": "Ninja",
"sourceDir": "src",
"binaryDir": "build"
}
]
}
Loading
Loading