Last active
June 10, 2024 17:02
-
-
Save greyhoundforty/e34d0d5f69a2e9d00453fabdc8569d56 to your computer and use it in GitHub Desktop.
Python Taskfile
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
# https://taskfile.dev/ | |
version: "3" | |
vars: | |
TERM: screen-256color | |
MAIN_PYTHON: python3 | |
LOCAL_PATH: | |
sh: 'echo "$(cd "$( dirname -- "$0" )" && pwd)"' | |
venv_path: "{{.LOCAL_PATH}}/.venv" | |
venv_bin_path: "{{.LOCAL_PATH}}/.venv/bin" | |
venv_python: "{{.LOCAL_PATH}}/.venv/bin/python3" | |
venv_pip: "{{.LOCAL_PATH}}/.venv/bin/pip3" | |
tasks: | |
default: | |
silent: true | |
cmds: | |
- task -l | |
show: | |
desc: Show task variables | |
summary: | | |
Show all the task variables for the current environment. | |
Mainly used for debugging purposes. | |
silent: true | |
cmds: | |
- | | |
echo "OS: {{OS}}" | |
echo "ARCH: {{ARCH}}" | |
echo "MAIN_PYTHON: {{.MAIN_PYTHON}}" | |
echo "VENV_PATH: {{.venv_path}}" | |
echo "VENV_BIN_PATH: {{.venv_bin_path}}" | |
echo "VENV_PYTHON: {{.venv_python}}" | |
echo "VENV_PIP: {{.venv_pip}}" | |
precommit: | |
desc: Install pre-commit hooks locally | |
aliases: [prc] | |
summary: | | |
Install pre-commit hooks locally in the repository. | |
silent: true | |
cmds: | |
- | | |
pre-commit install || echo "Unable to initialize pre-commit hooks" | |
venv:create: | |
desc: Create python virtual environment | |
aliases: [vcrt] | |
silent: true | |
cmds: | |
- | | |
echo "Creating Python Virtual Environment at {{.venv_path}}" | |
{{.MAIN_PYTHON}} -m venv {{.venv_path}} | |
source {{.venv_bin_path}}/activate | |
{{.venv_pip}} install pip --upgrade --index-url=https://pypi.org/simple/ | |
{{.venv_pip}} install wheel setuptools --upgrade --index-url=https://pypi.org/simple/ | |
{{.venv_pip}} freeze > requirements.txt | |
status: | |
- test -d {{.venv_bin_path}} | |
venv:activate: | |
desc: Activate the python virtual environment | |
aliases: [vact] | |
silent: false | |
cmds: | |
- | | |
source {{.venv_bin_path}}/activate && \ | |
echo "Python Virtual Environment activated" | |
echo "Currently installed packages:" | |
{{.venv_pip}} freeze | |
# status: | |
# - test -d {{.PYTHON_VENV_PATH}} | |
venv:install: | |
desc: Install python dependencies | |
aliases: [vnstl] | |
summary: | | |
Install python dependencies if the requirements.txt file exists. | |
silent: false | |
cmds: | |
- | | |
source {{.venv_bin_path}}/activate && \ | |
{{.venv_pip}} install -r requirements.txt --upgrade --index-url=https://pypi.org/simple/ | |
status: | |
- test -f requirements.txt | |
venv:clean: | |
desc: Clean and remove the python virtual environment | |
aliases: [vcln] | |
summary: | | |
Remove the python virtual environment. | |
silent: true | |
cmds: | |
- | | |
echo "Removing Python Virtual Environment at {{.venv_path}}" | |
rm -rf {{.venv_path}} | |
venv:freeze: | |
desc: Freeze python dependencies | |
aliases: [vfrz] | |
summary: | | |
Freeze python dependencies to requirements.txt file. | |
silent: false | |
cmds: | |
- | | |
source {{.venv_path}}/bin/activate && \ | |
{{.venv_pip}} freeze > requirements.txt | |
status: | |
- test -f requirements.txt | |
venv:flake8: | |
desc: Run flake8 tests | |
aliases: [vflk8] | |
summary: | | |
Run flake8 tests on the project. | |
silent: false | |
cmds: | |
- | | |
source {{.venv_path}}/bin/activate && \ | |
{{.venv_pip}} install -r requirements.txt --upgrade --index-url=https://pypi.org/simple/ && \ | |
{{.venv_path}}/bin/flake8 . | |
status: | |
- test -d {{.venv_path}} | |
- test -f requirements.txt |
Author
greyhoundforty
commented
Jun 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment