forked from stanford-crfm/helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit.sh
executable file
·46 lines (40 loc) · 1.5 KB
/
pre-commit.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# This script fails when any of its commands fail.
set -e
# Check that python version is at least 3.8.
valid_version=$(python3 -c 'import sys; print(sys.version_info[:2] >= (3, 8))')
if [ "$valid_version" == "False" ]; then
echo "Python 3 version (python3 --version) must be at least 3.8, but was:"
echo "$(python3 --version 2>&1)"
exit 1
fi
# Manually upgrade pip to at least 21.1 to avoid issue #1053
python -m pip install --upgrade pip
# If this package is already installed under the deprecated name, uninstall it.
# TODO: Remove this after 2022-12-01
pip uninstall -y crfm-benchmarking
# On Mac OS, skip installing pytorch with CUDA because CUDA is not supported
if [[ $OSTYPE != 'darwin'* ]]; then
# Manually install pytorch to avoid pip getting killed: https://stackoverflow.com/a/54329850
pip install --no-cache-dir --find-links https://download.pytorch.org/whl/torch_stable.html torch==1.12.1+cu113 torchvision==0.13.1+cu113
fi
# Manually install protobuf to workaround issue: https://github.com/protocolbuffers/protobuf/issues/6550
pip install --no-binary=protobuf protobuf==3.20.1
# Install all pinned dependencies
pip install -r requirements-freeze.txt
pip install -e .
pip check
# Python style checks and linting
black --check --diff src scripts || (
echo ""
echo "The code formatting check failed. To fix the formatting, run:"
echo ""
echo ""
echo -e "\tblack src scripts"
echo ""
echo ""
exit 1
)
mypy --install-types --non-interactive src scripts
flake8 src scripts
echo "Done."