Skip to content

Commit

Permalink
add black formatting pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
arbakker committed Aug 2, 2023
1 parent 5f73023 commit 6c72a79
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
38 changes: 38 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

print_message() {
padding_char=">"
message=$1
indent_level="${2:-1}"
level=${3:-NOCOLOR}
prepend_newline=${4:-false}
case "$level" in
"INFO")
color='\033[0;32m'
;;
"WARNING")
color='\033[0;33m'
;;
"ERROR")
color='\033[0;31m'
;;
*)
color='\033[0;37m'
;;
esac
if [[ $prepend_newline == true ]]; then echo ""; fi
printf "${color}%s %s\n\033[0;37m" $(printf "${padding_char}%.0s" $(seq 1 "$indent_level")) "$message"
}

print_message "pre-commit - running Black formatting" 1 "" true

if ! command -v black &> /dev/null
then
print_message "ERROR: black could not be found" 2 "ERROR" false
exit 1
fi

FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g' | grep -E "\.py$")
[ -z "$FILES" ] && exit 0
echo "$FILES" | xargs black --stdin-filename "{}"
echo "$FILES" | xargs git add
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.gitconfig
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ Design rues. Examples of these are:
parameter.
- with additional scenarios for other combinations.

## Develop

To install from source requires minimum version of pip: `23.2.1`.

Install dev dependencies with:

```sh
pip install ".[dev]"
```

Install enable precommit hook with:

```sh
git config -f .gitconfig core.hooksPath .githooks
```

## Install

```bash
Expand All @@ -39,7 +55,7 @@ pip3 install .
ct-api
```

## Exanple operaties
## Example operaties

```bash
# Landingpage
Expand Down
11 changes: 9 additions & 2 deletions coordinates_transformation_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,19 @@ async def transform():


def custom_openapi():
oas_file_resource = (impresources.files(assets) / "openapi.yaml")
oas_file_resource = impresources.files(assets) / "openapi.yaml"
with oas_file_resource.open("rb") as oas_file:
return yaml.load(oas_file, yaml.SafeLoader)


app.openapi = custom_openapi


def start():
uvicorn.run("coordinates_transformation_api.main:app", workers=2, host="0.0.0.0", port=8000, reload=True)
uvicorn.run(
"coordinates_transformation_api.main:app",
workers=2,
host="0.0.0.0",
port=8000,
reload=True,
)
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ requires-python = ">=3.11.4"
dynamic = ["version"]

[project.optional-dependencies]
dev = ["black", "mypy", "autoflake", "isort"]
dev = ["black"]
# TODO: add/enable other formatting/linting tools
# "mypy", "autoflake", "isort"

[build-system]
build-backend = "setuptools.build_meta"
Expand Down

0 comments on commit 6c72a79

Please sign in to comment.