forked from mit-dci/opencbdc-tx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created standard way to get project root; fixes mit-dci#304
- Loading branch information
Showing
12 changed files
with
83 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# calling scripts can use this script to capture the project ROOT dir | ||
# SCRIPT_DIR="$( cd -- "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
# ROOT="$( "$SCRIPT_DIR"/get-root.sh )" | ||
|
||
# returns the fullpath to the ROOT dir without a slash at the end | ||
ROOT= | ||
# if we are in a git repository | ||
if git rev-parse --show-toplevel >/dev/null 2>&1; then | ||
ROOT="$( git rev-parse --show-toplevel )" | ||
else | ||
# $BASH_SOURCE[0] is the full path of the script being executed | ||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" | ||
# scripts dir will always be one level below ROOT level: "$ROOT"/scripts | ||
ROOT="$( cd -- "$SCRIPT_DIR"/.. && pwd )" | ||
fi | ||
|
||
# check for directory existence | ||
if [[ ! -d "$ROOT" ]]; then | ||
echo "Error: ROOT '${ROOT}' not found." | ||
exit 1 | ||
fi | ||
|
||
# use other scripts in the script dir to capture the ROOT fullpath | ||
printf "%s\n" "$ROOT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
#!/usr/bin/env bash | ||
|
||
ROOT="$(cd "$(dirname "$0")"/.. && pwd)" | ||
SCRIPT_DIR="$( cd -- "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
ROOT="$( "$SCRIPT_DIR"/get-root.sh )" | ||
PREFIX="${ROOT}"/prefix | ||
MIN_CODE_QUALITY=8.0 | ||
|
||
get_code_score() { | ||
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 | ||
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 | ||
fi | ||
echo "Linting Python code with minimum quality of $MIN_CODE_QUALITY/10.0..." | ||
echo "Linting Python code with minimum quality of $MIN_CODE_QUALITY/10.0..." | ||
} | ||
|
||
check_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 | ||
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 | ||
} | ||
|
||
get_code_score $1 | ||
if source "${ROOT}/scripts/activate-venv.sh"; then | ||
echo "Virtual environment activated." | ||
echo "Virtual environment activated." | ||
else | ||
echo "Failed to activate virtual environment." | ||
exit 1 | ||
echo "Failed to activate virtual environment." | ||
exit 1 | ||
fi | ||
|
||
check_pylint | ||
if ! pylint scripts src tests tools --rcfile=.pylintrc \ | ||
--fail-under=$MIN_CODE_QUALITY $(git ls-files '*.py'); then | ||
--fail-under=$MIN_CODE_QUALITY $(git ls-files '*.py'); then | ||
echo "Linting failed, please fix the issues and rerun." | ||
exit 1 | ||
exit 1 | ||
else | ||
echo "Linting passed." | ||
echo "Linting passed." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters