-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from komish/py-codestyle-tooling
Add Python Code Style Enforcement to GitHub Actions
- Loading branch information
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Python Style | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
# Only trigger on core script changes | ||
- 'scripts/**.py' | ||
|
||
jobs: | ||
enforce: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Set up Python 3.x Part 1 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.9" | ||
- name: Install style tooling | ||
working-directory: scripts | ||
run: make venv.codestyle | ||
- name: Run formatter | ||
working-directory: scripts | ||
run: make ci.format | ||
# Temporarily auto-pass linting until we are able to manually review and | ||
# address. | ||
- name: Run linter | ||
working-directory: scripts | ||
run: make lint || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
PY_BIN ?= python3 | ||
|
||
# The virtualenv containing code style tools. | ||
VENV_CODESTYLE = venv.codestyle | ||
VENV_CODESTYLE_BIN = $(VENV_CODESTYLE)/bin | ||
|
||
# The virtualenv containing our CI scripts | ||
VENV_TOOLS = venv.tools | ||
VENV_TOOLS_BIN = $(VENV_TOOLS)/bin | ||
|
||
# This is what we pass to git ls-files. | ||
LS_FILES_INPUT_STR ?= 'src/*.py' | ||
|
||
.PHONY: default | ||
default: format lint | ||
|
||
# The same as format, but will throw a non-zero exit code | ||
# if the formatter had to make changes. | ||
.PHONY: ci.format | ||
ci.format: format | ||
git diff --exit-code | ||
|
||
venv.codestyle: | ||
$(MAKE) venv.codestyle.always-reinstall | ||
|
||
# This target will always install the codestyle venv. | ||
# Useful for development cases. | ||
.PHONY: venv.codestyle.always-reinstall | ||
venv.codestyle.always-reinstall: | ||
$(PY_BIN) -m venv $(VENV_CODESTYLE) | ||
./$(VENV_CODESTYLE_BIN)/pip install --upgrade \ | ||
black \ | ||
ruff | ||
|
||
.PHONY: format | ||
format: venv.codestyle | ||
./$(VENV_CODESTYLE_BIN)/black \ | ||
--verbose \ | ||
$$(git ls-files $(LS_FILES_INPUT_STR)) | ||
|
||
.PHONY: lint | ||
lint: venv.codestyle | ||
./$(VENV_CODESTYLE_BIN)/ruff \ | ||
check \ | ||
$$(git ls-files $(LS_FILES_INPUT_STR)) | ||
|
||
venv.tools: | ||
$(MAKE) venv.tools.always-reinstall | ||
|
||
# This target will always install the tools at the venv. | ||
# Useful for development cases. | ||
.PHONY: venv.tools.always-reinstall | ||
venv.tools.always-reinstall: | ||
$(PY_BIN) -m venv $(VENV_TOOLS) | ||
./$(VENV_TOOLS_BIN)/pip install -r requirements.txt | ||
./$(VENV_TOOLS_BIN)/python setup.py install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ignore = [ | ||
"E402", # import ordering (komish): import ordering isn't handled by Black so we need to handle this manually. | ||
"E501", # line length (komish): line length is not enforced by Black so we need to handle these manually. | ||
] |