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 13, 2024
1 parent 7323f53 commit 974c53a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
38 changes: 9 additions & 29 deletions scripts/install-build-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
25 changes: 25 additions & 0 deletions scripts/pylint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 974c53a

Please sign in to comment.