From 4869b934e601560fd4e8fa4e3613f8fb1600665c Mon Sep 17 00:00:00 2001 From: Morgan Rockett Date: Thu, 13 Jun 2024 16:46:36 -0400 Subject: [PATCH] added standalone pylint.sh script; improved install-build-tools.sh over prev commit Signed-off-by: Morgan Rockett --- .github/workflows/ci.yml | 14 ++++---- .gitignore | 1 - README.md | 11 +++--- scripts/install-build-tools.sh | 63 +++++++++++++++------------------- scripts/pylint.sh | 36 +++++++++++++++++++ 5 files changed, 75 insertions(+), 50 deletions(-) create mode 100755 scripts/pylint.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55f26ece5..14e6ddd9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,7 @@ jobs: run: scripts/lint.sh pylint: name: Pylint - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 continue-on-error: true timeout-minutes: 5 strategy: @@ -62,15 +62,13 @@ 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 + set -x + 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 diff --git a/.gitignore b/.gitignore index 71f3f5701..66a2cde54 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ ethash*/ lua-*/ benchmark-results/ CMakeFiles/ -Python-*/ plots/ .deps/ .libs/ diff --git a/README.md b/README.md index 36104729f..f80611548 100644 --- a/README.md +++ b/README.md @@ -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 & 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") @@ -87,7 +87,7 @@ 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 - ./scripts/install-build-tools.sh + sudo ./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. @@ -116,7 +116,7 @@ See the [live deployment](https://mit-dci.github.io/opencbdc-tx-pages/) to brows ## UHS-based Architectures (2PC & Atomizer) -See the [2PC & Atomizer User Guide](docs/2pc_atomizer_user_guide.md) +See the [2PC & Atomizer User Guide](docs/2pc_atomizer_user_guide.md) ## PArSEC Architecture @@ -159,7 +159,7 @@ Review results and logs at `testruns//` ## 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 @@ -168,6 +168,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 ``` diff --git a/scripts/install-build-tools.sh b/scripts/install-build-tools.sh index 258e7611a..16ce53888 100755 --- a/scripts/install-build-tools.sh +++ b/scripts/install-build-tools.sh @@ -14,41 +14,23 @@ 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 - fi - return 1 -} - +echo "OS Type: $OSTYPE" +echo "Python3 current version: $(python3 --version)" if [[ "$OSTYPE" == "darwin"* ]]; then 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)" + + # need homebrew to install dependencies + if ! command -v brew &>/dev/null; then + # exit with error if user does not have homebrew installed + 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 python3 pylint python-matplotlib 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 @@ -59,28 +41,37 @@ if [[ "$OSTYPE" == "darwin"* ]]; then fi elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # export DEBIAN_FRONTEND=noninteractive $SUDO apt update - $SUDO apt install -y build-essential wget cmake libgtest-dev libbenchmark-dev lcov git software-properties-common rsync unzip + $SUDO apt install -y build-essential wget cmake libgtest-dev libbenchmark-dev lcov git software-properties-common rsync unzip bc - 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" + # 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 + + $SUDO apt update $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 - # Python 3.10+ not installed so get the latest version - if ! check_python_version; then + # if Python ["3.10", "3.11", "3.12"] is not installed, install the latest version of those + if ! python3 --version | grep -E 'Python 3.1[0-2]'; then $SUDO add-apt-repository ppa:deadsnakes/ppa - $SUDO apt update - latest_python_version=$(apt-cache search python3. | grep -o 'python3\.[0-9]*' | sort -V | tail -n 1) + latest_python_version=$(apt-cache search python3. | grep -E -o '^python3.1[0-2]\s+' | tail -n 1 | tr -d ' ') $SUDO apt install -y $latest_python_version - $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 --install /usr/bin/python3 python3 /usr/bin/$latest_python_version 1 $SUDO update-alternatives --config python3 fi + + # Install pip3 and matplotlib and pylint + $SUDO apt install python3-pip + $SUDO python3 -m pip install matplotlib pylint fi -python3 --version +echo "Using Python version: $(python3 --version)" PYTHON_TIDY=/usr/local/bin/run-clang-tidy.py if [ ! -f "${PYTHON_TIDY}" ]; then diff --git a/scripts/pylint.sh b/scripts/pylint.sh new file mode 100755 index 000000000..f237578cc --- /dev/null +++ b/scripts/pylint.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# depedenent on 'sudo scripts/install-build-tools.sh' to install pylint +if ! command -v pylint &>/dev/null; then + echo "pylint is not installed." + echo "Run 'sudo ./scripts/install-build-tools.sh' to install pylint." + exit 1; +fi + +MIN_CODE_QUALITY=8.0 +if [ -n "$1" ]; then + # set minimum quality to user input (int/float) if provided and (5.0 <= input <= 10.0) + if [[ $1 =~ ^[0-9]*([\.][0-9])?$ ]]; then + if (( $(echo "$1 >= 5.0" | bc -l) )) && (( $(echo "$1 <= 10.0" | bc -l) )); then + MIN_CODE_QUALITY=$1 + else + # In the future, we want code quality to be at minimum 8.0/10.0 + echo "Code quality score must be between 5.0 and 10.0, inclusive." + echo "Recommended code quality score is >= 8.0." + exit 1 + fi + else + echo "Code quality score must be an integer or floating point number." + exit 1 + fi +fi + +echo "Linting Python code with minimum quality of $MIN_CODE_QUALITY/10.0..." +pylint --rcfile=.pylintrc --fail-under=$MIN_CODE_QUALITY $(git ls-files '*.py') + +if [ $? -ne 0 ]; then + echo "Linting failed, please fix the issues above." + exit 1 +else + echo "Linting passed." +fi