From e2328648bf051886a3bbb652cb3e15bdc33fe495 Mon Sep 17 00:00:00 2001 From: pdemp1729 Date: Sun, 8 Jan 2023 00:51:32 +0000 Subject: [PATCH] Add isort to code check - We use the 'black' profile within the isort config to make isort compatible with black, which is also being used in this docker image. --- Dockerfile | 2 ++ README.md | 7 ++++--- config/.isort.cfg | 3 +++ entrypoint.sh | 3 +++ requirements.txt | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 config/.isort.cfg diff --git a/Dockerfile b/Dockerfile index 170ab69..5160a63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,11 @@ COPY requirements.txt requirements.txt RUN pip install -r requirements.txt COPY config/.flake8 . +COPY config/.isort.cfg . COPY entrypoint.sh /usr/local/bin ENV DEFAULT_FLAKE8_CONFIG=${APP_ROOT}/.flake8 +ENV DEFAULT_ISORT_CONFIG=${APP_ROOT}/.isort.cfg VOLUME ${CODE_DIR} WORKDIR ${CODE_DIR} diff --git a/README.md b/README.md index d306b49..76d0cac 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # docker-code-quality -Docker image for python code quality +Docker image for checking python code quality ## Usage -After building the docker image using `./docker.sh build` it can be used to run [flake8](https://flake8.pycqa.org/en/6.0.0/index.html) -and [black](https://black.readthedocs.io/en/stable/index.html) (in check mode) on a codebase of your choosing. +After building the docker image using `./docker.sh build` it can be used to run [flake8](https://flake8.pycqa.org/en/6.0.0/index.html), +[black](https://black.readthedocs.io/en/stable/index.html) and [isort](https://pycqa.github.io/isort/index.html) +(in check mode) on a codebase of your choosing. In particular, assuming you're in the directory of the code you want to check, simply run ``` diff --git a/config/.isort.cfg b/config/.isort.cfg new file mode 100644 index 0000000..28ee479 --- /dev/null +++ b/config/.isort.cfg @@ -0,0 +1,3 @@ +[settings] +py_version=39 +profile=black diff --git a/entrypoint.sh b/entrypoint.sh index c31719d..2f87c81 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,5 +3,8 @@ echo "Running flake8..." flake8 --config=$DEFAULT_FLAKE8_CONFIG $CODE_DIR +echo "Running isort --check" +isort --settings-file=$DEFAULT_ISORT_CONFIG --src=$CODE_DIR --check $CODE_DIR + echo "Running black --check..." black --target-version py39 --check $CODE_DIR diff --git a/requirements.txt b/requirements.txt index b0355e9..4a0d5b5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ black==22.12.0 flake8==6.0.0 +isort==5.11.1