Skip to content

Commit

Permalink
Merge pull request #684 from gammasim/linter
Browse files Browse the repository at this point in the history
Linter updates
  • Loading branch information
GernotMaier authored Dec 7, 2023
2 parents 44cbe1f + a5bd97a commit 92b1c92
Show file tree
Hide file tree
Showing 42 changed files with 595 additions and 955 deletions.
136 changes: 136 additions & 0 deletions .github/workflows/CI-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
name: CI-linting

on:
pull_request:
types: [opened, synchronize]
schedule:
- cron: "0 0 * * *"

jobs:

linting:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -leo pipefail {0}

permissions:
contents: read
packages: read
statuses: write

steps:
- name: checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Check for non-ASCII characters
run: |
output=$(find . -type f \
\( -name "*.py" -o -name "*.rst" -o -name "*.yml" -o -name "*.toml" \) \
-exec perl -ne 'print if /[^[:ascii:]]/' {} \;)
if [ -n "$output" ]; then
echo "Non-ASCII characters found in documentation."
exit 1
fi
- name: install packages not included in super-linter
run: |
pip install validate-pyproject restructuredtext-lint
- name: pyproject.toml
run: |
validate-pyproject pyproject.toml
# RST linter
# Note: unclear how to suppress error messages
# (use grep -v in this case)
# - name: restructuredtext-lint
# run: |
# rst-lint README.rst docs/source |
# grep -v "Unknown directive type" |
# grep -v "Unknown interpreted text role" |
# grep -v "Cannot analyze code. Pygments package not found."

- name: Check whether the citation metadata from CITATION.cff is valid
uses: citation-file-format/[email protected]
with:
args: "--validate"

- name: yaml_config used by super-linter
run: |
# TODO - very large line length
echo 'rules:' > yaml_config.yaml
echo ' line-length:' >> yaml_config.yaml
echo ' max: 250' >> yaml_config.yaml
# Dependencies required to avoid errors
# reported by linters
- name: Install mamba dependencies
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
init-shell: bash

- name: Python dependencies
run: |
pip install -e '.[tests,dev,doc]'
pip install pylint
- name: pylint
run: |
pylint $(git ls-files 'simtools/*.py')
- name: Lint Code Base
uses: super-linter/super-linter@v5
env:
VALIDATE_ALL_CODEBASE: false
# github actions
VALIDATE_GITHUB_ACTIONS: true
# yaml
VALIDATE_YAML: true
YAML_CONFIG_FILE: yaml_config.yaml
YAML_ERROR_ON_WARNING: false
# isort
VALIDATE_PYTHON_ISORT: true
PYTHON_ISORT_CONFIG_FILE: pyproject.toml
# flake8
VALIDATE_PYTHON_FLAKE8: true
# black
VALIDATE_PYTHON_BLACK: true
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
# markdown
VALIDATE_MARKDOWN: true
# docker
VALIDATE_DOCKERFILE_HADOLINT: true
# copy and paste
VALIDATE_JSCPD_ALL_CODEBASE: true
# .env file
VALIDATE_ENV: true
# language
VALIDATE_NATURAL_LANGUAGE: true
# bash
VALIDATE_BASH: true
# path for linter rules
LINTER_RULES_PATH: ./
# create a log file
CREATE_LOG_FILE: true
LOG_FILE: superlinter.log
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Upload super-linter log file
# and keep it for 5 days
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: super-linter reports
path: |
superlinter.log
retention-days: 5
2 changes: 1 addition & 1 deletion .github/workflows/CI-unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: checkout
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand Down
9 changes: 7 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: isort
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.11.0
hooks:
- id: black
args: ["--line-length=100"]
Expand All @@ -18,7 +18,7 @@ repos:
args: ["--max-line-length=100"]
# https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -28,3 +28,8 @@ repos:
hooks:
- id: docstr-coverage
args: ["--verbose", "2", "--fail-under", "70.", "simtools"]
# gitup action
- repo: https://github.com/rhysd/actionlint
rev: v1.6.26
hooks:
- id: actionlint
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ Please cite this software if it use used for a publication, see the `Zenodo reco
Acknowledgements
================

This project is supported by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) project number 460248186 (PUNCH4NFDI).
This project is supported by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) - project number 460248186 (PUNCH4NFDI).
6 changes: 3 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Types of dockerfiles and containers available:

- [simtools users](#container-for-simtools-users): a container with all software installed (CORSIKA, sim\_telarray, simtools python environment, simtools). Pull latest release with: `docker pull ghcr.io/gammasim/simtools-prod:latest`
- [simtools developers](#container-for-simtools-developers): a container with CORSIKA, sim\_telarray, and simtools conda environment installed. Pull latest release with: `docker pull ghcr.io/gammasim/simtools-dev:latest`
- [sim\_telarray](#container-for-simulation-software-corsika--sim_telarray): provides a container with the CORSIKA and sim\_telarray installed. This provides the base image for the previously listed containers. Pull latest release with: `docker pull ghcr.io/gammasim/simtools-simtelarray:latest`
- [sim_telarray](#container-for-corsika-and-simtelarray): provides a container with the CORSIKA and sim\_telarray installed. This provides the base image for the previously listed containers. Pull latest release with: `docker pull ghcr.io/gammasim/simtools-simtelarray:latest`

## Container for simtools Users

Expand Down Expand Up @@ -95,7 +95,7 @@ docker build -f Dockerfile-dev -t simtools-dev .

Use the docker container in the same way as above, replacing `ghcr.io/gammasim/simtools-dev:latest` by `simtools-dev`.

## Container for simulation software CORSIKA / sim\_telarray
## Container for CORSIKA and sim\_telarray

Provide a container including the following the CORSIKA and sim\_telarray simulation software packages.

Expand All @@ -118,7 +118,7 @@ docker build -f Dockerfile-simtelarray -t simtelarray .
```

Building expects that a tar ball of corsika/sim\_telarray (named corsika7.7\_simtelarray.tar.gz) is available in the building directory.
Download the tar package from the MPIK website (password applies) with
Download the tar package from MPIK (password applies) with

```bash
./download_simulationsoftware.sh
Expand Down
10 changes: 10 additions & 0 deletions docs/source/coding_guidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ In rare cases, one might want to skip pre-commit checks with
git commit --no-verify
Code Linting
============

Linters of almost all file types are run by the CI-linter workflow.

To run pylint locally, use:

.. code-block::
pylint $(git ls-files 'simtools/*.py')
API documentation
-----------------
Expand Down
18 changes: 7 additions & 11 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@

import os
import sys
from pathlib import Path

import toml
import yaml

from pathlib import Path

import simtools.version

sys.path.insert(0, os.path.abspath("../../simtools"))
Expand All @@ -31,20 +30,17 @@ def get_authors_from_citation_file():
Read list of authors from CITATION.cff file
"""
try:
with open(Path(__file__).parent / "../../CITATION.cff") as file:
citation = yaml.safe_load(file)
except FileNotFoundError:
raise
with open(Path(__file__).parent / "../../CITATION.cff", encoding="utf-8") as file:
citation = yaml.safe_load(file)

author = ""
tmp_author = ""
try:
for person in citation["authors"]:
author = author + person["given-names"] + " " + person["family-names"]
author += " (" + person["affiliation"] + "), "
tmp_author = tmp_author + person["given-names"] + " " + person["family-names"]
tmp_author += " (" + person["affiliation"] + "), "
except KeyError:
pass
return author[:-2]
return tmp_author[:-2]


def get_python_version_from_pyproject():
Expand Down
Loading

0 comments on commit 92b1c92

Please sign in to comment.