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 updates #684

Merged
merged 74 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
a216997
add check yaml
GernotMaier Nov 19, 2023
752eaa8
remove yaml
GernotMaier Nov 19, 2023
affb721
cleanup of pyproject.toml
GernotMaier Nov 19, 2023
a170f2d
first version of linter workflow
GernotMaier Nov 19, 2023
dcff228
add TODO for draft release
GernotMaier Nov 20, 2023
432dbf3
Merge branch 'main' into linter
GernotMaier Nov 21, 2023
b338fe5
super linter
GernotMaier Nov 21, 2023
2eb1cc6
linting
GernotMaier Nov 21, 2023
346d243
linting
GernotMaier Nov 21, 2023
0a942fb
linting
GernotMaier Nov 21, 2023
3a9cc3a
add black/isort config
GernotMaier Nov 21, 2023
bcd842f
super linter
GernotMaier Nov 22, 2023
375e629
super linter
GernotMaier Nov 22, 2023
3b62d72
add RST linter
GernotMaier Nov 22, 2023
d1dec31
re-order; add mamba installation
GernotMaier Nov 22, 2023
78b9a4c
remove non-ascii
GernotMaier Nov 22, 2023
8947c83
rst
GernotMaier Nov 22, 2023
d8b262b
rst not working
GernotMaier Nov 22, 2023
630a3a0
fixed markdown error
GernotMaier Nov 22, 2023
9596886
fix textlint error
GernotMaier Nov 22, 2023
bd2774e
black
GernotMaier Nov 22, 2023
018d26f
add pylint command to developer code
GernotMaier Nov 22, 2023
6ccdbb3
pylint options
GernotMaier Nov 22, 2023
71c2b8f
agreed pylint options
GernotMaier Nov 23, 2023
c0241f2
Merge branch 'main' into linter
GernotMaier Nov 27, 2023
58c90c0
Merge branch 'linter' into linter-motivated-fixes
GernotMaier Nov 27, 2023
74044a4
run not only for pull to main
GernotMaier Nov 28, 2023
c99aa1a
Merge branch 'linter' into linter-motivated-fixes
GernotMaier Nov 28, 2023
1ae8a92
run on pull to any branch
GernotMaier Nov 28, 2023
d2fcf2e
Merge pull request #690 from gammasim/linter-motivated-fixes
GernotMaier Dec 1, 2023
eae6652
Merge branch 'main' into linter
GernotMaier Dec 1, 2023
5c55beb
fix reformating issues reported by black
GernotMaier Dec 5, 2023
d0e1849
pylint fixes
GernotMaier Dec 5, 2023
c9273e0
add pip install to make simtools modules findable
GernotMaier Dec 5, 2023
84dd06b
pythonpath
GernotMaier Dec 5, 2023
2afbad9
add inithook, hopefully fixes import issue of pylint
GernotMaier Dec 5, 2023
6c01dce
mamba install
GernotMaier Dec 5, 2023
2fae010
f
GernotMaier Dec 5, 2023
32b52fb
try python package
GernotMaier Dec 5, 2023
1561cf9
install pylint separately
GernotMaier Dec 5, 2023
2cee7ab
Merge branch 'main' into linter
GernotMaier Dec 5, 2023
46b8ae0
pylint
GernotMaier Dec 5, 2023
252399f
pylint issue
GernotMaier Dec 5, 2023
950e3e2
pylint
GernotMaier Dec 5, 2023
10a8406
pylint
GernotMaier Dec 5, 2023
5331806
pylint
GernotMaier Dec 5, 2023
5042d95
improved pylint string
GernotMaier Dec 5, 2023
53969ec
pylint
GernotMaier Dec 5, 2023
c6eb382
pylint
GernotMaier Dec 5, 2023
9b4973b
pylint
GernotMaier Dec 5, 2023
311d2fe
pylint
GernotMaier Dec 5, 2023
1868dbd
pylint option cleanup
GernotMaier Dec 5, 2023
ff179b5
Merge branch 'main' into linter
GernotMaier Dec 6, 2023
f7994d3
set paths
GernotMaier Dec 6, 2023
cd3cbe6
change test
VictorBarbosaMartins Dec 6, 2023
313e04f
double check
VictorBarbosaMartins Dec 6, 2023
2e865a9
Merge branch 'main' into linter
GernotMaier Dec 6, 2023
852c48d
2D
GernotMaier Dec 6, 2023
a061426
1D
GernotMaier Dec 6, 2023
7058b20
fix test
GernotMaier Dec 6, 2023
c87c8f9
Use Lock correctly
orelgueta Dec 6, 2023
ffaccc7
Disable pylint for broad exception cause we do not really have a choi…
orelgueta Dec 6, 2023
602e649
Disable pylint complaint because code is clearer this way
orelgueta Dec 6, 2023
6dbe689
Disable pylint error because it seems it is not actually a protected …
orelgueta Dec 6, 2023
3f27c1c
Merge branch 'linter' of github.com:gammasim/simtools into linter
orelgueta Dec 6, 2023
3197970
fix pylint issue on sequence
GernotMaier Dec 7, 2023
b92b8e6
2D in colors
GernotMaier Dec 7, 2023
4455eb3
Merge branch 'main' into linter
GernotMaier Dec 7, 2023
9afbae1
remove obsolete line for super-linter
GernotMaier Dec 7, 2023
5ecdfcd
super-linter settings
GernotMaier Dec 7, 2023
aaeed91
super-linter settings
GernotMaier Dec 7, 2023
681cc1f
import sorting
GernotMaier Dec 7, 2023
b93963b
remove metadata from docstr
GernotMaier Dec 7, 2023
a5bd97a
correct underscore
VictorBarbosaMartins Dec 7, 2023
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
140 changes: 140 additions & 0 deletions .github/workflows/CI-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
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: true
# github actions
VALIDATE_GITHUB_ACTIONS: true
# yaml
VALIDATE_YAML: true
YAML_CONFIG_FILE: yaml_config.yaml
YAML_ERROR_ON_WARNING: false
# pylint
VALIDATE_PYTHON_PYLINT: 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 }}
with:
python_package_directory: .

# 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
15 changes: 6 additions & 9 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,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
Loading