Skip to content

Commit 23cbc31

Browse files
committed
copier scripts
1 parent b1120ca commit 23cbc31

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: v0.0.7-22-gf36c22e
2+
_commit: v0.0.7-23-g1d1a72e
33
_src_path: gh:LabAutomationAndScreening/copier-base-template.git
44
description: Copier template for creating Python libraries and executables
55
python_ci_versions:

.devcontainer/manual-setup-deps.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
11
#!/usr/bin/env sh
22
# can pass in the full major.minor.patch version of python as an optional argument
33
# 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+
46
set -ex
57

68
# Ensure that uv won't use the default system Python
79
python_version="3.12.7"
810

911
# Parse arguments
1012
skip_lock=false
13+
optionally_lock=false
1114
while [ "$#" -gt 0 ]; do
1215
case $1 in
1316
--skip-lock) skip_lock=true ;;
17+
--optionally-lock) optionally_lock=true ;;
1418
*) python_version="${1:-$python_version}" ;; # Take the first non-flag argument as the input
1519
esac
1620
shift
1721
done
1822

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+
1929
export UV_PYTHON="$python_version"
2030
export UV_PYTHON_PREFERENCE=only-system
2131

2232
SCRIPT_DIR="$(dirname "$0")"
2333
PROJECT_ROOT_DIR="$(realpath "$SCRIPT_DIR/..")"
2434

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+
45+
2546
# Ensure that the lock file is in a good state
2647
if [ "$skip_lock" = "false" ]; then
2748
uv lock --check --directory "$PROJECT_ROOT_DIR"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% if python_package_registry is defined and python_package_registry == "AWS CodeArtifact" %}{% raw %}#!/usr/bin/env bash
2+
set -e
3+
4+
# If none of these are set we can't possibly continue and should fail so you can fix it
5+
if [ -z "$AWS_PROFILE" ] && [ -z "$AWS_ACCESS_KEY_ID" ] && [ -z "$CODEARTIFACT_AUTH_TOKEN" ]; then
6+
echo "No AWS profile, access key, or auth token found, cannot proceed."
7+
exit 1
8+
else
9+
# Only regenerate the token if it doesn't exist or wasn't already set as an environmental variable (e.g. during CI or passed into a docker image build)
10+
if [ -z "$CODEARTIFACT_AUTH_TOKEN" ]; then
11+
echo "Fetching CodeArtifact token"
12+
export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token --domain {% endraw %}{{ repo_org_name }}{% raw %} --domain-owner {% endraw %}{{ aws_central_infrastructure_account_id }}{% raw %} --region {% endraw %}{{ aws_org_home_region }}{% raw %} --query authorizationToken --output text --profile {% endraw %}{{ core_infra_base_access_profile_name }}{% raw %})
13+
fi
14+
15+
export UV_INDEX_CODE_ARTIFACT_PRIMARY_USERNAME=aws
16+
export UV_INDEX_CODE_ARTIFACT_PRIMARY_PASSWORD="$CODEARTIFACT_AUTH_TOKEN"
17+
export UV_INDEX_CODE_ARTIFACT_STAGING_USERNAME=aws
18+
export UV_INDEX_CODE_ARTIFACT_STAGING_PASSWORD="$CODEARTIFACT_AUTH_TOKEN"
19+
20+
fi{% endraw %}{% endif %}

template/.devcontainer/manual-setup-deps.sh.jinja

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
11
{% raw %}#!/usr/bin/env sh
22
# can pass in the full major.minor.patch version of python as an optional argument
33
# 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+
46
set -ex
57

68
# Ensure that uv won't use the default system Python
79
python_version="{% endraw %}{{ python_version }}{% raw %}"
810

911
# Parse arguments
1012
skip_lock=false
13+
optionally_lock=false
1114
while [ "$#" -gt 0 ]; do
1215
case $1 in
1316
--skip-lock) skip_lock=true ;;
17+
--optionally-lock) optionally_lock=true ;;
1418
*) python_version="${1:-$python_version}" ;; # Take the first non-flag argument as the input
1519
esac
1620
shift
1721
done
1822

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+
1929
export UV_PYTHON="$python_version"
2030
export UV_PYTHON_PREFERENCE=only-system
2131

2232
SCRIPT_DIR="$(dirname "$0")"
2333
PROJECT_ROOT_DIR="$(realpath "$SCRIPT_DIR/..")"
2434

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+
2548
# Ensure that the lock file is in a good state
2649
if [ "$skip_lock" = "false" ]; then
2750
uv lock --check --directory "$PROJECT_ROOT_DIR"

template/.devcontainer/post-start-command.sh.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -ex
44
# For some reason the directory is not setup correctly and causes build of devcontainer to fail since
55
# it doesn't have access to the workspace directory. This can normally be done in post-start-command
66
git config --global --add safe.directory /workspaces/{% endraw %}{{ repo_name }}{% if python_package_registry is defined and python_package_registry != "PyPI" %}{% raw %}
7-
echo "!!! In order to install dependencies, you must authenticate into the private registry, so run this script to complete the process: sh .devcontainer/manual-setup-deps.sh"{% endraw %}{% endif %}
7+
echo "!!! In order to install dependencies, you must authenticate into the private registry, so run this script to complete the process: source .devcontainer/manual-setup-deps.sh"{% endraw %}{% endif %}

0 commit comments

Comments
 (0)