Skip to content

Commit

Permalink
Lint YAML files with yamllint
Browse files Browse the repository at this point in the history
There is now a configuration file for `yamllint`
and a `pre-commit` hook.

Some of the most straightforward linting issues were fixed.
The other ones are ignored and should be handled in the future.
  • Loading branch information
fabcor-maxiv committed Jun 27, 2024
1 parent 33afc56 commit ec23305
Show file tree
Hide file tree
Showing 26 changed files with 231 additions and 120 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/coverage_report.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
---

name: Coverage Report
on:

on: # yamllint disable-line rule:truthy
pull_request:
types: [opened, reopened, synchronize]
paths:
- '**.py'

jobs:
pytest-coverage:
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:

# yamllint disable-line rule:indentation
- uses: actions/checkout@v3

- name: Set up Python 3.10
Expand All @@ -18,16 +25,20 @@ jobs:
python-version: "3.10"

- name: Install dependencies
# yamllint disable rule:line-length
run: |
sudo apt-get update && sudo apt-get install -y libsasl2-dev libldap2-dev libssl-dev
python -m pip install --upgrade pip
python -m pip install poetry --user
python -m poetry install --extras=tango
# yamllint enable rule:line-length

- name: Run and write pytest
# yamllint disable rule:line-length
run: |
set -o pipefail
poetry run pytest --cov=mxcubecore --junitxml=pytest.xml --cov-report=term-missing:skip-covered | tee pytest-coverage.txt
# yamllint enable rule:line-length

- name: Pytest coverage comment
id: coverage-comment
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/create-tag.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
---

name: Create/Update Tag
on:
on: # yamllint disable-line rule:truthy
push:
branches:
- develop
jobs:
create-version-tag:
runs-on: ubuntu-latest
steps:
# yamllint disable-line rule:indentation
- uses: actions/checkout@v3
with:
token: ${{ secrets.CI_TOKEN }}
Expand Down Expand Up @@ -34,10 +37,12 @@ jobs:
poetry publish
- name: Read package version
id: set-tag
# yamllint disable rule:line-length
run: |
pip install --upgrade pip
pip install toml
echo ::set-output name=tag_name::v$(python -c 'import toml; print(toml.load("./pyproject.toml")["tool"]["poetry"]["version"])')
# yamllint enable rule:line-length

- name: Check tag exists
id: check-tag-exists
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: "Pages"
concurrency:
group: "pages"

on:
on: # yamllint disable-line rule:truthy
push:
pull_request:

Expand Down
52 changes: 30 additions & 22 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
---

name: Linting & Code Quality
on:

on: # yamllint disable-line rule:truthy
pull_request:
types: [opened, reopened, synchronize]

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

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

- name: Install openldap
run: |
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y libldap2-dev libsasl2-dev slapd ldap-utils tox lcov valgrind
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry --user
python -m poetry install
- name: Run Pre-Commit
run: |
poetry run pre-commit run --all-files

- uses: actions/checkout@v3

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

- name: Install openldap
# yamllint disable rule:line-length
run: |
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y libldap2-dev libsasl2-dev slapd ldap-utils tox lcov valgrind
# yamllint enable rule:line-length

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry --user
python -m poetry install
- name: Run Pre-Commit
run: |
poetry run pre-commit run --all-files
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---

name: Pytest
on:
on: # yamllint disable-line rule:truthy
pull_request:
types: [opened, reopened, synchronize]
paths:
Expand All @@ -19,6 +21,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install openldap
# yamllint disable-line rule:line-length
run: sudo apt-get update && sudo apt-get install -y libldap2-dev libsasl2-dev slapd ldap-utils tox lcov valgrind

- name: Install dependencies
Expand Down
48 changes: 21 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
---

default_language_version:
python: python3.8

repos:

- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
args:
- --strict

- repo: https://github.com/python-poetry/poetry
rev: 1.5.0
hooks:
- id: poetry-check
# - id: poetry-lock

- repo: https://github.com/myint/autoflake
rev: v1.6.0
hooks:
Expand All @@ -17,19 +28,19 @@ repos:
- --in-place
- --remove-duplicate-keys
- --ignore-pass-after-docstring

- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
name: Black
- id: black
name: Black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
#
# Exclude files below from trailing-whitespace checks until we get around fixing them.
# This way we can check that all other files are trailing-whitespace clean in CI.
#
# Exclude files from trailing-whitespace checks until we get around fixing them.
# This way we can check that other files are trailing-whitespace clean in CI.
exclude: |
(?x)^(
mxcubecore/configuration/.*|
Expand All @@ -47,10 +58,8 @@ repos:
mxcubecore/HardwareObjects/ESRF/ID29XRFSpectrum\.py
)$
- id: end-of-file-fixer
#
# Exclude files below from end-of-file-fixer checks until we get around fixing them.
# This way we can check that all other files are end-of-file-fixer clean in CI.
#
# Exclude files from end-of-file-fixer checks until we get around fixing them.
# This way we can check that other files are end-of-file-fixer clean in CI.
exclude: |
(?x)^(
mxcubecore/configuration/.*|
Expand All @@ -60,26 +69,11 @@ repos:
)$
- id: check-case-conflict
- id: check-merge-conflict
# exclude files where underlines are not distinguishable from merge conflicts
# Exclude files where underlines are not distinguishable from merge conflicts.
exclude: /README\.rst$|^docs/.*\.rst$
- id: check-symlinks
- id: check-xml
- id: check-yaml
exclude: ^.drone\.yml
- id: mixed-line-ending
args: ["--fix=lf"]
# - repo: https://github.com/PyCQA/isort
# rev: 5.10.1
# hooks:
# - id: isort
# name: Import Sort
# args:
# - --settings=.
# exclude: (/__init__\.py$|deprecated/|mxcubecore/HardwareObjects/(ALBA|ASLS|DESY|EMBL|ESRF|LNLS|MAXIV|SOLEIL|ANSTO|Gphl|Arinax))
# - repo: https://github.com/PyCQA/flake8
# rev: 4.0.1
# hooks:
# - id: flake8
# name: Flake8
# additional_dependencies: ["flake8-bugbear==22.9.11"]
# exclude: (utils/pyispyb_client/|deprecated/|mxcubecore/HardwareObjects/(ALBA|ASLS|DESY|EMBL|ESRF|LNLS|MAXIV|SOLEIL|ANSTO|Gphl|Arinax))
1 change: 1 addition & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ build:
- "git fetch --unshallow || true"
- "mamba env create --file conda-environment-dev.yml --force"
- "mamba run --name mxcubecore poetry install --only=docs,main"
# yamllint disable-line rule:line-length
- "mamba run --name mxcubecore sphinx-build -T -E -b html -c ./docs/ ./docs/source/ ${READTHEDOCS_OUTPUT}/html/"


Expand Down
8 changes: 8 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

extends: default

rules:
# Match line length to the one set by `black` the Python formatter
line-length:
max: 88
2 changes: 2 additions & 0 deletions conda-environment-dev.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

name: mxcubecore
channels:
- conda-forge
Expand Down
11 changes: 8 additions & 3 deletions mxcubecore/configuration/alba_xaloc13/beamline_config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---

# yamllint disable rule:comments-indentation
# yamllint disable rule:indentation

# FIRST DRAFT of ALAB xaloc13 configuration. TO BE EDITED

# The class to initialise, and init parameters
Expand All @@ -15,8 +20,8 @@ _initialise_class:
# would need those added (e.g. the centring methods)
#
_objects:
# The !!o0map and the lines starting with '- ' give you an *orderd* dictionary
# And thus a reproducible loading order
# The !!o0map and the lines starting with '- ' give you an *orderd* dictionary
# And thus a reproducible loading order
!!omap
# The values are the file paths to the configuration file for the
# object, relative to the configuration file path(s)
Expand Down Expand Up @@ -103,7 +108,7 @@ acquisition_limit_values:
- 6000.0
osc_range: # (degrees)
- -2165.0
- 2165.0
- 2165.0
number_of_images: # (int)
- 1
- 9999
Expand Down
8 changes: 5 additions & 3 deletions mxcubecore/configuration/embl_hh_p14/beamline_config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

# FIRST DRAFT of EMBL P14 configuration. TO BE EDITED

# The class to initialise, and init parameters
Expand Down Expand Up @@ -54,7 +56,7 @@ _objects:
- image_tracking: image-tracking.xml
- gphl_workflow: gphl-workflow.xml
- gphl_connection: gphl-setup.xml
# - centring: centring.xml
# - centring: centring.xml
# Analysis:
- offline_processing: auto-processing.xml
- online_processing: parallel-processing.xml
Expand All @@ -64,8 +66,8 @@ _objects:
- ppu_control: ppu_control.xml
# Non-object attributes:
advanced_methods:
- MeshScan
- XrayCentering
- MeshScan
- XrayCentering
tunable_wavelength: true
disable_num_passes: false
run_online_processing: true
Expand Down
5 changes: 5 additions & 0 deletions mxcubecore/configuration/esrf_id30a2/gphl-setup.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---

# yamllint disable rule:comments
# yamllint disable rule:comments-indentation
# yamllint disable rule:line-length

_initialise_class:
class: mxcubecore.HardwareObjects.Gphl.GphlWorkflowConnection.GphlWorkflowConnection
Expand Down
7 changes: 7 additions & 0 deletions mxcubecore/configuration/esrf_id30a2/gphl-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
---

# yamllint disable rule:comments-indentation
# yamllint disable rule:hyphens
# yamllint disable rule:indentation
# yamllint disable rule:line-length

_initialise_class:
class: mxcubecore.HardwareObjects.Gphl.GphlWorkflow.GphlWorkflow

Expand Down
Loading

0 comments on commit ec23305

Please sign in to comment.