Skip to content

Commit 2664b8d

Browse files
committed
chore: replace mirror URL adjustment with wrapper script support
The `replace-mirrors` function was removed from environment setup and task scripts. Instead, the scripts now check for the existence of wrapper scripts (like `pixi-wrapper.sh` and `uv-wrapper.sh`) and use them to invoke `pixi` and `uv`. This change provides more flexibility and avoids directly modifying lock files. Changes affect: - Environment activation script (.config/direnv/10-python.sh) - Dependency installation script (tasks/install.sh) - Dependency upgrade script (tasks/upgrade.sh) - Package initialization script (tasks/gen-init.sh) The wrapper approach allows for custom pre/post processing of commands without hardcoded URL replacements, making the scripts more maintainable and adaptable to different environments.
1 parent 1ddb1a6 commit 2664b8d

4 files changed

Lines changed: 25 additions & 33 deletions

File tree

template/.config/copier/mise/tasks/gen-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function has() {
1010
}
1111

1212
TEMPLATE="\
13-
# tangerine-start: lazy-loader.py.jinja
13+
# tangerine-start: lazy-loader.py
1414
import lazy_loader as lazy
1515
1616
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)

template/.config/copier/mise/tasks/install.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@ set -o errexit
55
set -o nounset
66
set -o pipefail
77

8-
function replace-mirrors() {
9-
local file="$1"
10-
if [[ -f $file ]]; then
11-
# ref: <https://github.com/astral-sh/uv/issues/6349#issuecomment-3076752818>
12-
sd 'https://(\S+)/packages\b' 'https://files.pythonhosted.org/packages' "$file"
13-
sd 'https://(\S+)/simple\b' 'https://pypi.org/simple' "$file"
14-
fi
8+
function has() {
9+
type "$@" &> /dev/null
1510
}
1611

1712
if [[ -f 'pixi.lock' ]]; then
18-
pixi install
19-
replace-mirrors 'pixi.lock'
13+
pixi='pixi'
14+
if has pixi-wrapper.sh; then pixi='pixi-wrapper.sh'; fi
15+
"$pixi" install
2016
fi
2117

2218
if [[ -f 'uv.lock' ]]; then
23-
uv sync --all-extras --all-groups
24-
replace-mirrors 'uv.lock'
19+
uv='uv'
20+
if has uv-wrapper.sh; then uv='uv-wrapper.sh'; fi
21+
"$uv" sync --all-extras --all-groups
2522
fi

template/.config/copier/mise/tasks/upgrade.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,18 @@ set -o errexit
66
set -o nounset
77
set -o pipefail
88

9-
function replace-mirrors() {
10-
local file="$1"
11-
if [[ -f $file ]]; then
12-
# ref: <https://github.com/astral-sh/uv/issues/6349#issuecomment-3076752818>
13-
sd 'https://(\S+)/packages\b' 'https://files.pythonhosted.org/packages' "$file"
14-
sd 'https://(\S+)/simple\b' 'https://pypi.org/simple' "$file"
15-
fi
9+
function has() {
10+
type "$@" &> /dev/null
1611
}
1712

1813
if [[ -f 'pixi.lock' ]]; then
19-
pixi upgrade
20-
replace-mirrors 'pixi.lock'
14+
pixi='pixi'
15+
if has pixi-wrapper.sh; then pixi='pixi-wrapper.sh'; fi
16+
"$pixi" upgrade
2117
fi
2218

2319
if [[ -f 'uv.lock' ]]; then
24-
uv sync --upgrade
25-
replace-mirrors 'uv.lock'
20+
uv='uv'
21+
if has uv-wrapper.sh; then uv='uv-wrapper.sh'; fi
22+
"$uv" sync --upgrade
2623
fi

template/.config/direnv/10-python.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@
44

55
pushd "$(git rev-parse --show-toplevel)" > /dev/null || return 1
66

7-
function replace-mirrors() {
8-
local file="$1"
9-
if [[ -f $file ]]; then
10-
sd 'https://(\S+)/simple\b' 'https://pypi.org/simple' "$file"
11-
sd 'https://(\S+)/packages\b' 'https://files.pythonhosted.org/packages' "$file"
12-
fi
7+
function has() {
8+
type "$@" &> /dev/null
139
}
1410

1511
if [[ -f 'pixi.lock' ]]; then
1612
options=()
1713
if [[ -t 2 ]]; then
1814
options+=(--color=always)
1915
fi
20-
eval "$(pixi shell-hook "${options[@]}")"
21-
replace-mirrors 'pixi.lock'
16+
pixi='pixi'
17+
if has pixi-wrapper.sh; then pixi='pixi-wrapper.sh'; fi
18+
eval "$("$pixi" shell-hook "${options[@]}")"
2219
fi
2320

2421
if [[ -f 'uv.lock' ]]; then
25-
uv sync --all-extras --all-groups
26-
replace-mirrors 'uv.lock'
22+
uv='uv'
23+
if has uv-wrapper.sh; then uv='uv-wrapper.sh'; fi
24+
"$uv" sync --all-extras --all-groups
2725
sed --in-place --regexp-extended \
2826
's|\s*(include-system-site-packages)\s*=\s*.*\s*|\1 = true|' '.venv/pyvenv.cfg'
2927
# shellcheck disable=SC1091

0 commit comments

Comments
 (0)