Skip to main content

Move my venv-wrappers into a dedicated directory

ID
108aaef
date
2023-11-12 01:13:05+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
d479bbf
message
Move my venv-wrappers into a dedicated directory
changed files
5 files, 50 additions, 13 deletions

Changed files

.with-venv-python/README.md (0) → .with-venv-python/README.md (1554)

diff --git a/.with-venv-python/README.md b/.with-venv-python/README.md
new file mode 100644
index 0000000..d9dd8e5
--- /dev/null
+++ b/.with-venv-python/README.md
@@ -0,0 +1,43 @@
+This folder contains aliases for my Python scripts that causes them to run in a scripts-repo virtual environment, rather than my global Python.
+
+There's unlikely to be anything here which is useful to anyone but me.
+
+## Why?
+
+I try to run everything inside virtual environments, and not install any dependencies globally.
+I used to install my dependencies with the `--user` flag, but [Glyph's article](https://blog.glyph.im/2023/08/get-your-mac-python-from-python-dot-org.html) persuaded me to change my ways.
+For several reasons:
+
+*   Don't pollute my global Python installation
+*   Make it easier to track which library versions I'm using (there are some scripts I go for years on end without using, and it's annoying if I don't have a record of what library version I originally wrote them with)
+*   Better isolation of different projects
+
+I have a single virtualenv on my Mac for my scripts (`~/repos/scripts/.venv`).
+
+I could point to that Python in the shebang at the top of my scripts:
+
+```console
+$ cat myscript
+#!/Users/alexwlchan/repos/scripts/.venv/bin/python3
+"""
+This script is for ...
+```
+
+but that's quite fragile and makes the scripts less portable.
+
+So instead, I save the scripts as `[scriptname].py`, then create an alias `[scriptname]` in this folder which runs my script inside the virtual environment:
+
+```console
+$ cat myscript.py
+#!/usr/bin/env python3
+"""
+This script is for ...
+
+$ cat myscript
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+~/repos/scripts/.venv/bin/python3 "~/repos/scripts/images/[myscript].py" "$@"
+```

images/reborder (258) → .with-venv-python/noplaylist (128)

diff --git a/images/reborder b/.with-venv-python/noplaylist
similarity index 60%
rename from images/reborder
rename to .with-venv-python/noplaylist
index 370e5d3..56a0e76 100755
--- a/images/reborder
+++ b/.with-venv-python/noplaylist
@@ -3,7 +3,4 @@
 set -o errexit
 set -o nounset
 
-# https://stackoverflow.com/q/59895/1558022
-SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
-
-/Users/alexwlchan/repos/scripts/.venv/bin/python3 "$SCRIPT_DIR/reborder.py" "$@"
+~/repos/scripts/.venv/bin/python3 "~/repos/scripts/text/noplaylist.py" "$@"

text/noplaylist (260) → .with-venv-python/reborder (128)

diff --git a/text/noplaylist b/.with-venv-python/reborder
similarity index 54%
rename from text/noplaylist
rename to .with-venv-python/reborder
index 5b0c13d..28c14b3 100755
--- a/text/noplaylist
+++ b/.with-venv-python/reborder
@@ -3,7 +3,4 @@
 set -o errexit
 set -o nounset
 
-# https://stackoverflow.com/q/59895/1558022
-SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
-
-/Users/alexwlchan/repos/scripts/.venv/bin/python3 "$SCRIPT_DIR/noplaylist.py" "$@"
+~/repos/scripts/.venv/bin/python3 "~/repos/scripts/images/reborder.py" "$@"

images/README.md (5782) → images/README.md (5786)

diff --git a/images/README.md b/images/README.md
index aaa179e..e41900f 100644
--- a/images/README.md
+++ b/images/README.md
@@ -114,8 +114,8 @@ These scripts are for working with images and other visual material.
   </dd>
 
   <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/images/reborder">
-      <code>reborder [PATH] [BORDER_WIDTH]</code>
+    <a href="https://github.com/alexwlchan/scripts/blob/main/images/reborder.py">
+      <code>reborder.py [PATH] [BORDER_WIDTH]</code>
     </a>
   </dt>
   <dd>
@@ -158,7 +158,7 @@ These scripts are for working with images and other visual material.
   <dd>
     saves a single comic from <a href="https://xkcd.com/">xkcd</a>, plus some metadata.
   </dd>
-  
+
   <dt>
     <a href="https://github.com/alexwlchan/scripts/blob/main/images/srgbify">
       <code>srgbify [PATH]</code>

text/README.md (2885) → text/README.md (2891)

diff --git a/text/README.md b/text/README.md
index e7a6b7b..436749b 100644
--- a/text/README.md
+++ b/text/README.md
@@ -35,8 +35,8 @@ These are utilities for manipulating streams of text; I consider them in a simil
   </dd>
 
   <dt>
-    <a href="https://github.com/alexwlchan/scripts/blob/main/text/noplaylist">
-      <code>noplaylist < [URL]</code>
+    <a href="https://github.com/alexwlchan/scripts/blob/main/text/noplaylist.py">
+      <code>noplaylist.py < [URL]</code>
     </a>
   </dt>
   <dd>