Skip to content

Commit

Permalink
Add formatting tools (#31)
Browse files Browse the repository at this point in the history
* Add formatting tools

Signed-off-by: Martin Hickey <[email protected]>

* Update after review

Review comment:
#31 (review)

Signed-off-by: Martin Hickey <[email protected]>

---------

Signed-off-by: Martin Hickey <[email protected]>
  • Loading branch information
hickeyma authored Feb 13, 2024
1 parent 5b895c4 commit ac597d8
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
*.egg-info
*.pyc
__pycache__
.coverage
.coverage.*
durations/*
coverage*.xml
dist
htmlcov
build
test

# IDEs
.vscode/
.idea/

# Env files
.env

# Virtual Env
venv/
.venv/

# Mac personalization files
*.DS_Store

# Tox envs
.tox
10 changes: 10 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[settings]
profile=black
from_first=true
import_heading_future=Future
import_heading_stdlib=Standard
import_heading_thirdparty=Third Party
import_heading_firstparty=First Party
import_heading_localfolder=Local
known_firstparty=
known_localfolder=tuning
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
exclude: imports
- repo: https://github.com/PyCQA/isort
rev: 5.11.5
hooks:
- id: isort
exclude: imports
23 changes: 23 additions & 0 deletions scripts/fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

pre-commit run --all-files
RETURN_CODE=$?

function echoWarning() {
LIGHT_YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${LIGHT_YELLOW}${1}${NC}"
}

if [ "$RETURN_CODE" -ne 0 ]; then
if [ "${CI}" != "true" ]; then
echoWarning "☝️ This appears to have failed, but actually your files have been formatted."
echoWarning "Make a new commit with these changes before making a pull request."
else
echoWarning "This test failed because your code isn't formatted correctly."
echoWarning 'Locally, run `make run fmt`, it will appear to fail, but change files.'
echoWarning "Add the changed files to your commit and this stage will pass."
fi

exit $RETURN_CODE
fi
3 changes: 3 additions & 0 deletions setup_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pre-commit>=3.0.4,<4.0
pydeps>=1.12.12,<2
tox>=4.4.2,<5
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tox]
envlist = fmt

[testenv:fmt]
description = format with pre-commit
commands = ./scripts/fmt.sh
allowlist_externals = ./scripts/fmt.sh

0 comments on commit ac597d8

Please sign in to comment.