|
1 | 1 | {% raw %}#!/usr/bin/env sh |
2 | 2 | # can pass in the full major.minor.patch version of python as an optional argument |
3 | 3 | # can set `--skip-lock` as optional argument to just install dependencies without verifying lock file |
| 4 | +# can set `--optionally-lock` to check for a uv.lock file in the project directory and only respect the lock if it already exists (useful for initially instantiating the repository) (mutually exclusive with --skip-lock) |
| 5 | + |
4 | 6 | set -ex |
5 | 7 |
|
6 | 8 | # Ensure that uv won't use the default system Python |
7 | 9 | python_version="{% endraw %}{{ python_version }}{% raw %}" |
8 | 10 |
|
9 | 11 | # Parse arguments |
10 | 12 | skip_lock=false |
| 13 | +optionally_lock=false |
11 | 14 | while [ "$#" -gt 0 ]; do |
12 | 15 | case $1 in |
13 | 16 | --skip-lock) skip_lock=true ;; |
| 17 | + --optionally-lock) optionally_lock=true ;; |
14 | 18 | *) python_version="${1:-$python_version}" ;; # Take the first non-flag argument as the input |
15 | 19 | esac |
16 | 20 | shift |
17 | 21 | done |
18 | 22 |
|
| 23 | +# Ensure that --skip-lock and --optionally-lock are mutually exclusive |
| 24 | +if [ "$skip_lock" = "true" ] && [ "$optionally_lock" = "true" ]; then |
| 25 | + echo "Error: --skip-lock and --optionally-lock cannot be used together." >&2 |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
19 | 29 | export UV_PYTHON="$python_version" |
20 | 30 | export UV_PYTHON_PREFERENCE=only-system |
21 | 31 |
|
22 | 32 | SCRIPT_DIR="$(dirname "$0")" |
23 | 33 | PROJECT_ROOT_DIR="$(realpath "$SCRIPT_DIR/..")" |
24 | 34 |
|
| 35 | +# If optionally_lock is set, decide whether to skip locking based on the presence of uv.lock |
| 36 | +if [ "$optionally_lock" = "true" ]; then |
| 37 | + if [ ! -f "$PROJECT_ROOT_DIR/uv.lock" ]; then |
| 38 | + skip_lock=true |
| 39 | + else |
| 40 | + skip_lock=false |
| 41 | + fi |
| 42 | +fi |
| 43 | + |
| 44 | +{% endraw %}{% if python_package_registry is defined and python_package_registry == "AWS CodeArtifact" %}{% raw %} |
| 45 | +aws sso login --profile={% endraw %}{{ core_infra_base_access_profile_name }}{% raw %} |
| 46 | +. "$SCRIPT_DIR/code-artifact-auth.sh"{% endraw %}{% endif %}{% raw %} |
| 47 | + |
25 | 48 | # Ensure that the lock file is in a good state |
26 | 49 | if [ "$skip_lock" = "false" ]; then |
27 | 50 | uv lock --check --directory "$PROJECT_ROOT_DIR" |
|
0 commit comments