Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Adds ruff (#21)
Browse files Browse the repository at this point in the history
* Adds ruff

* Removes bandit

* Fixes mypy
  • Loading branch information
yxtay authored Dec 4, 2023
1 parent be47ed8 commit 5c84261
Show file tree
Hide file tree
Showing 14 changed files with 1,016 additions and 2,284 deletions.
127 changes: 61 additions & 66 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,73 +1,68 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 # Use the ref you want to point at
hooks:
# endings
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix, lf]
- id: trailing-whitespace
args: [--markdown-linebreak-ext, md]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 # Use the ref you want to point at
hooks:
# endings
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix, lf]
- id: trailing-whitespace
args: [--markdown-linebreak-ext, md]

# files
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-symlinks
- id: destroyed-symlinks
- id: fix-byte-order-marker
# files
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-symlinks
- id: destroyed-symlinks
- id: fix-byte-order-marker

# git
- id: check-added-large-files
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: no-commit-to-branch
- id: forbid-new-submodules
# git
- id: check-added-large-files
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: no-commit-to-branch
- id: forbid-new-submodules

# python
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: debug-statements
# - id: double-quote-string-fixer # conflicts with black
- id: fix-encoding-pragma
args: [--remove]
- id: name-tests-test
- id: requirements-txt-fixer
# python
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: debug-statements
# - id: double-quote-string-fixer # conflicts with black
- id: fix-encoding-pragma
args: [--remove]
- id: name-tests-test
- id: requirements-txt-fixer

# configs
- id: check-json
- id: pretty-format-json
- id: check-toml
- id: check-xml
- id: check-yaml
# - id: sort-simple-yaml # must specify files to check
# files: "^$"
# args: [--filenames, ""]
# - id: file-contents-sorter # must specify files to check
# files: "^$"
# args: [--filenames, ""]
# configs
- id: check-json
- id: pretty-format-json
- id: check-toml
- id: check-xml
- id: check-yaml
# - id: sort-simple-yaml # must specify files to check
# files: "^$"
# args: [--filenames, ""]
# - id: file-contents-sorter # must specify files to check
# files: "^$"
# args: [--filenames, ""]

# security
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
# security
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: v0.0.265
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: [-lll, -iii]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: v0.1.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
33 changes: 20 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN useradd --create-home --uid ${UID} --user-group ${USER}

# set up environment
ARG VIRTUAL_ENV=${HOME}/.venv
ENV PATH=${VIRTUAL_ENV}/bin:${HOME}/.local/bin:${PATH} \
ENV PATH=${VIRTUAL_ENV}/bin:${PATH} \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1

Expand All @@ -24,28 +24,35 @@ ENV PATH=${VIRTUAL_ENV}/bin:${HOME}/.local/bin:${PATH} \
##
FROM base AS dev

RUN target=/var/cache/apt \
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean && \
apt-get update \
&& apt-get install --no-install-recommends -y \
build-essential \
curl \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*

ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_COMPILE=1 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=0

# set up python
WORKDIR ${HOME}
COPY pyproject.toml poetry.lock ./
RUN --mount=type=cache,target=${HOME}/.cache/pypoetry \
curl -sSL https://install.python-poetry.org | python \
&& poetry config virtualenvs.in-project true \
WORKDIR ${HOME}/app
COPY --chown=${USER}:${USER} pyproject.toml poetry.lock ./
RUN --mount=type=cache,target=${HOME}/.cache/pip \
--mount=type=cache,target=${HOME}/.cache/pypoetry \
pip install poetry \
&& python -m venv ${VIRTUAL_ENV} \
&& poetry install --only main --no-root \
&& chown -R ${USER}:${USER} ${HOME} \
&& python --version \
&& poetry show

# set up project
USER ${USER}
WORKDIR ${HOME}/app
COPY configs configs
COPY src src
COPY --chown=${USER}:${USER} configs configs
COPY --chown=${USER}:${USER} src src

EXPOSE 8000
ARG ENVIRONMENT=dev
Expand All @@ -61,7 +68,7 @@ FROM base AS prod
USER ${USER}
WORKDIR ${HOME}/app
COPY --from=dev --chown=${USER}:${USER} ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY --from=dev ${HOME}/app ${HOME}/app
COPY --from=dev --chown=${USER}:${USER} ${HOME}/app ${HOME}/app

EXPOSE 8000
ARG ENVIRONMENT=prod
Expand Down
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ help: ## print help message

.PHONY: deps-install
deps-install: ## install dependencies
python -m pip install poetry
python -m poetry install --no-root
python -m pre_commit install
poetry install --no-root
python -m pre_commit install --install-hooks

.PHONY: deps-install-ci
deps-install-ci:
Expand All @@ -45,15 +44,15 @@ deps-install-ci:

.PHONY: deps-update
deps-update:
python -m poetry update
python -m poetry export --format requirements.txt --output requirements.txt --without-hashes
poetry update
poetry export --format requirements.txt --output requirements.txt --without-hashes
python -m pre_commit autoupdate

requirements.txt: poetry.lock
python -m poetry export --format requirements.txt --output requirements.txt --without-hashes
poetry export --format requirements.txt --output requirements.txt --without-hashes

requirements-dev.txt: poetry.lock
python -m poetry export --with dev --format requirements.txt --output requirements-dev.txt --without-hashes
poetry export --with dev --format requirements.txt --output requirements-dev.txt --without-hashes

## checks

Expand All @@ -68,7 +67,6 @@ lint:
python -m ruff check .
python -m isort . --check --diff
python -m black $(SOURCE_DIR) $(TEST_DIR) --diff
python -m bandit -r $(SOURCE_DIR) -lll -iii
python -m mypy $(SOURCE_DIR)

.PHONY: test
Expand Down
Loading

0 comments on commit 5c84261

Please sign in to comment.