Skip to content
Snippets Groups Projects
Commit 87bfd170 authored by Anton Shestakov's avatar Anton Shestakov
Browse files

contrib: add a set of scripts to run pytype in Docker

Having a simple way to run pytype for developers can massively shorten
development cycle. Using the same Docker image and scripts that we use on our
CI guarantees that the result achieved locally will be very similar to (if not
the same as) the output of our CI runners.

Things to note: the Dockerfile needs to do a little dance around user
permissions inside /home/ci-runner/ because:

- on one hand, creating new files on the host (e.g. .pyi files inside .pytype/)
  should use host user's uid and gid

- on the other hand, when we run the image as uid:gid of host user, it needs to
  be able to read/execute files inside the image that are owned by ci-runner

Since local user's uid might be different from ci-runner's uid, we execute this
very broad chmod command inside /home/ci-runner/, but then run the image as the
host user's uid:gid.

There might be a better way to do this.
parent 46280260
No related branches found
No related tags found
1 merge request!741pytype: make it possible to run pytype locally while using all the relevant scripts that we use on CI
...@@ -296,9 +296,11 @@ ...@@ -296,9 +296,11 @@
rm -rf $(PYOX_DIR)/doc rm -rf $(PYOX_DIR)/doc
cp -a doc $(PYOX_DIR)/doc cp -a doc $(PYOX_DIR)/doc
pytype-docker:
contrib/docker/pytype/recipe.sh
.PHONY: help all local build doc cleanbutpackages clean install install-bin \ .PHONY: help all local build doc cleanbutpackages clean install install-bin \
install-doc install-home install-home-bin install-home-doc \ install-doc install-home install-home-bin install-home-doc \
dist dist-notests check tests rust-tests check-code format-c \ dist dist-notests check tests rust-tests check-code format-c \
update-pot pyoxidizer pyoxidizer-windows-tests pyoxidizer-macos-tests \ update-pot pyoxidizer pyoxidizer-windows-tests pyoxidizer-macos-tests \
$(packaging_targets) \ $(packaging_targets) \
...@@ -299,7 +301,7 @@ ...@@ -299,7 +301,7 @@
.PHONY: help all local build doc cleanbutpackages clean install install-bin \ .PHONY: help all local build doc cleanbutpackages clean install install-bin \
install-doc install-home install-home-bin install-home-doc \ install-doc install-home install-home-bin install-home-doc \
dist dist-notests check tests rust-tests check-code format-c \ dist dist-notests check tests rust-tests check-code format-c \
update-pot pyoxidizer pyoxidizer-windows-tests pyoxidizer-macos-tests \ update-pot pyoxidizer pyoxidizer-windows-tests pyoxidizer-macos-tests \
$(packaging_targets) \ $(packaging_targets) \
osx osx pytype-docker
FROM registry.heptapod.net/mercurial/ci-images/mercurial-core:v2.0
USER ci-runner
ENV PATH=/home/ci-runner/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV PYTHONPATH=/home/ci-runner/.local/lib/python3.11/site-packages
RUN python3 -m pip install --user --break-system-packages --upgrade pytype==2023.11.21
ADD --chown=ci-runner entrypoint.sh /home/ci-runner/entrypoint.sh
RUN chmod -R a=rwX /home/ci-runner/.local/ /home/ci-runner/entrypoint.sh
CMD /home/ci-runner/entrypoint.sh
#!/usr/bin/env bash
set -euo pipefail
cd /tmp/mercurial-ci/
make local
./contrib/setup-pytype.sh
./contrib/check-pytype.sh
#!/usr/bin/env bash
# find repo-root without calling hg as this might be run with sudo
THIS="$(readlink -m "$0")"
HERE="$(dirname "$THIS")"
HG_ROOT="$(readlink -m "$HERE"/../../..)"
echo source mercurial repository: "$HG_ROOT"
# find actual user as this might be run with sudo
if [ -n "$SUDO_UID" ]; then
ACTUAL_UID="$SUDO_UID"
else
ACTUAL_UID="$(id -u)"
fi
if [ -n "$SUDO_GID" ]; then
ACTUAL_GID="$SUDO_GID"
else
ACTUAL_GID="$(id -g)"
fi
echo using user "$ACTUAL_UID:$ACTUAL_GID"
if groups | egrep -q '\<(docker|root)\>' ; then
env DOCKER_BUILDKIT=1 docker build --tag mercurial-pytype-checker "$HERE"
docker run --rm -it --user "$ACTUAL_UID:$ACTUAL_GID" -v "$HG_ROOT:/tmp/mercurial-ci" mercurial-pytype-checker
else
echo "user not in the docker group" >&2
echo "(consider running this with \`sudo\`)" >&2
exit 255
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment