diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 279e706f..9a5982b3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ { "name": "Concordia", "image": "mcr.microsoft.com/devcontainers/python:0-3.11", - "postCreateCommand": ".devcontainer/setup.sh", + "postCreateCommand": "./bin/install.sh", "customizations": { "vscode": { "extensions": [ diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml index 2f745596..a2de2ee4 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/install/action.yml @@ -46,21 +46,13 @@ runs: - name: Create venv if: steps.restore.outputs.cache-hit != 'true' shell: bash - run: | - python -m venv venv + run: ./bin/setup_venv.sh venv - name: Activate venv shell: bash run: | echo "${PWD}/venv/bin" >> $GITHUB_PATH - - name: Install - if: steps.restore.outputs.cache-hit != 'true' - shell: bash - run: | - pip install --require-virtualenv --require-hashes -r requirements.txt - pip install --require-virtualenv --no-deps --no-index --no-build-isolation --editable . - - name: Show installation shell: bash run: | diff --git a/.devcontainer/setup.sh b/bin/install.sh similarity index 75% rename from .devcontainer/setup.sh rename to bin/install.sh index e9e08d6e..fff48870 100755 --- a/.devcontainer/setup.sh +++ b/bin/install.sh @@ -14,13 +14,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# Set up devcontainer -set -e +# Install concordia. +set -euxo pipefail +cd "$(dirname "$0")/.." -python --version -pip --version -pip list +echo 'Installing requirements...' +pip install --no-deps --require-hashes --requirement requirements.txt +echo +echo -pip install --no-deps --require-hashes -r requirements.txt +echo 'Installing Concordia...' pip install --no-deps --no-index --no-build-isolation --editable . +echo +echo + pip list diff --git a/bin/setup_venv.sh b/bin/setup_venv.sh new file mode 100755 index 00000000..fde20a5d --- /dev/null +++ b/bin/setup_venv.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Copyright 2024 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Sets up the virtual environment. +set -euo pipefail +cd "$(dirname "$0")/.." + +readonly VENV_PATH="${1:-venv}" +if [[ -d "${VENV_PATH}" ]]; then + read -p "Virtual environment "${VENV_PATH}" already exists. Overwrite? (Y/N) " confirm + [[ "${confirm}" = [Yy]* ]] && rm -rf "${VENV_PATH}" || exit 1 +fi + +echo "Creating virtual environment at ${VENV_PATH}..." +python3 -m venv "${VENV_PATH}" +source "${VENV_PATH}"/bin/activate +python --version +pip --version +pip list +echo +echo + +./bin/install.sh diff --git a/bin/test.sh b/bin/test.sh new file mode 100755 index 00000000..8fc2f229 --- /dev/null +++ b/bin/test.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Copyright 2024 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Test concordia. +set -euxo pipefail +cd "$(dirname "$0")/.." +FAILURES=false + +echo "pytest concordia..." +pytest concordia || FAILURES=true +echo +echo + +echo "pytype concordia..." +pytype concordia || FAILURES=true +echo +echo + +echo "pylint concordia..." +pylint --errors-only concordia || FAILURES=true +echo +echo + +if "${FAILURES}"; then + echo -e '\033[0;31mFAILURE\033[0m' && exit 1 +else + echo -e '\033[0;32mSUCCESS\033[0m' +fi diff --git a/bin/test_examples.sh b/bin/test_examples.sh new file mode 100755 index 00000000..bbf09822 --- /dev/null +++ b/bin/test_examples.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# +# Copyright 2024 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Test the examples. +set -euxo pipefail +cd "$(dirname "$0")/.." +FAILURES=false + +echo "pytest examples..." +pytest examples || FAILURES=true +echo +echo + +echo "pytype examples..." +pytype examples || FAILURES=true +echo +echo + +echo "pylint examples..." +pylint --errors-only examples || FAILURES=true +echo +echo + +echo "convert notebooks..." +./bin/convert_notebooks.sh notebooks +echo +echo + +echo "pytype notebooks..." +pytype --pythonpath=. notebooks || FAILURES=true +echo +echo + +echo "pylint notebooks..." +pylint --errors-only notebooks || FAILURES=true +echo +echo + +if "${FAILURES}"; then + echo -e '\033[0;31mFAILURE\033[0m' && exit 1 +else + echo -e '\033[0;32mSUCCESS\033[0m' +fi diff --git a/bin/update_requirements.sh b/bin/update_requirements.sh new file mode 100755 index 00000000..44b5b383 --- /dev/null +++ b/bin/update_requirements.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# Copyright 2024 DeepMind Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Update requirements.txt. +set -euxo pipefail +cd "$(dirname "$0")/.." + +pip-compile --quiet --generate-hashes --reuse-hashes --upgrade --strip-extras \ + --extra dev setup.py examples/requirements.in diff --git a/examples/requirements.txt b/examples/requirements.in similarity index 72% rename from examples/requirements.txt rename to examples/requirements.in index 7fdc3cad..81611a83 100644 --- a/examples/requirements.txt +++ b/examples/requirements.in @@ -1,6 +1,6 @@ +# Requirements for the Concordia examples. absl-py docstring-parser -gdm-concordia immutabledict IPython matplotlib