Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 46 additions & 0 deletions .github/workflows/autolint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Autolint with black

on:
push:
branches:
- main

jobs:

lint-autofix:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false # Needed for manual push

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black

- name: Auto-fix with black
run: black --line-length 120 .

- name: Commit and push changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin ${{ github.head_ref }}
git checkout ${{ github.head_ref }}
git add .
if ! git diff --cached --quiet; then
git commit -m "chore: auto-fix Python lint issues"
git rebase origin/${{ github.head_ref }}
git push https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }} HEAD:refs/heads/${{ github.head_ref }}
fi
env:
# Required if using a token for push
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126 changes: 126 additions & 0 deletions .github/workflows/code_style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Pylint

on:
pull_request:

permissions:
contents: read
pull-requests: write
issues: write
checks: write

jobs:
pylint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint jq
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Run Pylint and save JSON
run: |
pylint --rcfile=.pylintrc $(git ls-files '*.py') \
--output-format=json > pylint_output.json || true

- name: Upload Pylint report
uses: actions/upload-artifact@v4
with:
name: pylint-report
path: pylint_output.json

- name: Generate Pylint PR summary (collapsible)
if: always()
run: |
echo "### 🧹 Pylint Summary" > lint_summary.md

ERRORS=$(jq '[.[] | select(.type == "error" or .type == "fatal")] | length' pylint_output.json)
WARNINGS=$(jq '[.[] | select(.type == "warning")] | length' pylint_output.json)
REFACTOR=$(jq '[.[] | select(.type == "refactor")] | length' pylint_output.json)
SCORE=$(pylint --rcfile=config/.pylintrc $(git ls-files '*.py') \
| grep "Your code has been rated" \
| awk '{print $7}' \
| cut -d'/' -f1 || echo "N/A")

echo "" >> lint_summary.md
echo "🧾 **Score:** $SCORE" >> lint_summary.md
echo "❌**Errors:** $ERRORS" >> lint_summary.md
echo "⚠️**Warnings:** $WARNINGS" >> lint_summary.md
echo "🛠️**Refactors:** $REFACTOR" >> lint_summary.md
echo "" >> lint_summary.md

# Collapsible section
echo "<details>" >> lint_summary.md
echo "<summary>Show all Pylint messages</summary>" >> lint_summary.md
echo "" >> lint_summary.md
echo '```' >> lint_summary.md

# Include all issues (or limit to first N)
jq -c '.[]' pylint_output.json | while IFS= read -r item; do
path=$(echo "$item" | jq -r '.path')
line=$(echo "$item" | jq -r '.line')
col=$(echo "$item" | jq -r '.column // 1')
type=$(echo "$item" | jq -r '.type | ascii_upcase')
msg=$(echo "$item" | jq -r '.message')

case "$type" in
ERROR) emoji="❌" ;;
FATAL) emoji="💀" ;;
WARNING) emoji="⚠️" ;;
REFACTOR) emoji="🛠️" ;;
CONVENTION) emoji="📏" ;;
INFO) emoji="ℹ️" ;;
*) emoji="" ;;
esac

# Detect line or range
if [[ "$msg" =~ "Similar lines" ]] || [[ "$msg" =~ "Similar functions" ]]; then

code=$(echo "$msg" | awk 'NR>3')
msg=$(echo "$msg" | awk 'NR<=3')
else
code=$(sed -n "${line}p" "$path")
fi

# # Escape backticks in code
# code=${code//'`'/\`}
# echo "---------------"
# echo "$code"

# Append to Markdown
echo "**$path:$line:$col** $emoji $type: *$msg*" >> lint_summary.md
echo "" >> lint_summary.md
echo '```python' >> lint_summary.md
echo "$code" >> lint_summary.md
echo '```' >> lint_summary.md
echo "" >> lint_summary.md
done
echo "_Inline annotations are also visible in the PR files tab._" >> lint_summary.md
echo "_Full report uploaded as an artifact **pylint-report**._" >> lint_summary.md

- name: Post Pylint summary as PR comment
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body-file: lint_summary.md

- name: Run lint action
uses: wearerequired/lint-action@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
pylint: true
continue_on_error: true
133 changes: 133 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.idea/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
.venv/
.vscode/
.codex
12 changes: 12 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[MESSAGES CONTROL]
disable=C0114, C0116

[REPORTS]
output-format=colorized
score = yes

[FORMAT]
max-line-length=120

[MASTER]
exit-zero = yes
Loading
Loading