Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jagapiou committed Dec 10, 2024
1 parent 31c8c60 commit d534440
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// on large machines).
"--shm-size=6gb"
],
"postCreateCommand": "pip install --editable .[dev]",
"postCreateCommand": ".devcontainer/setup.sh",
"customizations": {
"vscode": {
"extensions": [
Expand Down
26 changes: 26 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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.
#
# Set up devcontainer
set -e

python --version
pip --version
pip list

pip install --no-deps --require-hashes -r requirements.txt
pip install --no-deps --no-index --no-build-isolation --editable .
pip list
23 changes: 23 additions & 0 deletions bin/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/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.
#
# Installation script.
set -e
python3 -m venv venv
source venv/bin/activate
pip install --require-virtualenv --require-hashes -r requirements.txt
pip install --require-virtualenv --no-deps --no-index --no-build-isolation --editable .
pip list
39 changes: 39 additions & 0 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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 meltingpot.
FAILURES=false

echo "pytest meltingpot..."
pytest meltingpot || FAILURES=true
echo
echo

echo "pytype meltingpot..."
pytype meltingpot || FAILURES=true
echo
echo

echo "pylint meltingpot..."
pylint --errors-only meltingpot || 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
39 changes: 39 additions & 0 deletions bin/test_examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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.
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

if "${FAILURES}"; then
echo -e '\033[0;31mFAILURE\033[0m' && exit 1
else
echo -e '\033[0;32mSUCCESS\033[0m'
fi
20 changes: 20 additions & 0 deletions bin/update_requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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.

pip-compile --generate-hashes --reuse-hashes --strip-extras \
--upgrade --extra dev setup.py
1 change: 0 additions & 1 deletion examples/requirements.txt → examples/requirements.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
absl_py
dm_env
dm_meltingpot
dm_tree
dmlab2d
gymnasium
Expand Down
22 changes: 19 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import shutil
import tarfile
import tempfile
import urllib.request

import setuptools
Expand Down Expand Up @@ -52,15 +53,30 @@ def run(self):
def download_and_extract_assets(self):
"""Downloads and extracts assets to meltingpot/assets."""
tar_file_path = os.path.join(
self.get_package_dir('assets'), os.path.basename(ASSETS_URL))
self.get_package_dir('assets'), os.path.basename(ASSETS_URL)
)
if os.path.exists(tar_file_path):
print(f'found cached assets {tar_file_path}', flush=True)
else:
tmp_path = self.download_assets()
os.makedirs(os.path.dirname(tar_file_path), exist_ok=True)
shutil.copy(tmp_path, tar_file_path)
print(f'copied assets to {tar_file_path}', flush=True)
self.extract_assets(tar_file_path)

def download_assets(self):
"""Downloads assets tar file to temporary location."""
tmp_path = os.path.join(tempfile.gettempdir(), os.path.basename(ASSETS_URL))
if os.path.exists(tmp_path):
print(f'found cached assets {tmp_path}', flush=True)
else:
print('downloading assets...', flush=True)
urllib.request.urlretrieve(ASSETS_URL, filename=tar_file_path)
print(f'downloaded {tar_file_path}', flush=True)
urllib.request.urlretrieve(ASSETS_URL, filename=tmp_path)
print(f'downloaded assets to {tmp_path}', flush=True)
return tmp_path

def extract_assets(self, tar_file_path):
"""Extracts assets tar file to meltingpot/assets."""
root = os.path.join(self.get_package_dir(''), 'meltingpot')
os.makedirs(root, exist_ok=True)
if os.path.exists(f'{root}/assets'):
Expand Down

0 comments on commit d534440

Please sign in to comment.