Skip to content

Commit

Permalink
build: add linting workflow
Browse files Browse the repository at this point in the history
PR: #2
  • Loading branch information
slaclau committed Jul 19, 2024
1 parent f5fb58b commit 98574b8
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 1 deletion.
175 changes: 175 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: "lint"

on:
workflow_call:

jobs:
flake8:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install python packages
run: |
pip install -e .[lint]
- name: flake8
if: always()
run: |
flake8 src --format=json >> flake8.json
- name: flake8 report
if: always()
run: |
python scripts/flake82md.py flake8.json "flake8 report" >> flake8.md
cat flake8.md >> $GITHUB_STEP_SUMMARY
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: flake8
path: |
flake8.json
flake8.md
mypy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install python packages
run: |
pip install -e .[lint]
- name: mypy
if: always()
run: |
mypy --strict src | mypy-json-report parse --output-file mypy.json
exit ${PIPESTATUS[0]}
- name: mypy report
if: always()
run: |
python scripts/mypy2md.py mypy.json "mypy report" >> mypy.md
cat mypy.md >> $GITHUB_STEP_SUMMARY
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: mypy
path: |
mypy.json
mypy.md
black:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install python packages
run: |
pip install -e .[lint]
- name: black
if: always()
run: |
echo "# black report" >> black.md
echo "These files have not been formatted" >> black.md
black --check src &>> black.md
- name: black report
if: always()
run: |
sed -i "s/would reformat \/home\/runner\/work\/plotly-gtk\/plotly-gtk\///g" black.md
sed -i "s/_/\\_/g" black.md
cat black.md >> $GITHUB_STEP_SUMMARY
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: black
path: black.md

isort:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install python packages
run: |
pip install -e .[lint]
- name: isort
if: always()
run: |
echo "# isort report" >> isort.md
echo "These files have not been formatted" >> isort.md
isort -c src &>> isort.md
- name: isort report
if: always()
run: |
sed -i "s/\/home\/runner\/work\/plotly-gtk\/plotly-gtk\///g" isort.md
cat isort.md >> $GITHUB_STEP_SUMMARY
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: isort
path: isort.md
deptry:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install python packages
run: |
pip install -e .[lint]
- name: deptry
run: |
deptry src --json-output deptry.json
- name: deptry report
if: always()
run: |
python scripts/deptry2md.py deptry.json "deptry report" >> deptry.md
cat deptry.md >> $GITHUB_STEP_SUMMARY
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: deptry
path: |
deptry.json
deptry.md
2 changes: 2 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ permissions:
jobs:
test:
uses: ./.github/workflows/test.yaml
lint:
uses: ./.github/workflows/lint.yaml
# Build job
build-docs:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
_version.py

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ build-backend = "setuptools.build_meta"

[project.optional-dependencies]
doc = ["pylint", "sphinx", "sphinx-pyreverse", "pydata-sphinx-theme", "sphinx-rtd-theme", "plotly"]
lint = ["black", "isort", "flake8", "flake8-pylint", "flake8-json", "flake8-bugbear", "mypy", "mypy-json-report", "pygobject-stubs", "deptry"]
test = ["plotly", "pytest", "pillow", "selenium","pytest-subtests", "pytest-cov", "pytest-html"]
dev = ["plotly-gtk[doc, test]"]
dev = ["plotly-gtk[doc, lint, test]"]

[tool.setuptools.dynamic]
readme = {file = "README.md", content-type = "text/markdown"}
Expand Down Expand Up @@ -108,3 +109,5 @@ docstring_style = "numpy"
[tool.coverage.run]
omit = ["test/demo"]

[tool.deptry]
pep621_dev_dependency_groups = ["doc", "lint", "test"]
18 changes: 18 additions & 0 deletions scripts/deptry2md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
import sys

codes_dict={"DEP002": "Project should not contain unused dependencies"}

with open(sys.argv[1]) as f:
data = json.load(f)
if len(sys.argv) > 1:
print(f"# {sys.argv[2]}")
codes = list({d["error"]["code"] for d in data})
for code in codes:
if code in codes_dict:
print(f"## {code}: {codes_dict[code]}")
else:
print(f"# {code}")
modules = [d["module"] for d in data if d["error"]["code"] == code]
for module in modules:
print(module)
46 changes: 46 additions & 0 deletions scripts/flake82md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json
import sys

with open(sys.argv[1]) as f:
data = json.load(f)
if len(sys.argv) > 1:
print(f"# {sys.argv[2]}")
n = 0
errors = {}
for i in data:
n += len(data[i])
errors[i] = len(data[i])
print(f"{len(data)} files checked, {n} issues found")
print("| File | Issues |")
print("| - | - |")
for i in errors:
print(f"| {i.replace("_", "\_")} | {errors[i]} |")
for i in data:
if len(data[i]) > 0:
print(f"## {i.replace("_", "\_")}:")
print(f"{len(data[i])} issues found")
print("The following code(s) occurred in this file")
print("| Occurences | Code | Meaning |")
print("| - | - | - |")
codes = sorted(set(d["code"] for d in data[i]))
codeCount = {}
codeText = {}
for line in data[i]:
codeCount[line["code"]] = codeCount.get(line["code"], 0) + 1
codeText[line["code"]] = line["text"]
for code in codes:
print(f"| {codeCount[code]} | {code} | {codeText[code]} |")
print()
count = 0
for line in data[i]:
count += 1
print(
f'{line["code"]}:{line["line_number"]}:{line["column_number"]}: {line["text"]}'
)
print("```python")
if line["physical_line"] is not None:
print(line["physical_line"].strip())
print("```")
if count > 100:
print(f"Truncated at {count} errors")
break
19 changes: 19 additions & 0 deletions scripts/mypy2md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
import sys

with open(sys.argv[1]) as f:
data = json.load(f)
if len(sys.argv) > 1:
print(f"# {sys.argv[2]}")
n = 0
for i in data:
for line in data[i]:
n += data[i][line]
print(f"{len(data)} files checked, {n} issues found")
for i in data:
print(f"## {i}")
print("| Occurrences | Message |")
print("| - | - |")
for line in data[i]:
print(f"| {data[i][line]} | {line} |")
print()

0 comments on commit 98574b8

Please sign in to comment.