Skip to content

Commit ff343dd

Browse files
committed
Add Linting Infrastructure
Signed-off-by: VaniHaripriya <vmudadla@redhat.com>
1 parent 00758af commit ff343dd

File tree

8 files changed

+401
-0
lines changed

8 files changed

+401
-0
lines changed

.github/workflows/lint.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
name: Lint
3+
4+
on:
5+
pull_request: {}
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
lint:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
pull-requests: read
17+
18+
steps:
19+
- name: Check out repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.10"
26+
27+
- name: Install Python tooling
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install black pydocstyle yamllint
31+
32+
- name: Set up Node
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: "20"
36+
37+
- name: Install markdownlint-cli
38+
run: npm install -g markdownlint-cli
39+
40+
- name: Determine changed files
41+
id: changed-files
42+
uses: tj-actions/changed-files@v44
43+
with:
44+
files_yaml: |
45+
python:
46+
- "**/*.py"
47+
markdown:
48+
- "**/*.md"
49+
yaml:
50+
- "**/*.yml"
51+
- "**/*.yaml"
52+
53+
- name: Run Black (changed files)
54+
if: steps.changed-files.outputs.python_any_changed == 'true'
55+
run: |
56+
black --config pyproject.toml --check ${{ steps.changed-files.outputs.python_all_changed_files }}
57+
58+
- name: Run pydocstyle (changed files)
59+
if: steps.changed-files.outputs.python_any_changed == 'true'
60+
run: |
61+
pydocstyle --config=pyproject.toml ${{ steps.changed-files.outputs.python_all_changed_files }}
62+
63+
- name: Run custom import guard
64+
if: steps.changed-files.outputs.python_any_changed == 'true'
65+
run: |
66+
python scripts/check_imports.py \
67+
--config scripts/import_exceptions.json \
68+
${{ steps.changed-files.outputs.python_all_changed_files }}
69+
70+
- name: Run markdownlint (changed files)
71+
if: steps.changed-files.outputs.markdown_any_changed == 'true'
72+
run: |
73+
markdownlint -c .markdownlint.json ${{ steps.changed-files.outputs.markdown_all_changed_files }}
74+
75+
- name: Run yamllint (changed files)
76+
if: steps.changed-files.outputs.yaml_any_changed == 'true'
77+
run: |
78+
yamllint -c .yamllint.yml ${{ steps.changed-files.outputs.yaml_all_changed_files }}

.markdownlint.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"default": true,
3+
"MD013": {
4+
"line_length": 120,
5+
"heading_line_length": 120,
6+
"code_block_line_length": 160
7+
},
8+
"MD033": false,
9+
"MD041": false
10+
}
11+

.pre-commit-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
repos:
3+
- repo: https://github.com/psf/black
4+
rev: 24.4.2
5+
hooks:
6+
- id: black
7+
name: black
8+
args: ["--config", "pyproject.toml"]
9+
- repo: https://github.com/PyCQA/pydocstyle
10+
rev: 6.3.0
11+
hooks:
12+
- id: pydocstyle
13+
name: pydocstyle
14+
args: ["--config=pyproject.toml"]
15+
- repo: https://github.com/igorshubovych/markdownlint-cli
16+
rev: v0.39.0
17+
hooks:
18+
- id: markdownlint
19+
args: ["-c", ".markdownlint.json"]
20+
- repo: https://github.com/adrienverge/yamllint
21+
rev: v1.35.1
22+
hooks:
23+
- id: yamllint
24+
args: ["-c", ".yamllint.yml"]
25+
- repo: local
26+
hooks:
27+
- id: import-guard
28+
name: import-guard
29+
entry: python scripts/check_imports.py
30+
language: system
31+
types: [python]

.yamllint.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
extends: default
3+
rules:
4+
line-length:
5+
max: 120
6+
level: warning
7+
truthy:
8+
level: warning

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PYTHON_SOURCES := $(shell find components pipelines third_party scripts -name "*.py")
2+
MARKDOWN_SOURCES := $(shell find . -name "*.md" -not -path "./.git/*" -not -path "./.venv/*")
3+
YAML_SOURCES := $(shell find . -name "*.yml" -o -name "*.yaml" -not -path "./.git/*" -not -path "./.venv/*")
4+
5+
BLACK ?= black
6+
PYDOCSTYLE ?= pydocstyle
7+
MARKDOWNLINT ?= markdownlint
8+
YAMLLINT ?= yamllint
9+
PYTHON ?= python3
10+
11+
.PHONY: format lint lint-black lint-docstrings lint-markdown lint-yaml lint-imports check-imports
12+
13+
format:
14+
$(BLACK) --config pyproject.toml $(PYTHON_SOURCES)
15+
16+
lint: lint-black lint-docstrings lint-markdown lint-yaml lint-imports
17+
18+
lint-black:
19+
$(BLACK) --config pyproject.toml --check $(PYTHON_SOURCES)
20+
21+
lint-docstrings:
22+
$(PYDOCSTYLE) --config=pyproject.toml $(PYTHON_SOURCES)
23+
24+
lint-markdown:
25+
$(MARKDOWNLINT) -c .markdownlint.json $(MARKDOWN_SOURCES)
26+
27+
lint-yaml:
28+
$(YAMLLINT) -c .yamllint.yml $(YAML_SOURCES)
29+
30+
lint-imports:
31+
$(PYTHON) scripts/check_imports.py components pipelines third_party scripts
32+
33+
check-imports: lint-imports
34+

pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[tool.black]
2+
line-length = 120
3+
target-version = ["py310"]
4+
include = '\.pyi?$'
5+
exclude = '''
6+
/(
7+
\.git
8+
| \.venv
9+
| build
10+
| dist
11+
| __pycache__
12+
| node_modules
13+
| .*/_generated/
14+
)/
15+
'''
16+
17+
[tool.pydocstyle]
18+
convention = "google"
19+
add_ignore = ["D100", "D104"]
20+
match_dir = "(?!\\.|build|dist|\\.venv).*"

0 commit comments

Comments
 (0)