Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter #159

Merged
merged 11 commits into from
Oct 10, 2024
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
6 changes: 3 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Pull request description:
# Pull request description


## Changes or fixes:
## Changes or fixes


## Examples:
## Examples
9 changes: 7 additions & 2 deletions .github/workflows/CDImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ jobs:
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Set MACH3_VERSION
run: echo "MACH3_VERSION=${{ github.head_ref }}" >> "$GITHUB_ENV"
env:
GITHUB_HEAD_REF: ${{ github.head_ref }}

- name: Build Docker image
run: |
if [ "${{ github.ref_type }}" == 'tag' ]; then
docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.os }}${{ github.ref_name }} --build-arg MACH3_VERSION=${{ github.ref_name }}
docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.os }}${{ github.ref_name }} --build-arg MACH3_VERSION="${MACH3_VERSION}"
else
docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.tag_latest }} --build-arg MACH3_VERSION=develop
docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.tag_latest }} --build-arg MACH3_VERSION="develop"
fi

- name: Push Docker image
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/CIBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ jobs:
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Set environment variable for MACH3_VERSION
run: echo "MACH3_VERSION=${{ github.head_ref }}" >> "$GITHUB_ENV"

- name: Build the Docker image
run: docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.tag }} --build-arg MACH3_VERSION=${{ github.head_ref }} --build-arg CMAKE_OPTIONS="${{ matrix.cmakeoptions }}"
run: docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.tag }} --build-arg MACH3_VERSION=${{ env.MACH3_VERSION }} --build-arg CMAKE_OPTIONS="${{ matrix.cmakeoptions }}"
5 changes: 3 additions & 2 deletions .github/workflows/CIValidations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ jobs:
steps:
- uses: actions/checkout@v4


- name: Get MaCh3 Validations
run: |
cd /opt/
git clone https://github.com/mach3-software/MaCh3Tutorial.git MaCh3Validations
cd MaCh3Validations
mkdir build
cd build
cmake ../ -DMaCh3_Branch=${{ github.head_ref }}
cmake ../ -DMaCh3_Branch="${{ env.GITHUB_HEAD_REF }}"
env:
GITHUB_HEAD_REF: ${{ github.head_ref }}

- name: Build MaCh3 Validations
run: |
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/Linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# Lint our code and throw error if something is looking fishy in the changes
name: Super Linter

on:
pull_request:
branches: [develop]

jobs:
super-linter:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run Super Linter
uses: github/super-linter@v7
env:
VALIDATE_MARKDOWN: true # Enable Markdown linting
VALIDATE_DOCKERFILE: true # Enable Dockerfile linting
VALIDATE_YAML: true # Enable YAML linting
VALIDATE_GITHUB_ACTIONS: true # Enable GitHub Actions workflow linting
VALIDATE_PYTHON: true # Enable Python linting
VALIDATE_ALL_CODEBASE: false # Lint the entire codebase
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token for permissions
DISABLE_LINTERS: "CPP" # Disable linting for other languages
16 changes: 16 additions & 0 deletions .github/workflows/Meme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Add random meme whenever PR is opened
name: "Random Meme"

on:
pull_request:
types: [opened, reopened]

jobs:
test:
name: setup environment
runs-on: ubuntu-latest
steps:
- name: Memes
uses: deep5050/memes-on-issues-action@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 10 additions & 10 deletions .github/workflows/Newsletter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ jobs:

- name: Count the total number of commits in MaCh3
run: |
echo "commit_count=$(git rev-list --count HEAD)" >> $GITHUB_ENV
echo "commit_count=$(git rev-list --count HEAD)" >> "$GITHUB_ENV"

- name: Count commits in the last week for MaCh3
run: |
echo "commits_last_week=$(git rev-list --count --since='1 week ago' HEAD)" >> $GITHUB_ENV
echo "commits_last_week=$(git rev-list --count --since='1 week ago' HEAD)" >> "$GITHUB_ENV"

- name: Get the most recent tag for MaCh3
run: |
latest_tag=$(git describe --tags --abbrev=0)
echo "latest_tag=${latest_tag}" >> $GITHUB_ENV
echo "latest_tag=${latest_tag}" >> "$GITHUB_ENV"

- name: Get the current date
run: |
current_date=$(date +"%d/%m/%Y")
echo "current_date=${current_date}" >> $GITHUB_ENV
echo "current_date=${current_date}" >> "$GITHUB_ENV"

- name: Checkout the MaCh3Tutorial repository
uses: actions/checkout@v4
Expand All @@ -41,16 +41,16 @@ jobs:

- name: Count the total number of commits in MaCh3Tutorial
run: |
echo "tutorial_commit_count=$(git -C MaCh3Tutorial rev-list --count HEAD)" >> $GITHUB_ENV
echo "tutorial_commit_count=$(git -C MaCh3Tutorial rev-list --count HEAD)" >> "$GITHUB_ENV"

- name: Count commits in the last week for MaCh3Tutorial
run: |
echo "tutorial_commits_last_week=$(git -C MaCh3Tutorial rev-list --count --since='1 week ago' HEAD)" >> $GITHUB_ENV
echo "tutorial_commits_last_week=$(git -C MaCh3Tutorial rev-list --count --since='1 week ago' HEAD)" >> "$GITHUB_ENV"

- name: Get the most recent tag for MaCh3Tutorial
run: |
tutorial_latest_tag=$(git -C MaCh3Tutorial describe --tags --abbrev=0)
echo "tutorial_latest_tag=${tutorial_latest_tag}" >> $GITHUB_ENV
echo "tutorial_latest_tag=${tutorial_latest_tag}" >> "$GITHUB_ENV"

- name: Checkout the MaCh3-PythonUtils repository
uses: actions/checkout@v4
Expand All @@ -61,16 +61,16 @@ jobs:

- name: Count the total number of commits in MaCh3-PythonUtils
run: |
echo "python_utils_commit_count=$(git -C MaCh3-PythonUtils rev-list --count HEAD)" >> $GITHUB_ENV
echo "python_utils_commit_count=$(git -C MaCh3-PythonUtils rev-list --count HEAD)" >> "$GITHUB_ENV"

- name: Count commits in the last week for MaCh3-PythonUtils
run: |
echo "python_utils_commits_last_week=$(git -C MaCh3-PythonUtils rev-list --count --since='1 week ago' HEAD)" >> $GITHUB_ENV
echo "python_utils_commits_last_week=$(git -C MaCh3-PythonUtils rev-list --count --since='1 week ago' HEAD)" >> "$GITHUB_ENV"

- name: Get the most recent tag for MaCh3-PythonUtils
run: |
python_utils_latest_tag=$(git -C MaCh3-PythonUtils describe --tags --abbrev=0)
echo "python_utils_latest_tag=${python_utils_latest_tag}" >> $GITHUB_ENV
echo "python_utils_latest_tag=${python_utils_latest_tag}" >> "$GITHUB_ENV"

- name: Create a new GitHub Discussion
uses: abirismyname/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/TagTutorial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
cd MaCh3Tutorial/

# Extract the tag name from GITHUB_REF
TAG_NAME=$(echo "${GITHUB_REF#refs/tags/}")
TAG_NAME="${GITHUB_REF#refs/tags/}"

# Create the new tag
git tag $TAG_NAME
git tag "$TAG_NAME"

# Push the tag to the MaCh3Tutorial repository
git push https://${{ secrets.MACH3_VALIDATIONS_PAT }}@github.com/mach3-software/MaCh3Tutorial.git $TAG_NAME
git push https://${{ secrets.MACH3_VALIDATIONS_PAT }}@github.com/mach3-software/MaCh3Tutorial.git "$TAG_NAME"
31 changes: 15 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## How to Contribute Code to MaCh3
# How to Contribute Code to MaCh3
The gitflow development policy should be followed, with the master and develop branches only being committed to via pull request.

New features should be developed on branches in this repository with the branch naming: `feature_FEATURENAME`
Expand All @@ -8,59 +8,58 @@ Please see [here](https://www.atlassian.com/git/tutorials/comparing-workflows/gi
## Doxygen
When making comments try following Doxygen type of comments

```
```cpp
// I like comments
void Foo(){}
```
try
```
```cpp
/// @brief I like comments
void Foo(){}
```
After making release or tag please
```
```bash
cd Doc
doxygen Doxyfile
```
to produce both html and latex file. To produce book like pdf file:
```
```bash
cd latex
pdflatex refman.tex
```

## Logger
MaCh3 is using spdlog logger see [here](https://github.com/gabime/spdlog/tree/master). And wraps it around MaCh3 names [here](https://github.com/mach3-software/MaCh3/blob/develop/manager/MaCh3Logger.h)
It is advised to use it. For example rather than
```
```cpp
std::cout<< " Error: Something is wrong" <<std::endl;
```
it is advised to used logger
```
```cpp
MACH3LOG_ERROR("Something is wrong");
```
To pass argument to logger use following syntax:
```
```cpp
MACH3LOG_INFO("I like {}, do you like {}", FirsString, SecondString);
```
Logger by default will print whole float. Normally to show only several significant figures you would use `std::precision(2)`. To obtain same thing with logger please use `{:.2f}` like this:
```
```cpp
MACH3LOG_INFO("Here is full LLH but I only show 2 significant figures {:.2f}", LLH);
```

## Config Syntax
MaCh3 currently uses yaml as config handler. To help unify syntax over the code there are several YamlHelper function available [here](https://github.com/mach3-software/MaCh3/blob/develop/manager/YamlHelper.h). Most important is `GetFromManager`. For code below which checks if config entry exist and if doesn't set some default value

```
```cpp
bool AsimovFit = false;

if(config[AsimovFit])
{
AsimovFit = config[AsimovFit].as<bool>;
}

```
This can be replaced with:
```
```cpp
bool AsimovFit = GetFromManager<bool>(config[AsimovFit], false);
```

Expand All @@ -70,23 +69,23 @@ Some fits require lot's of RAM. Easiest and fastest solution to reduce RAM is us
## Error handling
MaCh3 uses custom error handling implemented [here](https://github.com/mach3-software/MaCh3/blob/develop/manager/MaCh3Exception.h)
Instead of throw
```
```cpp
throw;
```
it is advised to use:

```
```cpp
throw MaCh3Exception(__FILE__ , __LINE__ , "Some message");
```
or
```
```cpp
throw MaCh3Exception(__FILE__ , __LINE__ );
```
This way we can ensure error messages are unified and user always get hints where in the code problem occurred. If current MaCh3Exception is not sufficient consider implementing new or expanding current exceptions in MaCh3Exception.h.

## Formatting
To ensure a unified style in MaCh3 software you can use a clang-format file which has instructions about formatting code.
```
```bash
clang-format --assume-filename=/path/to/your/.clang-format=${MaCh3_ROOT}/../.clang-format blarb.cpp
```
Please see [here](https://clang.llvm.org/docs/ClangFormat.html) and [here](https://root.cern/contribute/coding_conventions/) for more details.
6 changes: 3 additions & 3 deletions Diagnostics/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Diagnostic
# Diagnostic
**ProcessMCMC** - The main app you want to use for analysing the ND280 chain. It prints posterior distribution after burn-in the cut. Moreover, you can compare two/three different chains. There are a few options you can modify easily inside the app like selection, burn-in cut, and whether to plot xse+flux or only flux. Other functionality
<ol>
<li> Produce a covariance matrix with multithreading (which requires lots of RAM due to caching) </li>
Expand All @@ -14,12 +14,12 @@
**DiagMCMC** - Perform MCMC diagnostic like autocorrelation or trace plots.

**RHat** - Performs RHat diagnostic to study if all used chains converged to the same stationary distribution.
```
```bash
./RHat Ntoys MCMCchain_1.root MCMCchain_2.root MCMCchain_3.root ... [how many you like]
```

**CombineMaCh3Chains** - will combine chains files produced by **MCMC**, enforcing the condition that all the files to combine were made using the exact same software versions and config files
```
```bash
CombineMaCh3Chains [-h] [-c [0-9]] [-f] [-o <output file>] file1.root [file2.root, file3.root ...]
```
*fileX.root* are the individual spline files to combine, can specify any number, need at least one
Expand Down
Loading