Compare commits

...

3 commits

Author SHA1 Message Date
Benjamin Renard 67125661fd
.pre-commit-pylint: auto install pylint in venv and poetry env if missing 2024-02-13 13:41:35 +01:00
Benjamin Renard bdbe82c3ea
Dockerfile: set /src as git safe directory for root 2024-02-13 13:35:27 +01:00
Benjamin Renard bff5e318f5
Update README file 2024-02-13 13:34:45 +01:00
3 changed files with 24 additions and 8 deletions

View file

@ -5,11 +5,13 @@ PWD=`pwd`
if [ -d "$PWD/venv" ]
then
echo "Run pylint inside venv ($PWD/venv)..."
[ ! -e "$PWD/venv/bin/pylint" ] && $PWD/venv/bin/python -m pip install pylint
$PWD/venv/bin/pylint "$@"
exit $?
elif [ -e "$PWD/pyproject.toml" ]
then
echo "Run pylint using poetry..."
poetry run pylint --version > /dev/null 2>&1 || poetry run python -m pip install pylint
poetry run pylint "$@"
exit $?
else

View file

@ -2,6 +2,6 @@ from debian:stable-slim
RUN apt-get update && apt-get upgrade -y && apt-get install --no-install-recommends -y python3-all python3-dev python3-pip python3-venv build-essential pylint git && apt-get clean && rm -fr rm -rf /var/lib/apt/lists/*
RUN pip install pre-commit --break-system-packages
RUN mkdir /tmp/src
COPY .pre-commit-config.yaml .pre-commit-pylint fake_python_module /tmp/src/
RUN cd /tmp/src && git init && git add * && pre-commit autoupdate && pre-commit run --all-files && rm -fr /tmp/src
RUN mkdir /src && git config --global --add safe.directory /src
COPY .pre-commit-config.yaml .pre-commit-pylint fake_python_module /src/
RUN cd /src && git init && git add * && pre-commit autoupdate && pre-commit run --all-files && rm -fr /src

View file

@ -1,17 +1,31 @@
# Docker image to run pre-commit on Python apps/libraries
Image with common dependencies to run pre-commit in Python apps/libraries:
Debian stable based image with common dependencies to run `pre-commit` on Python apps/libraries:
- common python packages: `python3-all python3-dev python3-pip python3-venv pylint3`
- common python packages: `python3-all python3-dev python3-pip python3-venv pylint`
- `build-essential` to allow local python package using `pip`
- `pre-commit` and `git` commands
- pre-install `pre-commit` environments for `pylint`, `pyupgrade`, `black` and `isort`
- pre-install `pre-commit` environments for `ruff`, `pyupgrade`, `black`, `isort`,
`flake8`, `codespell`, `yamllint`, `prettier`, `pylint` and `bandit`.
To use it:
```bash
docker run -it -v "$(pwd)":/src -w /src brenard/python-pre-commit
pre-commit run --all-files
docker run \
-it --rm \
-v "$(pwd)":/src -w /src \
brenard/python-pre-commit \
pre-commit run --all-files
```
**Note:** an example `.pre-commit-config.yaml` file is provided with Docker image source.
To test it on your project, use to following command:
```bash
docker run \
-it --rm \
-v "$(pwd)":/src -w /src \
-v "$(pwd)/.pre-commit-config.yaml":/src/.pre-commit-config.yaml \
brenard/python-pre-commit \
pre-commit run --all-files
```