forked from odysseus-dev/odysseus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-basicsr.sh
More file actions
executable file
·56 lines (48 loc) · 1.81 KB
/
Copy pathinstall-basicsr.sh
File metadata and controls
executable file
·56 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
# Install basicsr with a Python 3.13+ compatible patch, then install realesrgan.
# basicsr's setup.py uses exec()+locals() which broke in Python 3.13/3.14.
set -euo pipefail
REPO="$(cd "$(dirname "$0")" && pwd)"
VENV_PIP="$REPO/venv/bin/pip"
VENV_PYTHON="$REPO/venv/bin/python"
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
echo "Downloading basicsr 1.4.2 source..."
curl -s -L "https://files.pythonhosted.org/packages/source/b/basicsr/basicsr-1.4.2.tar.gz" \
-o "$TMPDIR/basicsr.tar.gz"
tar -xzf "$TMPDIR/basicsr.tar.gz" -C "$TMPDIR"
export BASICSR_SRC="$TMPDIR/basicsr-1.4.2"
echo "Patching setup.py for Python 3.13+ compatibility..."
"$VENV_PYTHON" - <<'PYEOF'
import pathlib, sys, os
setup = pathlib.Path(os.environ["BASICSR_SRC"]) / "setup.py"
src = setup.read_text()
old = ("def get_version():\n"
" with open(version_file, 'r') as f:\n"
" exec(compile(f.read(), version_file, 'exec'))\n"
" return locals()['__version__']")
new = ("def get_version():\n"
" with open(version_file, 'r') as f:\n"
" ns = {}\n"
" exec(compile(f.read(), version_file, 'exec'), ns)\n"
" return ns['__version__']")
if old not in src:
print("ERROR: get_version() pattern not found.")
sys.exit(1)
setup.write_text(src.replace(old, new))
print("Patched.")
PYEOF
echo "Building patched basicsr wheel..."
cd "$TMPDIR/basicsr-1.4.2"
"$VENV_PYTHON" setup.py bdist_wheel --quiet 2>&1 | tail -3
WHEEL=$(find "$TMPDIR/basicsr-1.4.2/dist" -name "basicsr-*.whl" | head -1)
if [[ -z "$WHEEL" ]]; then
echo "ERROR: wheel build failed."
exit 1
fi
echo "Installing patched basicsr..."
"$VENV_PIP" install --quiet --no-deps "$WHEEL"
echo "basicsr installed."
echo "Installing realesrgan..."
"$VENV_PIP" install --quiet realesrgan
echo "realesrgan installed."