diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55f26ece5..0f5696369 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,15 +62,10 @@ 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: 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 + scripts/pylint.sh 5.0 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..86c9606c1 100644 --- a/README.md +++ b/README.md @@ -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..36736ba22 100755 --- a/scripts/install-build-tools.sh +++ b/scripts/install-build-tools.sh @@ -14,41 +14,21 @@ 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 -} - 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 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 @@ -68,8 +48,8 @@ elif [[ "$OSTYPE" == "linux-gnu"* ]]; then $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+ is not installed, get the latest version + if ! python3 --version | grep -E 'Python 3.1[0-9]+'; then $SUDO add-apt-repository ppa:deadsnakes/ppa $SUDO apt update diff --git a/scripts/pylint.sh b/scripts/pylint.sh new file mode 100755 index 000000000..0388f8eeb --- /dev/null +++ b/scripts/pylint.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# minimum standard of code quality (up to 10.0) +MIN_QUALITY=8.0 + +# set minimum quality to user input if provided if > 5.0 +if [ -n "$1" ]; then + if (( $(echo "$1 >= 5.0" | bc -l) )); then + MIN_QUALITY=$1 + else + echo "Minimum code quality must be greater than 5.0" + exit 1 + fi +fi + +echo "Linting Python code with minimum quality of $MIN_QUALITY/10.0..." + +pylint --rcfile=.pylintrc $(git ls-files '*.py') --fail-under=$MIN_QUALITY + +if [ $? -ne 0 ]; then + echo "Linting failed, please fix the issues above." + exit 1 +else + echo "Linting passed." +fi