-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor linting + enable via Github workflow (#126)
* Refactor linting + enable via Github workflow While the two previous PRs focused on getting the tests running on public Github runners and updating the supported Python + poetry versions, this PR now fully focuses on code **linting** + **formatting**. This PR: * Delegates all the linting to pre-commit via various hooks (same tools as before but managed by pre-commit) * Lets pre-commit manage the hooks -> reduces the dev dependencies in pyproject.toml to mypy*, pytest*, pre-commit and safety. * Removes darglint as deprecated / discontinued * Updates all the remaining dev dependencies + regenerates poetry.lock * Adds a workflow to run pre-commit for PRs * Updates Makefile targets so that `make help works * Consolidates the many **linting** + **formatting** Makefile targets into just only `make pre-commit` ... the exit code + shown diff tell if it changed something, so that there is now no difference between formatting or linting... just one single make target... thats how many python projects operate nowadays. * Fixes/handles all pre-commit findings * Enable running single hook via pre-commit target
- Loading branch information
Showing
14 changed files
with
749 additions
and
808 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,49 @@ | ||
name: Lint | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
concurrency: | ||
# Concurrency group that uses the workflow name and PR number if available | ||
# or commit SHA as a fallback. If a new build is triggered under that | ||
# concurrency group while a previous build is running it will be canceled. | ||
# Repeated pushes to a PR will cancel all previous builds, while multiple | ||
# merges to master will not cancel. | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-24.04 | ||
strategy: | ||
matrix: | ||
python-version: ['3.10'] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install poetry | ||
run: make poetry-download | ||
|
||
- name: Set up cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
.venv | ||
~/.cache/pre-commit | ||
key: venv-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}-${{ hashFiles('.pre-commit-config.yaml') }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
poetry config virtualenvs.in-project true | ||
make install | ||
- name: Lint | ||
run: | | ||
make pre-commit |
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 |
---|---|---|
@@ -1,44 +1,63 @@ | ||
default_language_version: | ||
python: python3.10 | ||
|
||
default_stages: [commit, push] | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.5.0 | ||
rev: v5.0.0 | ||
hooks: | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
exclude: LICENSE | ||
|
||
- repo: local | ||
exclude: LICENSE.md | ||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v3.19.1 | ||
hooks: | ||
- id: pyupgrade | ||
name: pyupgrade | ||
entry: poetry run pyupgrade --py310-plus | ||
types: [python] | ||
language: system | ||
|
||
- repo: local | ||
args: [--py39-plus] | ||
exclude: hyperliquid/utils/types.py$ | ||
- repo: https://github.com/PyCQA/isort | ||
rev: 6.0.0 | ||
hooks: | ||
- id: isort | ||
name: isort | ||
entry: poetry run isort --settings-path pyproject.toml | ||
types: [python] | ||
language: system | ||
|
||
- repo: local | ||
- repo: https://github.com/psf/black-pre-commit-mirror | ||
rev: 25.1.0 | ||
hooks: | ||
- id: black | ||
name: black | ||
entry: poetry run black --config pyproject.toml | ||
types: [python] | ||
language: system | ||
|
||
- repo: https://github.com/PyCQA/flake8 | ||
rev: 7.1.1 | ||
hooks: | ||
- id: flake8 | ||
# ignoring formatting related lints, which are handled by black | ||
args: ['--ignore=E501,E203,W503'] | ||
- repo: https://github.com/PyCQA/bandit | ||
rev: 1.8.2 | ||
hooks: | ||
- id: bandit | ||
exclude: tests/.*$ | ||
- repo: https://github.com/pylint-dev/pylint | ||
rev: v3.3.4 | ||
hooks: | ||
- id: pylint | ||
exclude: examples/.*$ | ||
- repo: https://github.com/python-poetry/poetry | ||
rev: 2.0.1 | ||
hooks: | ||
- id: poetry-check | ||
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt | ||
rev: 0.2.3 | ||
hooks: | ||
- id: yamlfmt | ||
args: [--mapping, '2', --offset, '2', --sequence, '4', --implicit_start] | ||
files: .pre-commit-config.yaml|\.github/workflows/.*\.yml$ | ||
- repo: https://github.com/python-jsonschema/check-jsonschema | ||
rev: 0.31.1 | ||
hooks: | ||
- id: check-github-workflows | ||
- repo: local | ||
hooks: | ||
- id: codestyle | ||
name: codestyle | ||
entry: make codestyle | ||
types: [python] | ||
- id: mypy | ||
name: mypy | ||
entry: poetry run mypy --config-file pyproject.toml ./ | ||
pass_filenames: false | ||
language: system | ||
- repo: meta | ||
hooks: | ||
- id: check-hooks-apply | ||
- id: check-useless-excludes |
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 |
---|---|---|
@@ -1,74 +1,44 @@ | ||
#* Variables | ||
# Define the shell to use when executing commands | ||
SHELL := /usr/bin/env bash -o pipefail -o errexit | ||
|
||
#* Lockfile handling | ||
lockfile-update: | ||
help: | ||
@@grep -h '^[a-zA-Z]' $(MAKEFILE_LIST) | awk -F ':.*?## ' 'NF==2 {printf " %-22s%s\n", $$1, $$2}' | sort | ||
|
||
lockfile-update: ## Update poetry.lock | ||
poetry lock -n | ||
|
||
lockfile-update-full: | ||
lockfile-update-full: ## Fully regenerate poetry.lock | ||
poetry lock -n --regenerate | ||
|
||
#* Installation | ||
install: | ||
install: ## Install dependencies from poetry.lock | ||
poetry install -n | ||
|
||
install-types: | ||
install-types: ## Find and install additional types for mypy | ||
poetry run mypy --install-types --non-interactive ./ | ||
|
||
#* Poetry | ||
poetry-download: | ||
poetry-download: ## Download and install poetry | ||
curl -sSL https://install.python-poetry.org | python - | ||
|
||
#* Formatters | ||
codestyle: | ||
poetry run pyupgrade --exit-zero-even-if-changed --py39-plus **/*.py | ||
poetry run isort --settings-path pyproject.toml ./ | ||
poetry run black --config pyproject.toml ./ | ||
lint: pre-commit ## Alias for the pre-commit target | ||
|
||
formatting: codestyle | ||
pre-commit: ## Run linters + formatters via pre-commit, run "make pre-commit hook=black" to run only black | ||
poetry run pre-commit run --all-files --verbose --show-diff-on-failure --color always $(hook) | ||
|
||
#* Linting | ||
test: | ||
test: ## Run tests with pytest | ||
poetry run pytest -c pyproject.toml tests/ | ||
|
||
check-codestyle: | ||
poetry run isort --diff --check-only --settings-path pyproject.toml ./ | ||
poetry run black --diff --check --config pyproject.toml ./ | ||
poetry run darglint --verbosity 2 hyperliquid tests | ||
|
||
check: | ||
poetry run mypy --config-file pyproject.toml ./ | ||
|
||
check-safety: | ||
poetry check | ||
check-safety: ## Run safety checks on dependencies | ||
poetry run safety check --full-report | ||
poetry run bandit -ll --recursive hyperliquid tests | ||
|
||
lint: test check-codestyle mypy check-safety | ||
update-dev-deps: ## Update development dependencies to latest versions | ||
poetry add -D mypy@latest pre-commit@latest pytest@latest safety@latest coverage@latest pytest-cov@latest | ||
poetry run pre-commit autoupdate | ||
|
||
update-dev-deps: | ||
poetry add -D bandit@latest darglint@latest "isort[colors]@latest" mypy@latest pre-commit@latest pydocstyle@latest pylint@latest pytest@latest pyupgrade@latest safety@latest coverage@latest coverage-badge@latest pytest-cov@latest | ||
poetry add -D --allow-prereleases black@latest | ||
|
||
#* Cleaning | ||
pycache-remove: | ||
cleanup: ## Cleanup project | ||
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf | ||
|
||
dsstore-remove: | ||
find . | grep -E ".DS_Store" | xargs rm -rf | ||
|
||
mypycache-remove: | ||
find . | grep -E ".mypy_cache" | xargs rm -rf | ||
|
||
ipynbcheckpoints-remove: | ||
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf | ||
|
||
pytestcache-remove: | ||
find . | grep -E ".pytest_cache" | xargs rm -rf | ||
|
||
build-remove: | ||
rm -rf build/ | ||
|
||
cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove pytestcache-remove | ||
|
||
.PHONY: all $(MAKECMDGOALS) |
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 |
---|---|---|
|
@@ -104,4 +104,3 @@ paths: | |
s: "BTC" | ||
t: 1681923600000 | ||
v: "0.98639" | ||
|
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 |
---|---|---|
|
@@ -64,4 +64,3 @@ paths: | |
{ "px": "20300", "sz": "3", "n": 3 } | ||
] | ||
] | ||
|
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
Oops, something went wrong.