Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 11 additions & 39 deletions misc/check_meta.sh
Original file line number Diff line number Diff line change
@@ -1,48 +1,20 @@
#!/usr/bin/env bash

red_output() {
echo -e "\033[31m$1\033[0m"
}
# TorchMeter, AGPL-3.0 license
# Author: Ahzyuan
# Repo: https://github.com/TorchMeter/torchmeter

green_output() {
echo -e "\033[32m$1\033[0m"
}

yellow_output() {
echo -e "\033[33m$1\033[0m"
}

find_dir() {
local target_path=$1
local current_path=$(realpath $(dirname $0))
local found_path=""

while [ "$current_path" != "/" ]; do
if [ -d "$current_path/$target_path" ]; then
found_path="$current_path"
break
elif [ -f "$current_path/$target_path" ]; then
found_path="$current_path"
break
fi
current_path=$(dirname "$current_path")
done

if [ -z "$found_path" ]; then
echo "Error: $target_path not found!"
exit 1
else
echo $found_path
fi
}
source "$(dirname "$0")/utils.sh"

# ---------------------------------------------------------------------------------------------------

ROOT=$(find_dir 'torchmeter')
if [[ $? -ne 0 ]]; then
exit 1
if ROOT="$(find_dir 'torchmeter')"; then
cd "$ROOT" || {
red_output "Error: Cannot enter $ROOT"
exit 1
}
else
cd $ROOT
exit 1
fi

if [[ ! -d "$ROOT/dist" ]]; then
Expand All @@ -60,7 +32,7 @@ tar_requires_python=$(echo "$tar_output" | grep 'Requires-Python:' | head -n 1 |
echo -e "Metadata_version: $metadata_version $(yellow_output '(need >=1.2)')"
echo -e "Python Required: $tar_requires_python $(yellow_output "(need >=$requires_python)")"
echo "----------------------------------------"
if [[ "$metadata_version" > "1.2" ]] && \
if (( $(echo "$metadata_version > 1.2" | bc -l) )) && \
[[ $(echo -e "$tar_requires_python\n$requires_python" | sort -V | head -n 1) == "3.8" ]]; then
green_output "Metadata and requires-python are correct."
else
Expand Down
108 changes: 31 additions & 77 deletions misc/docs_preview.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,10 @@
#! /usr/bin/env bash

cyan_output() {
echo -e "\033[36m$1\033[0m"
}

yellow_output() {
echo -e "\033[33m$1\033[0m"
}

green_output() {
echo -e "\033[32m$1\033[0m"
}

red_output() {
echo -e "\033[31m$1\033[0m"
}
# TorchMeter, AGPL-3.0 license
# Author: Ahzyuan
# Repo: https://github.com/TorchMeter/torchmeter

find_dir() {
local target_path=$1
local current_path=$(realpath $(dirname $0))
local found_path=""

while [ "$current_path" != "/" ]; do
if [ -d "$current_path/$target_path" ]; then
found_path="$current_path"
break
elif [ -f "$current_path/$target_path" ]; then
found_path="$current_path"
break
fi
current_path=$(dirname "$current_path")
done

if [ -z "$found_path" ]; then
echo "Error: $target_path not found!"
exit 1
else
echo $found_path
fi
}
source "$(dirname "$0")/utils.sh"

check_py_dependencies() {

Expand All @@ -54,30 +20,32 @@ try:
deps = config["options.extras_require"]["docs"].strip()
for dep in deps.split('\n'):
dep = re.findall(r"(\w+)(\[.+\])?", dep)[0][0]
if os.system(f"pip list | grep '{dep}'"):
if os.system(f"pip list | grep '{dep}' > /dev/null"):
print(dep)
except KeyError:
sys.exit("Error: Missing [options.extras_require] or docs dependencies in setup.cfg")
EOF
)

# shellcheck disable=SC2181
if [[ $? -ne 0 ]]; then
red_output "Failed to parse setup.cfg"
exit 1
else
LACK=($LACK)
fi

for dep in "${Deps[@]}"; do
if [[ -z "$dep" ]]; then
continue
fi

pip install "$dep" || {
red_output "Failed to install $dep"
exit 1
}
done
if [[ -n "$LACK" ]]; then
LACK=("$LACK")
for dep in "${LACK[@]}"; do
if [[ -z "$dep" ]]; then
continue
fi

pip install "$dep" || {
red_output "Failed to install $dep"
exit 1
}
done
fi
green_output "All docs dependencies have been installed."

}
Expand Down Expand Up @@ -129,35 +97,21 @@ while [[ "$#" -gt 0 ]]; do
done

# navigate to project root
ROOT=$(find_dir 'torchmeter')
if [[ $? -ne 0 ]]; then
if ! ROOT="$(find_dir 'torchmeter')"; then
exit 1
else
cd $ROOT
cd "$ROOT" || {
red_output "Error: Cannot enter $ROOT"
exit 1
}
fi

if [[ -d "$ROOT/dist" ]]; then
rm -r "$ROOT/dist"
fi

# activate conda env
eval "$(conda shell.bash hook)"

envs=$(conda env list | grep -v "#" | cut -d " " -f1)

cyan_output "Available conda environments:"
PS3="Choose your Python env: "
select env in $envs
do
if [ -n "$env" ]; then
cyan_output "$env selected."
conda activate "$env"
green_output "$env activated."
break
else
red_output "Invalid selection. Please try again."
fi
done
activate_conda_env || exit 1

# check dependencies
if [ "$QUICK_MODE" = false ]; then
Expand All @@ -166,13 +120,13 @@ if [ "$QUICK_MODE" = false ]; then
cyan_output "\nChecking Python dependencies..."
check_py_dependencies

# Check Drawio
cyan_output "\nChecking drawio..."
check_drawio
# # Check Drawio
# cyan_output "\nChecking drawio..."
# check_drawio

# Check xvfb
cyan_output "\nChecking xvfb..."
check_xvfb
# # Check xvfb
# cyan_output "\nChecking xvfb..."
# check_xvfb

else
yellow_output "Quick mode enabled: skipping all dependency checks."
Expand Down
73 changes: 15 additions & 58 deletions misc/lint_format.sh
Original file line number Diff line number Diff line change
@@ -1,65 +1,22 @@
#!/usr/bin/env bash

green_output() {
echo -e "\033[32m$1\033[0m"
}
# TorchMeter, AGPL-3.0 license
# Author: Ahzyuan
# Repo: https://github.com/TorchMeter/torchmeter

cyan_output() {
echo -e "\033[36m\033[0m"
}
source "$(dirname "$0")/utils.sh"

find_dir() {
local target_path=$1
local current_path=$(realpath $(dirname $0))
local found_path=""

while [ "$current_path" != "/" ]; do
if [ -d "$current_path/$target_path" ]; then
found_path="$current_path"
break
elif [ -f "$current_path/$target_path" ]; then
found_path="$current_path"
break
fi
current_path=$(dirname "$current_path")
done

if [ -z "$found_path" ]; then
echo "Error: $target_path not found!"
exit 1
else
echo $found_path
fi
}

# ---------------------------------------------------------------------------------------------------

ROOT=$(find_dir 'torchmeter')
if [[ $? -ne 0 ]]; then
if ! ROOT="$(find_dir 'torchmeter')"; then
exit 1
else
cd $ROOT
cd "$ROOT" || {
red_output "Error: Cannot enter $ROOT"
exit 1
}
fi

# -------------------------------------- Activate Virtual Env ---------------------------------------

eval "$(conda shell.bash hook)"

envs=$(conda env list | grep -v "#" | cut -d " " -f1)

cyan_output "Available conda environments:"
PS3="Choose your Python env: "
select env in $envs
do
if [ -n "$env" ]; then
cyan_output "$env selected."
conda activate "$env"
green_output "$env activated.\n"
break
else
red_output "Invalid selection. Please try again."
fi
done
activate_conda_env || exit 1

# --------------------------------------------- Format -----------------------------------------------

Expand All @@ -71,10 +28,10 @@ exit_code=$?
set -e

if [[ $exit_code -eq 0 ]]; then
echo -e "βœ… Formatting finish! πŸŽ‰\n"
green_output "βœ… Formatting finish! πŸŽ‰\n"
else
echo -e "❌ Formatting failed! Some code does not meet the format requirements!s" >&2
echo -e "❌ Ruff terminates abnormally due to invalid configuration, invalid CLI options, or an internal error" >&2
red_output "❌ Formatting failed! Some code does not meet the format requirements!s" >&2
red_output "❌ Ruff terminates abnormally due to invalid configuration, invalid CLI options, or an internal error" >&2
exit 1
fi

Expand All @@ -91,8 +48,8 @@ exit_code=$?
set -e

if [[ $exit_code -eq 0 ]]; then
echo -e "βœ… Linting passed! Code quality check successful! πŸŽ‰\n"
green_output "βœ… Linting passed! Code quality check successful! πŸŽ‰\n"
else
echo -e "❌ Linting failed! Some code does not meet the linting rules!\n" >&2
red_output "❌ Linting failed! Some code does not meet the linting rules!\n" >&2
exit 1
fi
Loading
Loading