Skip to content

Commit

Permalink
chore: create scirpt for venv.
Browse files Browse the repository at this point in the history
  • Loading branch information
zlj-zz committed Dec 11, 2023
1 parent 30a69b2 commit 78ef68c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- '**.gif'
- '**.yml'
- 'const.py'
- 'tools/'

jobs:
build:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ log
.coverage*
htmlcov/

# venv
.pigit_venv

# useless file temp
useless/

Expand Down
60 changes: 60 additions & 0 deletions tools/venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env sh
# run scirpit with `source`.

# 检查Python版本
version=$(python3 -c 'import sys; sys.exit(sys.version_info < (3, 7))')
echo $version
if [[ "$version" ]]; then
echo "Python版本必须为3.8或更高版本"
exit 1
fi

op=$1
name=".pigit_venv"

create_venv() {
if [ -d "$name" ]; then
echo "Virtual env'$name' existed."
exit 1
fi

python3 -m venv "$name"

source "$name/bin/activate"

pip install -r requirements.txt

echo "Virtual env has created. activate with running::"
echo "source $name/bin/activate"
}

activate_venv() {
if [ ! -d "$name" ]; then
echo "Not found env '$name'."
exit 1
fi

source "$name/bin/activate"
echo "The virtual env has actived."
}

deactivate_venv() {
if [ -z "$VIRTUAL_ENV" ]; then
echo "Current not activate virtula env."
exit 1
fi

# exit command
deactivate
echo "The virtual env exited."
}


if [[ "$op" == "start" ]]; then
activate_venv
elif [[ "$op" == "stop" ]]; then
deactivate_venv
else
create_venv
fi

0 comments on commit 78ef68c

Please sign in to comment.