Skip to content

Commit

Permalink
✨ Add tfenv
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelange committed Dec 15, 2024
1 parent 6582ff0 commit 12d5c4b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
24 changes: 17 additions & 7 deletions .bash_profile
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ eval "$(zoxide init bash)" || true

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
export PROMPT_COMMAND='history -a;history -c;history -r'
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(direnv hook bash)"
eval "$(pyenv virtualenv-init -)"
export PROMPT_COMMAND='_pyenv_virtualenv_hook;_direnv_hook;history -a;history -c;history -r'
eval "$(direnv hook bash)" # direnv hook last so that `export PYENV_VERSION=vv` in local .env is exported first, and gets picked up by pyenv-virtualenv
export PYENV_VIRTUALENV_DISABLE_PROMPT=1

pyenv activate vv311
# add PYENV_VERSION=vv311 to your .env instead (see direnv in README)
# pyenv activate vv311


# exports
Expand Down Expand Up @@ -77,20 +78,29 @@ alias sm='smerge'
alias xdg-open='open'
alias pyenvls='pyenv virtualenvs | grep --invert-match "/envs/"'
alias i="
python -c 'import autotime, ipdb, pandas, rich' || pip install -U ipython-autotime ipdb pandas rich ipython
uv pip install ipython-autotime ipdb rich ipython pandas~=2.0
ipython -i -c '
# just make sure to use escaped double quotes
import os, logging, numpy as np, pandas as pd
# https://pandas.pydata.org/pandas-docs/version/2.1/user_guide/copy_on_write.html
pd.options.mode.copy_on_write = True
from pathlib import Path
here = Path(\".\").resolve()
from rich import pretty, print
pretty.install()
# set to WARNING by default
logging.basicConfig(level=logging.INFO, format=\"%(asctime)s:%(levelname)-7s %(filename)20s:%(lineno)-4d %(name)s:%(message)s\")
logger = logging.getLogger(__name__)
LOGGING_LEVEL = getattr(logging, os.environ.get(\"LOGGING_LEVEL\", \"INFO\"))
LOGGING_FORMAT = os.environ.get(
\"LOGGING_FORMAT\",
\"%(asctime)s:%(levelname)-7s %(filename)20s:%(lineno)-4d %(name)s:%(message)s\",
)
logging.basicConfig(level=LOGGING_LEVEL, format=LOGGING_FORMAT)
logging.info(\"Logging set to %s\", LOGGING_LEVEL)
# hotreload imports on each prompt
%load_ext autoreload
Expand Down Expand Up @@ -133,7 +143,7 @@ PS1="⨊ 𝕯𝓭𝓵:\[\033[36m\]\w\[\033[m\]$ " # ⚛ ⨊ 𝓓𝔇𝒟ℓℒ
# functions

# https://stackoverflow.com/a/73108928/5511061
dockersize() { docker manifest inspect -v "$1" | jq -c 'if type == "array" then .[] else . end' | jq -r '[ ( .Descriptor.platform | [ .os, .architecture, .variant, ."os.version" ] | del(..|nulls) | join("/") ), ( [ .SchemaV2Manifest.layers[].size ] | add ) ] | join(" ")' | numfmt --to iec --format '%.2f' --field 2 | sort | column -t ; }
dockersize() { docker manifest inspect -v "$1" | jq -c 'if type == "array" then .[] else . end' | jq -r '[ ( .Descriptor.platform | [ .os, .architecture, .variant, ."os.version" ] | del(..|nulls) | join("/") ), ( [ ( .OCIManifest // .SchemaV2Manifest ).layers[].size ] | add ) ] | join(" ")' | numfmt --to iec --format '%.2f' --field 2 | sort | column -t ; }
export -f dockersize
clusterimages() { kubectl get po -A -o json | jq -cr '.items[].spec.containers[].image' | grep -o '^[^@]\+' | sort -u | xargs -I _ bash -c 'echo - _ && dockersize _' ; }
export -f clusterimages
Expand Down
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# first source parent directories
source_up_if_exists
# then overwrite with current directory env vars
source_env_if_exists .env
3 changes: 3 additions & 0 deletions .gitignore.global
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,6 @@ GitHub.sublime-settings
.envrc
# dotenv
.env

# ruff
.ruff_cache
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ https://github.com/naokazuterada/MarkdownTOC#usage -->
- [Mac App Store \(MAS\)](#mac-app-store-mas)
- [Backups](#backups)
- [pyenv and pyenv-virtualenv](#pyenv-and-pyenv-virtualenv)
- [Terraform](#terraform)
- [Git with 2FA](#git-with-2fa)
- [Mac OSX specifics](#mac-osx-specifics)
- [Aliases](#aliases)
Expand Down Expand Up @@ -147,7 +148,7 @@ brew doctor
brew install \
git git-lfs gitmoji bash-completion rsync curl openssl readline automake xz zlib \
osxfuse sshfs htop ncdu direnv pwgen \
gcc@8 rust ruby node@14 sqlite3
gcc rust ruby node sqlite3
# check out caveats from command above!
# npm installs yarn
PATH="/usr/local/opt/node@14/bin:$PATH" npm install -g yarn
Expand Down Expand Up @@ -249,8 +250,9 @@ Note: first open Chrome for the first time
mkdir ~/git
git clone https://github.com/ddelange/new-mac-setup.git ~/git/new-mac-setup
ln -s ~/git/new-mac-setup/.bash_profile ~/.bash_profile && source ~/.bash_profile
ln -s ~/git/.envrc ~/.envrc # tell direnv to look for env vars when entering/leaving ~ (same file works for nested directories in a cumulative fashion)
touch ~/.env # fill this one with your secrets/env vars like `export PYENV_VERSION=vv`
mkdir -p ~/.config/htop && ln -s ~/git/new-mac-setup/htoprc ~/.config/htop/htoprc
direnv edit ~ # add `export SECRET=42` to load global env vars # pragma: allowlist secret

# Sublime Text 3 backup
# restore
Expand All @@ -276,7 +278,7 @@ Note: first open Chrome for the first time

### [pyenv](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#command-reference) and [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv#usage)

- Note: pyvenv-virtualenv needs to be initialised in [`~/.bash_profile`](/.bash_profile), or in `~/.bashrc` if both files are [maintained separately](https://github.com/pyenv/pyenv-virtualenv/issues/36#issuecomment-48387008):
- Note: pyvenv-virtualenv needs to be initialised in [`~/.bash_profile`](/.bash_profile) (already present there in the right order to cooperate with direnv), or in `~/.bashrc` if both files are [maintained separately](https://github.com/pyenv/pyenv-virtualenv/issues/36#issuecomment-48387008):
```bash
eval "$(pyenv init -)"
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
Expand All @@ -286,7 +288,7 @@ Note: first open Chrome for the first time
brew install pyenv pyenv-virtualenv
# get your favourite python versions - github.com/momo-lab/pyenv-install-latest
git clone https://github.com/momo-lab/pyenv-install-latest.git "$(pyenv root)"/plugins/pyenv-install-latest
git clone git://github.com/concordusapps/pyenv-implict.git "$(pyenv root)"/plugins/pyenv-implict
git clone https://github.com/concordusapps/pyenv-implict.git "$(pyenv root)"/plugins/pyenv-implict
pyenv install -l | grep '^\s*[0-9]' # list all available python versions
pyenv install-latest 2
pyenv install-latest 3
Expand All @@ -305,7 +307,15 @@ Note: first open Chrome for the first time
pyenv deactivate
pyenv uninstall <venv-name>
```
- Add an env var like `export PYENV_VERSION=vv` to your direnv `.env` file to automatically activate and deactivate when entering and leaving directories. Works as long as you don't put a dash (`-`) in your venv name.

### Terraform

```bash
brew install tfenv
tfenv install
tfenv use
```

### Git with 2FA

Expand All @@ -320,7 +330,7 @@ Note: first open Chrome for the first time
# EITHER
curl -sLw "\n" "http://gitignore.io/api/macos,python,django,sublimetext" >> ~/.gitignore # for all possibilities see http://gitignore.io/api/list
# OR
cp .gitignore.global ~/.gitignore
cp .gitignore.global ~/.gitignore # can no longer be a symlink on git version 2.32+

git config --global core.excludesfile "~/.gitignore"
```
Expand Down Expand Up @@ -410,7 +420,7 @@ git config --global alias.amend "commit --amend --reset-author --no-edit -a"
# "commit all amend with message" - add all modified tracked files to the last commit with a new commit message
git config --global alias.camend "commit --amend --reset-author -am"
# "squash last" X commits - allowing to edit a pre-generated commit message before committing - known caveat: when trying to squash into an initial commit, the reset fails
git config --global alias.squashlast '!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f'
git config --global alias.squashlast '!f(){ TEMP_MSG="$(mktemp)" && git log --format=%B HEAD...HEAD~${1} > "${TEMP_MSG}" && git reset --soft HEAD~${1} && git commit -n --edit --file "${TEMP_MSG}"; rm "${TEMP_MSG}"; }; f'
# "undo" whatever you did last, for instance an erroneous squashlast - ref https://megakemp.com/2016/08/25/git-undo/
git config --global alias.undo '! f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'
```
Expand Down
2 changes: 1 addition & 1 deletion htoprc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
htop_version=3.1.2
config_reader_min_version=2
fields=0 48 17 18 38 39 2 46 47 49 1
sort_key=39
sort_key=46
sort_direction=-1
tree_sort_key=46
tree_sort_direction=-1
Expand Down

0 comments on commit 12d5c4b

Please sign in to comment.