diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c78a212a309ec4d38aec121dc46212c220a63d7..eff2e7565c091fd3b4e37296fadd26ae45c4546e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,13 +11,13 @@ repos: hooks: - id: tox-black name: tox-black (local) - entry: tox + entry: bash language: system - args: ["-c", "tangostationcontrol/tox.ini", "-e", "black", "--"] + args: ["-c", "cd tangostationcontrol; tox -e black"] - repo: local hooks: - id: tox-pep8 name: tox-pep8 (local) - entry: tox + entry: bash language: system - args: ["-c", "tangostationcontrol/tox.ini", "-e", "pep8", "--"] + args: ["-c", "cd tangostationcontrol; tox -e pep8"] diff --git a/README.md b/README.md index d2b61cd5c37179e0d8a9041dd875bae8084778cc..38a70f1fbf33c5df9921554df6e9c450826dc6aa 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ Station Control software related to Tango devices. \ * [Installation](#installation) * [Prerequisites](#prerequisites) - * [Bootstrap](#bootstrap) * [User documentation (ReadTheDocs (Sphinx / ReStructuredText))](tangostationcontrol/docs/README.md) * [Docker compose & station services documentation](docker-compose/README.md) * [Jupyter startup files](docker-compose/jupyterlab/ipython-profiles/stationcontrol-jupyter/startup/README.md) @@ -33,14 +32,14 @@ Station Control software related to Tango devices. \ ## Prerequisites -After checking out this repo, be sure to also check out the submodules -for this `git` needs to be installed: +After checking out this repo, be sure to install our git hooks and activate the virtual environment: -```sh -git submodule init -git submodule update +```shell +source setup.sh ``` +The file `/etc/docker/daemon.json` must exist on the host, create the folder and file if necessary. + You will also need: * docker @@ -59,6 +58,7 @@ You will also need: * python3.10 * pip (python3-pip) * tox (python3-tox) +* shyaml On Ubuntu / Debian based systems these can typically be installed diff --git a/bin/hooks/post-checkout b/bin/hooks/post-checkout new file mode 100755 index 0000000000000000000000000000000000000000..b105475877cdacd355cd85813735b3b347dd521c --- /dev/null +++ b/bin/hooks/post-checkout @@ -0,0 +1,8 @@ +#!/bin/bash +# Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: Apache-2.0 + +command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } +git lfs post-checkout "$@" + +git submodule update --init diff --git a/bin/hooks/post-commit b/bin/hooks/post-commit new file mode 100755 index 0000000000000000000000000000000000000000..52b339cb3f496610a69a3bd6cc0cd8b4dbca93a3 --- /dev/null +++ b/bin/hooks/post-commit @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } +git lfs post-commit "$@" diff --git a/bin/hooks/post-merge b/bin/hooks/post-merge new file mode 100755 index 0000000000000000000000000000000000000000..6ac5abbb9927dd5aa6b53b1acb036a6b2000d40a --- /dev/null +++ b/bin/hooks/post-merge @@ -0,0 +1,8 @@ +#!/bin/bash +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: Apache-2.0 + +command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } +git lfs post-merge "$@" + +git submodule update --init diff --git a/bin/hooks/pre-push b/bin/hooks/pre-push new file mode 100755 index 0000000000000000000000000000000000000000..0f0089bc25dc188e65375cc983f3325dd9f4480c --- /dev/null +++ b/bin/hooks/pre-push @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } +git lfs pre-push "$@" diff --git a/bin/update_submodules.sh b/bin/update_submodules.sh deleted file mode 100755 index be2eb2761a3e7ef12c0248be5e1667dfaa55c4f5..0000000000000000000000000000000000000000 --- a/bin/update_submodules.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy) -# SPDX-License-Identifier: Apache-2.0 - -git submodule update --init diff --git a/sbin/install-pre-commit.sh b/sbin/install-hooks/pre-commit.sh old mode 100644 new mode 100755 similarity index 73% rename from sbin/install-pre-commit.sh rename to sbin/install-hooks/pre-commit.sh index e589fa12613a0db53519fb76290fdf8b1dfb2808..622697e5288a20cb907d258f177ddcbcb0da42bb --- a/sbin/install-pre-commit.sh +++ b/sbin/install-hooks/pre-commit.sh @@ -1,7 +1,12 @@ #!/bin/bash +if [ ! -f "setup.sh" ]; then + echo "pre-commit.sh must be executed with repository root as working directory!" + exit 1 +fi + pip install pre-commit -pre-commit install --hook-type pre-push --allow-missing-config +pre-commit install --hook-type pre-push # --allow-missing-config: Allows the installation to proceed # even if the configuration file is missing, and hooks won't be executed diff --git a/sbin/install-hooks/submodule-and-lfs.sh b/sbin/install-hooks/submodule-and-lfs.sh new file mode 100644 index 0000000000000000000000000000000000000000..afe39e2e3bc049810e8978d4db2deef37281d89c --- /dev/null +++ b/sbin/install-hooks/submodule-and-lfs.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: Apache-2.0 + +if [ ! -f "setup.sh" ]; then + echo "submodule-and-lfs.sh must be executed with repository root as working directory!" + exit 1 +fi + +cp bin/hooks/* .git/hooks/ diff --git a/setup.sh b/setup.sh index 867f2035326f9b3974616359bd014ca694852670..c3c8d8986d1887f43e9cec0fed1f092d7c875d2e 100755 --- a/setup.sh +++ b/setup.sh @@ -23,15 +23,14 @@ fi # Activate the virtual environment source "$VENV_DIR/bin/activate" -# Install git post-checkout hook upon next execution of git command -# git alias eventually automatically uninstalled +# Install git hooks if [ ! -f "${LOFAR20_DIR}/.git/hooks/post-checkout" ]; then - alias git="cp ${LOFAR20_DIR}/bin/update_submodules.sh ${LOFAR20_DIR}/.git/hooks/post-checkout; cp ${LOFAR20_DIR}/bin/update_submodules.sh ${LOFAR20_DIR}/.git/hooks/post-merge; unalias git; git" + source "${LOFAR20_DIR}/sbin/install-hooks/submodule-and-lfs.sh" fi -# Install git pre-push hook -if [ ! -f "${LOFAR20_DIR}/.git/hooks/pre-push" ]; then - source "${LOFAR20_DIR}/sbin/install-pre-commit.sh" +# Install git pre-commit pre-push hook +if [ ! -f "${LOFAR20_DIR}/.git/hooks/pre-push.legacy" ]; then + source "${LOFAR20_DIR}/sbin/install-hooks/pre-commit.sh" fi # It checks if Tango is running within nomad, by trying to query the service from consul.