Skip to content

Commit 10619e5

Browse files
committed
added standalone pylint.sh script; improved install-build-tools.sh over prev commit
Signed-off-by: Morgan Rockett <[email protected]>
1 parent 7323f53 commit 10619e5

File tree

5 files changed

+128
-59
lines changed

5 files changed

+128
-59
lines changed

.github/workflows/ci.yml

+13-14
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Setup Local Dependencies
3131
run: ./scripts/setup-dependencies.sh
3232
- name: Build
33-
run: scripts/build.sh
33+
run: ./scripts/build.sh
3434
lint:
3535
name: Lint
3636
runs-on: ubuntu-20.04
@@ -43,16 +43,17 @@ jobs:
4343
- name: Setup Local Dependencies
4444
run: ./scripts/setup-dependencies.sh
4545
- name: Build
46-
run: scripts/build.sh
46+
run: ./scripts/build.sh
4747
- name: Lint
48-
run: scripts/lint.sh
48+
run: ./scripts/lint.sh
4949
pylint:
5050
name: Pylint
51-
runs-on: ubuntu-20.04
51+
runs-on: ubuntu-22.04
5252
continue-on-error: true
53-
timeout-minutes: 5
53+
timeout-minutes: 10
5454
strategy:
5555
matrix:
56+
# pylint is not supported on python 3.13 yet
5657
python-version: ["3.10", "3.11", "3.12"]
5758
steps:
5859
- uses: actions/checkout@v2
@@ -62,15 +63,13 @@ jobs:
6263
uses: actions/setup-python@v2
6364
with:
6465
python-version: ${{ matrix.python-version }}
65-
- name: Install dependencies
66-
run: |
67-
python3 -m pip install --upgrade pip
68-
if [ -f requirements_py.txt ]; then pip install -r requirements_py.txt; fi
69-
pip install pylint
66+
- name: Setup Build Env
67+
run: sudo ./scripts/install-build-tools.sh
7068
- name: Lint with Pylint
7169
run: |
72-
# In the future we should have (minimum score of 8.0/10.0 or 9.0/10.0)
73-
pylint --rcfile=.pylintrc $(git ls-files '*.py') --fail-under=5.0
70+
set -x
71+
MIN_CODE_QUALITY=5.0
72+
./scripts/pylint.sh $MIN_CODE_QUALITY
7473
unit-and-integration-test:
7574
name: Unit and Integration Tests
7675
runs-on: ubuntu-20.04
@@ -84,9 +83,9 @@ jobs:
8483
- name: Setup Local Dependencies
8584
run: ./scripts/setup-dependencies.sh
8685
- name: Build
87-
run: scripts/build.sh
86+
run: ./scripts/build.sh
8887
- name: Run Unit Tests
89-
run: scripts/test.sh
88+
run: ./scripts/test.sh
9089
- name: Shorten SHA
9190
id: vars
9291
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ ethash*/
4747
lua-*/
4848
benchmark-results/
4949
CMakeFiles/
50-
Python-*/
5150
plots/
5251
.deps/
5352
.libs/

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ There are two UHS-based architectures as follows:
4242
- Maximum demonstrated throughput ~1.7M transactions per second.
4343
- Geo-replicated latency <1 second.
4444

45-
Read the [2PC &amp; Atomizer architecture guide](docs/uhs-architectures.md) for a detailed description of the system components and implementation of each architecture.
45+
Read the [2PC & Atomizer architecture guide](docs/uhs-architectures.md) for a detailed description of the system components and implementation of each architecture.
4646

4747
## Parallel Architecture for Scalably Executing smart Contracts ("PArSEC")
4848

@@ -86,8 +86,9 @@ If you just want to run the system, see "Run the Code" below.
8686
1. Setup the build-environment.
8787
Note that this script is just a convenience to install system-wide dependencies we expect.
8888
As a result, it uses the system package manager, requires `sudo`, and should only be run **once**.
89+
Note: Running Homebrew as root on mac is not supported.
8990
```console
90-
./scripts/install-build-tools.sh
91+
sudo ./scripts/install-build-tools.sh
9192
```
9293
2. Setup project dependencies
9394
This script builds and installs a local copy of several build-dependencies which are not widely packaged.
@@ -116,7 +117,7 @@ See the [live deployment](https://mit-dci.github.io/opencbdc-tx-pages/) to brows
116117

117118
## UHS-based Architectures (2PC & Atomizer)
118119

119-
See the [2PC &amp; Atomizer User Guide](docs/2pc_atomizer_user_guide.md)
120+
See the [2PC & Atomizer User Guide](docs/2pc_atomizer_user_guide.md)
120121

121122
## PArSEC Architecture
122123

@@ -159,7 +160,7 @@ Review results and logs at `testruns/<testrun-uuid>/`
159160
## Linting
160161

161162
### General
162-
This script checks for newlines at the end of files.
163+
This script checks for newlines at the end of all tracked git files except images.
163164
Then it runs clang-format and clang-tidy on `.cpp` files in the following directories:
164165
`src`, `tests`, `cmake-tests`, `tools`.
165166
```console
@@ -168,6 +169,7 @@ Then it runs clang-format and clang-tidy on `.cpp` files in the following direct
168169

169170
### Python
170171
Lint all python files according to ruleset defined in `.pylintrc`.
172+
Optional code quality value >= 5.0 and <= 10.0 can be entered as a threshold of failure.
171173
```console
172-
pylint --rcfile=.pylintrc $(git ls-files '*.py') --fail-under=8.0
174+
./scripts/pylint.sh 8.0
173175
```

scripts/install-build-tools.sh

+72-39
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,58 @@ cyan="\033[0;36m"
77
end="\033[0m"
88

99
set -e
10+
# for debugging, 'set -x' can be added to trace the commands
1011

1112
SUDO=''
1213
if (( $EUID != 0 )); then
1314
echo -e "non-root user, sudo required"
1415
SUDO='sudo'
1516
fi
1617

17-
# Function to check if a version of Python >= 3.10 is installed
18-
check_python_version() {
19-
if command -v python3 &>/dev/null; then
20-
# Get the version of Python
21-
PYTHON_VERSION=$(python3 --version | awk '{print $2}')
22-
IFS='.' read -r -a version_parts <<< "$PYTHON_VERSION"
23-
echo "Python version: ${version_parts[0]}.${version_parts[1]}"
24-
# >= 3.10
25-
if (( ${version_parts[0]} >= 3 && ${version_parts[1]} >= 10 )); then
26-
return 0
27-
fi
28-
fi
29-
return 1
30-
}
18+
# as of June 2024, python3.13 does not support pylint so limiting most recent version 3.12
19+
PY_VERSIONS=("3.12" "3.11" "3.10")
20+
echo "Python3 at start of script version: $(python3 --version)"
21+
echo "OS Type: $OSTYPE"
3122

3223
if [[ "$OSTYPE" == "darwin"* ]]; then
3324
CPUS=$(sysctl -n hw.ncpu)
3425
# ensure development environment is set correctly for clang
3526
$SUDO xcode-select -switch /Library/Developer/CommandLineTools
36-
# see if homebrew is installed and install if not
37-
if ! [[ -f /opt/homebrew/bin/brew ]]; then
38-
echo -e "${green}Installing Homebrew...${end}"
39-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
27+
28+
echo "Running sudo with homebrew as root through a shell script is not allowed."
29+
echo "These installs can be done manually in a terminal, however."
30+
31+
if ! command -v brew &>/dev/null; then
32+
echo -e "${cyan}Homebrew is required to install dependencies.${end}"
33+
exit 1
4034
fi
41-
export PATH="/opt/homebrew/bin:$PATH"
4235

43-
brew install llvm@14 googletest google-benchmark lcov make wget cmake curl bash python3 pylint python-matplotlib
36+
brew install llvm@14 googletest google-benchmark lcov make wget cmake bash bc
4437
brew upgrade bash
4538

46-
# Add Python 3 to PATH
47-
echo "export PATH=\"/opt/homebrew/opt/python@3/bin:\$PATH\"" >> ~/.bash_profile
48-
# Make python3 default
49-
echo "alias python=python3" >> ~/.bash_profile
50-
. ~/.bash_profile
39+
DEFAULT_PYTHON=`python3 --version`
40+
# Install one of the python versions if not already installed
41+
if ! (${DEFAULT_PYTHON} | grep -E 'Python 3.1[0-2]'); then
42+
FOUND=false
43+
for PY_VERS in "${PY_VERSIONS[@]}"; do
44+
if brew search python@${PY_VERS} | grep -q "python@${PY_VERS}"; then
45+
echo "Python$PY_VERS is available, so installing it"
46+
brew install python@${PY_VERSIONS[0]} pylint python-matplotlib
47+
export PATH="$(brew --prefix python@${PY_VERS})/bin:$PATH"
48+
FOUND=true
49+
break
50+
fi
51+
done
52+
53+
if [ "$FOUND" == false ]; then
54+
echo "Python3 install with brew failed, attempted on these versions: ${PY_VERSIONS[@]}"
55+
exit 1
56+
elif [ ${DEFAULT_PYTHON} >= 3.13 ]; then
57+
echo "Your Python3 default version: $DEFAULT_PYTHON is not supported by pylint yet"
58+
echo "Please set default python3 to one of the versions: ${PY_VERSIONS[@]} and try again."
59+
exit 1
60+
fi
61+
fi
5162

5263
CLANG_TIDY=/usr/local/bin/clang-tidy
5364
if [ ! -L "$CLANG_TIDY" ]; then
@@ -59,28 +70,50 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
5970
fi
6071

6172
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
62-
$SUDO apt update
63-
$SUDO apt install -y build-essential wget cmake libgtest-dev libbenchmark-dev lcov git software-properties-common rsync unzip
73+
# avoids getting stuck on interactive prompts which is essential for CI/CD
74+
export DEBIAN_FRONTEND=noninteractive
75+
$SUDO apt update -y
76+
$SUDO apt install -y build-essential wget cmake libgtest-dev libbenchmark-dev \
77+
lcov git software-properties-common rsync unzip bc
78+
79+
# Add LLVM GPG key (apt-key is deprecated in Ubuntu 21.04+ so using gpg)
80+
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | \
81+
gpg --dearmor -o /usr/share/keyrings/llvm-archive-keyring.gpg
82+
echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" | \
83+
$SUDO tee /etc/apt/sources.list.d/llvm.list
6484

65-
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | $SUDO apt-key add -
66-
$SUDO add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main"
85+
$SUDO apt update -y
6786
$SUDO apt install -y clang-format-14 clang-tidy-14
6887
$SUDO ln -s -f $(which clang-format-14) /usr/local/bin/clang-format
6988
$SUDO ln -s -f $(which clang-tidy-14) /usr/local/bin/clang-tidy
7089

71-
# Python 3.10+ not installed so get the latest version
72-
if ! check_python_version; then
73-
$SUDO add-apt-repository ppa:deadsnakes/ppa
74-
$SUDO apt update
75-
76-
latest_python_version=$(apt-cache search python3. | grep -o 'python3\.[0-9]*' | sort -V | tail -n 1)
77-
$SUDO apt install -y $latest_python_version
90+
# Install one of the python versions if not already installed
91+
if ! (python3 --version | grep -E 'Python 3.1[0-2]'); then
92+
FOUND=false
93+
for PY_VERS in "${PY_VERSIONS[@]}"; do
94+
if apt-cache search python3. | grep -E -q "^python$PY_VERS\s+"; then
95+
echo "Python$PY_VERS is available, so installing it"
96+
$SUDO apt install -y python3.$PY_VERS python3-pip python3-distutils
97+
$SUDO update-alternatives --install /usr/bin/python3 python3 /usr/bin/python$PY_VERS 1
98+
$SUDO update-alternatives --config python3
99+
FOUND=true
100+
break
101+
fi
102+
done
78103

79-
$SUDO update-alternatives --install /usr/bin/python3 python3 /usr/bin/$(ls /usr/bin/ | grep -E '^python3\.[0-9]+$' | sort -V | tail -n 1) 1
80-
$SUDO update-alternatives --config python3
104+
if [ "$FOUND" == false ]; then
105+
echo "Python3 install with apt failed, attempted on these versions: ${PY_VERSIONS[@]}"
106+
exit 1
107+
fi
81108
fi
109+
110+
# python packages
111+
$SUDO apt install -y python3-pip python3-distutils
112+
$SUDO python3 -m pip install --upgrade pip
113+
$SUDO python3 -m pip install matplotlib pylint
82114
fi
83-
python3 --version
115+
116+
echo "Python3 version now: $(python3 --version)"
84117

85118
PYTHON_TIDY=/usr/local/bin/run-clang-tidy.py
86119
if [ ! -f "${PYTHON_TIDY}" ]; then

scripts/pylint.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# depedenent on 'sudo scripts/install-build-tools.sh' to install pylint
4+
if ! command -v pylint &>/dev/null; then
5+
echo "pylint is not installed."
6+
echo "Run 'sudo ./scripts/install-build-tools.sh' to install pylint."
7+
exit 1;
8+
fi
9+
10+
MIN_CODE_QUALITY=8.0
11+
if [ -n "$1" ]; then
12+
# set minimum quality to user input (int/float) if provided and (5.0 <= input <= 10.0)
13+
if [[ $1 =~ ^[0-9]*([\.][0-9])?$ ]]; then
14+
if (( $(echo "$1 >= 5.0" | bc -l) )) && (( $(echo "$1 <= 10.0" | bc -l) )); then
15+
MIN_CODE_QUALITY=$1
16+
else
17+
# In the future, we want code quality to be at minimum 8.0/10.0
18+
echo "Code quality score must be between 5.0 and 10.0, inclusive."
19+
echo "Recommended code quality score is >= 8.0."
20+
exit 1
21+
fi
22+
else
23+
echo "Code quality score must be an integer or floating point number."
24+
exit 1
25+
fi
26+
fi
27+
28+
echo "Linting Python code with minimum quality of $MIN_CODE_QUALITY/10.0..."
29+
pylint --rcfile=.pylintrc --fail-under=$MIN_CODE_QUALITY $(git ls-files '*.py')
30+
31+
if [ $? -ne 0 ]; then
32+
echo "Linting failed, please fix the issues above."
33+
exit 1
34+
else
35+
echo "Linting passed."
36+
fi

0 commit comments

Comments
 (0)