Skip to content

Commit

Permalink
added standalone pylint.sh script; improved install-build-tools.sh ov…
Browse files Browse the repository at this point in the history
…er prev commit

Signed-off-by: Morgan Rockett <[email protected]>
  • Loading branch information
rockett-m committed Jun 20, 2024
1 parent 7323f53 commit 38568c5
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 61 deletions.
31 changes: 14 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
jobs:
build-release:
name: Build Release Candidate
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
env:
BUILD_RELEASE: 1
steps:
Expand All @@ -30,7 +30,7 @@ jobs:
- name: Setup Local Dependencies
run: ./scripts/setup-dependencies.sh
- name: Build
run: scripts/build.sh
run: ./scripts/build.sh
lint:
name: Lint
runs-on: ubuntu-20.04
Expand All @@ -43,14 +43,14 @@ jobs:
- name: Setup Local Dependencies
run: ./scripts/setup-dependencies.sh
- name: Build
run: scripts/build.sh
run: ./scripts/build.sh
- name: Lint
run: scripts/lint.sh
run: ./scripts/lint.sh
pylint:
name: Pylint
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
continue-on-error: true
timeout-minutes: 5
timeout-minutes: 10
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
Expand All @@ -62,18 +62,15 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
if [ -f requirements_py.txt ]; then pip install -r requirements_py.txt; fi
pip install pylint
- name: Setup Build Env
run: sudo ./scripts/install-build-tools.sh
- name: Lint with Pylint
run: |
# In the future we should have (minimum score of 8.0/10.0 or 9.0/10.0)
pylint --rcfile=.pylintrc $(git ls-files '*.py') --fail-under=5.0
MIN_CODE_QUALITY=5.0
./scripts/pylint.sh $MIN_CODE_QUALITY
unit-and-integration-test:
name: Unit and Integration Tests
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
Expand All @@ -84,9 +81,9 @@ jobs:
- name: Setup Local Dependencies
run: ./scripts/setup-dependencies.sh
- name: Build
run: scripts/build.sh
run: ./scripts/build.sh
- name: Run Unit Tests
run: scripts/test.sh
run: ./scripts/test.sh
- name: Shorten SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
Expand All @@ -101,7 +98,7 @@ jobs:
retention-days: 7
doxygen:
name: doxygen
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
with:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ ethash*/
lua-*/
benchmark-results/
CMakeFiles/
Python-*/
plots/
.deps/
.libs/
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ There are two UHS-based architectures as follows:
- Maximum demonstrated throughput ~1.7M transactions per second.
- Geo-replicated latency <1 second.

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

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

Expand Down Expand Up @@ -87,8 +87,13 @@ If you just want to run the system, see "Run the Code" below.
Note that this script is just a convenience to install system-wide dependencies we expect.
As a result, it uses the system package manager, requires `sudo`, and should only be run **once**.
```console
sudo ./scripts/install-build-tools.sh
```
Note: Running Homebrew as root on mac via shell script is not supported, so run without sudo and when prompted, enter the root password.
```console
./scripts/install-build-tools.sh
```

2. Setup project dependencies
This script builds and installs a local copy of several build-dependencies which are not widely packaged.
Because it installs to a local, configurable prefix (defaulting to `./prefix`), it does not need root permissions to run.
Expand Down Expand Up @@ -116,7 +121,7 @@ See the [live deployment](https://mit-dci.github.io/opencbdc-tx-pages/) to brows

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

See the [2PC &amp; Atomizer User Guide](docs/2pc_atomizer_user_guide.md)
See the [2PC & Atomizer User Guide](docs/2pc_atomizer_user_guide.md)

## PArSEC Architecture

Expand Down Expand Up @@ -159,7 +164,7 @@ Review results and logs at `testruns/<testrun-uuid>/`
## Linting

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

### Python
Lint all python files according to ruleset defined in `.pylintrc`.
Optional code quality value >= 5.0 and <= 10.0 can be entered as a threshold of failure.
```console
pylint --rcfile=.pylintrc $(git ls-files '*.py') --fail-under=8.0
./scripts/pylint.sh 8.0
```
198 changes: 159 additions & 39 deletions scripts/install-build-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ green="\033[0;32m"
cyan="\033[0;36m"
end="\033[0m"

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

SUDO=''
Expand All @@ -14,41 +15,45 @@ if (( $EUID != 0 )); then
SUDO='sudo'
fi

# Function to check if a version of Python >= 3.10 is installed
check_python_version() {
if command -v python3 &>/dev/null; then
# Get the version of Python
PYTHON_VERSION=$(python3 --version | awk '{print $2}')
IFS='.' read -r -a version_parts <<< "$PYTHON_VERSION"
echo "Python version: ${version_parts[0]}.${version_parts[1]}"
# >= 3.10
if (( ${version_parts[0]} >= 3 && ${version_parts[1]} >= 10 )); then
return 0
fi
# Supporting these versions for buildflow
PYTHON_VERSIONS=("3.12" "3.11" "3.10")
PYTHON_PACKAGES=("setuptools" "matplotlib" "numpy" "pylint")
PREFIX_DIR=`pwd`/prefix/bin
PY_INSTALLED=''
echo "Python3 versions supported: ${PYTHON_VERSIONS[@]}"
echo "OS Type: $OSTYPE"

make_symlinks() {
PY_LOCATION=$1
$SUDO mkdir -p ${PREFIX_DIR}
ln -snf ${PY_LOCATION} ${PREFIX_DIR}/python3
ln -snf ${PREFIX_DIR}/python3 ${PREFIX_DIR}/python
if [ ! -L ${PREFIX_DIR}/python ] && [ ! -L ${PREFIX_DIR}/python3 ]; then
echo "Symlink creation failed"; exit 1
fi
return 1
}

# macOS install with homebrew
if [[ "$OSTYPE" == "darwin"* ]]; then

# macOS does not support running shell scripts as root with homebrew
if [ $EUID -eq 0 ]; then
echo -e "Mac users should run this script without 'sudo'. Exiting..."
exit 1
fi

CPUS=$(sysctl -n hw.ncpu)
# ensure development environment is set correctly for clang
$SUDO xcode-select -switch /Library/Developer/CommandLineTools
# see if homebrew is installed and install if not
if ! [[ -f /opt/homebrew/bin/brew ]]; then
echo -e "${green}Installing Homebrew...${end}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

if ! command -v brew &>/dev/null; then
echo -e "${cyan}Homebrew is required to install dependencies.${end}"
exit 1
fi
export PATH="/opt/homebrew/bin:$PATH"

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

# Add Python 3 to PATH
echo "export PATH=\"/opt/homebrew/opt/python@3/bin:\$PATH\"" >> ~/.bash_profile
# Make python3 default
echo "alias python=python3" >> ~/.bash_profile
. ~/.bash_profile

CLANG_TIDY=/usr/local/bin/clang-tidy
if [ ! -L "$CLANG_TIDY" ]; then
$SUDO ln -s $(brew --prefix)/opt/llvm@14/bin/clang-tidy /usr/local/bin/clang-tidy
Expand All @@ -58,29 +63,144 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
$SUDO ln -s $(xcode-select -p)/usr/bin/gnumake /usr/local/bin/gmake
fi

# install python3 and necessary packages
BREW_ROOT=$(brew --prefix)

# check if any supported version of python3 is already installed
for PY_VERS in "${PYTHON_VERSIONS[@]}"; do
FULL_PY="python${PY_VERS}"
PYTHON_PATH=${BREW_ROOT}/bin/${FULL_PY}
echo "Checking if ${FULL_PY} is already installed"
# if path exists, then python3 version is already installed
if [ -e ${PYTHON_PATH} ]; then
echo "Installing dependencies for ${FULL_PY}"

# install python packages for the existing compatible python version
if ! $SUDO ${BREW_ROOT}/bin/pip${PY_VERS} install ${PYTHON_PACKAGES[@]}; then
echo "Python3 packages installation failed"; exit 1
fi

make_symlinks ${PYTHON_PATH}
PY_INSTALLED=${FULL_PY}
break
fi
done

# python3 supported version not found, so attempt to install it + deps
if [ "$PY_INSTALLED" == '' ]; then
for PY_VERS in "${PYTHON_VERSIONS[@]}"; do
FULL_PY="python${PY_VERS}"
PYTHON_PATH=${BREW_ROOT}/bin/${FULL_PY}

if brew search ${FULL_PY} | grep "${FULL_PY}"; then
echo "Installing ${FULL_PY} and dependencies"

# install python version and verify installation
if ! brew install ${FULL_PY}; then
echo "${FULL_PY} installation failed"; exit 1
fi

# install python packages for specific python version
if ! $SUDO ${BREW_ROOT}/bin/pip${PY_VERS} install ${PYTHON_PACKAGES[@]}; then
echo "Python3 packages installation failed"; exit 1
fi

make_symlinks ${PYTHON_PATH}
PY_INSTALLED=${FULL_PY}
break
fi
done
fi

# failed to install python3 supported version
if [ "$PY_INSTALLED" == '' ]; then
echo "Python3 install with brew failed, attempted on these versions: ${PYTHON_VERSIONS[@]}"
exit 1
else
echo "Success on ${PY_INSTALLED} install and required packages"
fi

# Linux install with apt
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
$SUDO apt update
$SUDO apt install -y build-essential wget cmake libgtest-dev libbenchmark-dev lcov git software-properties-common rsync unzip
# avoids getting stuck on interactive prompts which is essential for CI/CD
export DEBIAN_FRONTEND=noninteractive
$SUDO apt update -y
$SUDO apt upgrade -y
$SUDO apt install -y build-essential wget cmake libgtest-dev libbenchmark-dev \
lcov git software-properties-common rsync unzip bc

# Add LLVM GPG key (apt-key is deprecated in Ubuntu 21.04+ so using gpg)
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | \
gpg --dearmor -o /usr/share/keyrings/llvm-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" | \
$SUDO tee /etc/apt/sources.list.d/llvm.list

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

# Python 3.10+ not installed so get the latest version
if ! check_python_version; then
$SUDO add-apt-repository ppa:deadsnakes/ppa
$SUDO apt update
# Check if valid python3 version is installed; is so, install packages and create symlinks
for PY_VERS in "${PYTHON_VERSIONS[@]}"; do
FULL_PY="python${PY_VERS}"
PYTHON_PATH=/usr/bin/${FULL_PY}
# look for valid python install
if [ -e ${PYTHON_PATH} ]; then
echo "valid Python3 version detected: ${FULL_PY}"
# install python packages
if ! $SUDO ${FULL_PY} -m pip install ${PYTHON_PACKAGES[@]}; then
echo "Python3 packages installation failed"; exit 1
fi

latest_python_version=$(apt-cache search python3. | grep -o 'python3\.[0-9]*' | sort -V | tail -n 1)
$SUDO apt install -y $latest_python_version
make_symlinks ${PYTHON_PATH}
PY_INSTALLED=${PY_VERS}
break
fi
done

if [ "$PY_INSTALLED" == '' ]; then
# install one of the supported python versions
for PY_VERS in "${PYTHON_VERSIONS[@]}"; do
FULL_PY="python${PY_VERS}"
PYTHON_PATH=/usr/bin/${FULL_PY}
# Check if the desired Python version is available in the apt repository
if apt list -a ${FULL_PY} &> /dev/null; then
# for dependency installation on specific python version
$SUDO add-apt-repository -y ppa:deadsnakes/ppa
$SUDO apt update -y

$SUDO apt install -y ${FULL_PY}
if [ ! -e ${PYTHON_PATH} ]; then
echo "${FULL_PY} installation failed"; exit 1
fi

# install pip for the specific python3 version and packages
wget https://bootstrap.pypa.io/get-pip.py
if ! $SUDO ${FULL_PY} get-pip.py; then
echo "pip installation failed"
rm -f get-pip.py
exit 1
fi
rm -f get-pip.py
if ! $SUDO ${FULL_PY} -m pip install ${PYTHON_PACKAGES[@]}; then
echo "Python3 packages installation failed"; exit 1
fi

$SUDO update-alternatives --install /usr/bin/python3 python3 /usr/bin/$(ls /usr/bin/ | grep -E '^python3\.[0-9]+$' | sort -V | tail -n 1) 1
$SUDO update-alternatives --config python3
make_symlinks ${PYTHON_PATH}
PY_INSTALLED=${FULL_PY}
break
fi
done
fi

if [ "$PY_INSTALLED" == '' ]; then
echo "Python3 install with brew failed, attempted on these versions: ${PYTHON_VERSIONS[@]}"
exit 1
else
echo "Success on ${PY_INSTALLED} install and required packages"
fi

fi
python3 --version

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

0 comments on commit 38568c5

Please sign in to comment.