Skip to content

Instantly share code, notes, and snippets.

@agconti
Last active April 23, 2025 12:32
Show Gist options
  • Save agconti/1ed26b8f9957b21b00439028300c3394 to your computer and use it in GitHub Desktop.
Save agconti/1ed26b8f9957b21b00439028300c3394 to your computer and use it in GitHub Desktop.
An direnv setup for easily managing local python development environments. Put the .envrc at the root of your repo and the two other files in a tools directory. Manage creds via an .env file directing to 1password secrets
layout python3
# Automatically install dependencies when requirements.txt changes
LAST_INSTALLED_DEPENDENCIES_FLAG="$VIRTUAL_ENV/.dependencies_installed"
echo $LAST_INSTALLED_DEPENDENCIES_FLAG
if [ ! -f $LAST_INSTALLED_DEPENDENCIES_FLAG ] || [ requirements.txt -nt $LAST_INSTALLED_DEPENDENCIES_FLAG ]; then
echo "Installing dependencies..."
pip install -r requirements.txt
touch $LAST_INSTALLED_DEPENDENCIES_FLAG
fi
PATH_add "./tools"
#!/bin/bash
set -e
echo "๐Ÿ” Formatting and linting codebase..."
echo "๐Ÿ“ Formatting code with Black..."
black .
echo "๐Ÿ”„ Sorting imports with isort..."
isort .
echo "๐Ÿ‘ฎโ€โ™‚๏ธ Running pylint..."
pylint --ignore $VIRTUAL_ENV --recursive=y --exit-zero .
echo "๐Ÿ” Running type checking..."
mypy .
echo "โœ… Formatting and linting complete!"
#!/bin/bash
set -e
# Check if a command was provided.
if [ $# -eq 0 ]; then
echo "Error: No command provided"
echo "Usage: op_run.sh <command> [args...]"
exit 1
fi
# log in to 1password if signed out.
op whoami || eval $(op signin)
# Execute the command using op run
echo "๐Ÿ” Running command with 1Password environment variables..."
echo "op run --env-file="./.env" -- $@"
op run --env-file="./.env" -- "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment