Skip to main content

python/run_pip_sync

1#!/usr/bin/env python3
2"""
3Run `uv pip sync` with a `requirements.txt` file in the current folder.
5This will pick which file to use.
6"""
8import os
9from pathlib import Path
10import shlex
11import subprocess
12import sys
15if __name__ == "__main__":
16 # If we're on an external disk, disable the warning about being
17 # unable to clone files. In particular:
18 #
19 # warning: Failed to clone files; falling back to full copy.
20 # This may lead to degraded performance. If the cache and target
21 # directories are on different filesystems, reflinking may not
22 # be supported.
23 #
24 # If this is intentional, set `export UV_LINK_MODE=copy` or use
25 # `--link-mode=copy` to suppress this warning.
26 #
27 # On macOS, this means "are you in a path that starts with /Volumes".
28 if os.getcwd().startswith("/Volumes/"):
29 os.environ.update({"UV_LINK_MODE": "copy"})
31 # If a dev_requirements.txt file is available, use that, otherwise use
32 # the standard `requirements.txt`.
33 if Path("dev_requirements.txt").exists():
34 chosen_file = "dev_requirements.txt"
35 else:
36 chosen_file = "requirements.txt"
38 # Build the command to run.
39 cmd = ["uv", "pip", "sync", chosen_file]
41 if "--no-cache" in sys.argv:
42 cmd.append("--no-cache")
44 # Actually run the command, and print a debug entry for it.
45 subprocess.check_call(
46 [str(Path.home() / "repos/scripts/debug/print_info"), f"-> {shlex.join(cmd)}"]
47 )
48 subprocess.check_call(cmd, stdout=subprocess.DEVNULL)