Skip to content

Instantly share code, notes, and snippets.

@frbayart
Created January 23, 2022 17:38
Show Gist options
  • Save frbayart/403ba4d2f73d83aa68682c5a39452e41 to your computer and use it in GitHub Desktop.
Save frbayart/403ba4d2f73d83aa68682c5a39452e41 to your computer and use it in GitHub Desktop.
Python Shebang with Pyenv

Detect which python3 to use based on .python-version file (created by pyenv) anf fallback to python3 in $PATH

ie if vault_save.py is in ~/bin/ try to get ~/bin/'python-version` if it exists if will be used to execute the current Python file.

So if your $PATH is PATH=~/bin:$PATH, you can run from anywhere vault_save.py and it will use the pyenv version defined in ~/bin

#! /usr/bin/env bash
'''':;
K_DIRNAME="$(dirname -- "${BASH_SOURCE[0]}")"
if [[ -f ${K_DIRNAME}/.python-version ]]; then
PYENV_VERSION=$(cat "${K_DIRNAME}/.python-version")
K_PYTHON="${HOME}/.pyenv/versions/${PYENV_VERSION}/bin/python3"
else
K_PYTHON=$(which python3)
fi
exec "$K_PYTHON" "$0" $* # '''
# -*- coding: utf-8 -*-
# Description: Save secret in hashicorp vault
# Author: Francois Bayart (frbayart)
# SPDX-License-Identifier: MIT
'''
Expected configuration
- VAULT_TOKEN
- VAULT_ADDR
'''
import click, datetime, hashlib, requests, hvac
...
def main() {
print("hey")
}
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment