Skip to content

Commit 09c8d37

Browse files
authored
Set up formatting for R, check formatting in CI (#295)
* Set up formatting for R, automatic formatting in CI * Run formatters * Update doc * More dev docs * Update python metadata * use install-juliaup for consistency
1 parent 2bce3c2 commit 09c8d37

File tree

19 files changed

+630
-353
lines changed

19 files changed

+630
-353
lines changed

.github/workflows/main.yaml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ concurrency:
1616
cancel-in-progress: true
1717

1818
jobs:
19+
check-formatting:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Check out github
23+
uses: actions/checkout@v5
24+
with:
25+
submodules: recursive
26+
27+
- name: Set up Julia
28+
uses: julia-actions/install-juliaup@v2
29+
with:
30+
channel: lts
31+
32+
- name: Install Formatters
33+
run: |
34+
sudo apt install -y clang-format black isort
35+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/posit-dev/air/releases/download/0.8.0/air-installer.sh | sh
36+
julia --project=julia -e 'import Pkg; Pkg.add("JuliaFormatter")'
37+
38+
- name: Run formatting checks
39+
run: |
40+
make format-check || (echo "::error title=Formatting::Formatting check failed, run \`make format\` locally" && exit 1)
41+
1942
build:
2043
runs-on: ${{matrix.os}}
2144
strategy:
@@ -37,14 +60,12 @@ jobs:
3760
path: ./stan/
3861
key: ${{ runner.os }}-stan-${{ hashFiles('stan/src/stan/version.hpp') }}-v${{ env.CACHE_VERSION }}
3962

40-
4163
- name: Set up PATH for C example
4264
if: matrix.os == 'windows-latest'
4365
run: |
4466
Add-Content $env:GITHUB_PATH "$(pwd)/stan/lib/stan_math/lib/tbb"
4567
Add-Content $env:GITHUB_PATH "$(pwd)/test_models/full"
4668
47-
4869
- name: Build C example (Windows)
4970
if: matrix.os == 'windows-latest'
5071
run: |
@@ -91,7 +112,7 @@ jobs:
91112
strategy:
92113
matrix:
93114
os: [ubuntu-latest, macos-latest, windows-latest]
94-
python-version: ["3.9", "3.12"]
115+
python-version: ["3.9", "3.14"]
95116
fail-fast: false
96117
steps:
97118
- name: Check out github
@@ -298,7 +319,6 @@ jobs:
298319
timeout-minutes: 60
299320
run: |
300321
cargo clippy
301-
cargo fmt --check
302322
cargo run --example=example
303323
304324
# run all tests with feature download-bridgestan-src

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ We follow standard open source and GitHub practices:
2626

2727
* We add unit tests when changing or adding code.
2828

29+
* We keep our code formatted using automatic tools (`make format` can run all of them for you).
30+
2931
* We keep the main branch in a release-ready state at all times.
3032

3133
* We propose updates through [GitHub Pull Requests](https://github.com/roualdes/bridgestan/pulls) so that we can do code review. We do not push directly to the main branch.

Makefile

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,24 @@ stan-update-remote:
114114
compile_info:
115115
@echo '$(LINK.cpp) $(BRIDGE_O) $(LDLIBS) $(SUNDIALS_TARGETS) $(MPI_TARGETS) $(TBB_TARGETS)'
116116

117-
# set to false if you want to fail on formatting errors
118-
# e.g., in continuous integration
119-
BS_FORMAT_IGNOREABLE ?= true
120117

121-
.PHONY: format
118+
119+
.PHONY: format format-check
122120
format:
123-
clang-format -i src/*.cpp src/*.hpp src/*.h || $(BS_FORMAT_IGNOREABLE)
124-
isort python || $(BS_FORMAT_IGNOREABLE)
125-
black python || $(BS_FORMAT_IGNOREABLE)
126-
julia --project=julia -e 'using JuliaFormatter; format("julia/")' || $(BS_FORMAT_IGNOREABLE)
127-
# R seems to have no good formatter that doesn't choke on doc comments
128-
# Rscript -e 'formatR::tidy_dir("R/", recursive=TRUE)' || $(BS_FORMAT_IGNOREABLE)
121+
clang-format -i src/*.cpp src/*.hpp src/*.h || true
122+
isort python || true
123+
black python || true
124+
julia --project=julia -e 'using JuliaFormatter; format("julia/")' || true
125+
air format R || true
126+
cd rust && cargo fmt || true
127+
128+
format-check:
129+
clang-format --dry-run --Werror src/*.cpp src/*.hpp src/*.h
130+
isort python --check
131+
black python --check
132+
julia --project=julia -e 'using JuliaFormatter; if !format("julia/", overwrite=false) exit(1) end'
133+
air format R --check
134+
cd rust && cargo fmt --check
129135

130136
# print value of makefile variable (e.g., make print-TBB_TARGETS)
131137
.PHONY: print-%

0 commit comments

Comments
 (0)