Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .amazonq/rules/development-rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Shared Scripts Development Rules

## Code Quality

- Run `make lint` at the end of any code changes to ensure code quality

## Discussion Mode

- **Discussion Mode**: Prefix prompt with "D:" to enter read-only discussion mode
- In discussion mode: NO code updates, only read files and provide analysis/suggestions
- Always start responses with "[Discussion Mode]" header when in discussion mode
- Never exit discussion mode automatically - only when user uses "XD:" prefix
- If user seems to want code changes, remind them to use "XD:" to exit discussion mode
- **Exit Discussion**: Use "XD:" prefix to exit discussion mode and resume normal operations

## Project Structure

- Follow the existing module organization by language/tool (`node/`, `rust/`, `python/`, `common/`, `shell/`)
- Place setup scripts as `setup_dev.sh` and validation scripts as `assert_setup_dev.sh`
- Maintain separation between different tool ecosystems
2 changes: 1 addition & 1 deletion common/update_brew.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

brew update
brew upgrade
Expand Down
2 changes: 1 addition & 1 deletion node/assert_tools.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

echo "Node: $(which node)"
echo "NPM: $(which npm)"
Expand Down
2 changes: 1 addition & 1 deletion node/load_nvm.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Expand Down
2 changes: 1 addition & 1 deletion node/setup_dev.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

chmod +x "$(dirname "$0")/setup_zshrc_nvm.sh"
"$(dirname "$0")/setup_zshrc_nvm.sh"
Expand Down
2 changes: 1 addition & 1 deletion node/setup_zshrc_nvm.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

if ! grep -q "# >>> nvm initialize >>>" ~/.zshrc; then
if [ -s ~/.zshrc ] && [ "$(tail -c 1 ~/.zshrc | wc -l)" -eq 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion node/update_node.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

chmod +x "$(dirname "$0")/load_nvm.sh"
source "$(dirname "$0")/load_nvm.sh"
Expand Down
13 changes: 13 additions & 0 deletions python/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -ex

rm -rf .mypy_cache/
rm -rf .ruff_cache/
rm -rf .coverage
rm -rf coverage.xml
rm -rf __pycache__/
rm -rf .pytest_cache
rm -rf dist
find . -type d -name "__pycache__" -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
12 changes: 12 additions & 0 deletions python/clean_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -ex

chmod +x "$(dirname "$0")/clean.sh"
"$(dirname "$0")/clean.sh"

chmod +x "$(dirname "$0")/clean_venv.sh"
"$(dirname "$0")/clean_venv.sh"

chmod +x "$(dirname "$0")/../common/clean_cache_env.sh"
"$(dirname "$0")/../common/clean_cache_env.sh"
5 changes: 5 additions & 0 deletions python/clean_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -ex

rm -rf .venv/
33 changes: 33 additions & 0 deletions python/poetry/assert_python_poetry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -ex

echo "Python: $(which python)"
echo "Pip: $(which pip)"
echo "Poetry: $(which poetry)"
FAILED=0

if ! test "$(which python)" = "$(pwd)/.venv/bin/python"; then
echo "❌ Python: ERROR - not using project .venv"
FAILED=1
else
echo "✅ Python: OK"
fi
if ! test "$(which pip)" = "$(pwd)/.venv/bin/pip"; then
echo "❌ Pip: ERROR - not using project .venv"
FAILED=1
else
echo "✅ Pip: OK"
fi
if ! test "$(which poetry)" = "$HOME/.local/bin/poetry"; then
echo "❌ Poetry: ERROR - not in ~/.local/bin"
FAILED=1
else
echo "✅ Poetry: OK"
fi
if [ $FAILED -eq 1 ]; then
echo "❌ Setup assertion failed."
exit 1
else
echo "✅ Setup assertion passed."
fi
13 changes: 13 additions & 0 deletions python/poetry/assert_setup_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -ex

echo "Asserting setup_dev..."

chmod +x "$(dirname "$0")/assert_python_poetry.sh"
"$(dirname "$0")/assert_python_poetry.sh"

make lint test 2>/dev/null || just lint test 2>/dev/null || {
echo "❌ Error: Neither Makefile nor justfile found with lint and test targets"
exit 1
}
68 changes: 68 additions & 0 deletions python/poetry/setup_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

set -ex

while [[ $# -gt 0 ]]; do
case $1 in
--colima-docker)
COLIMA_DOCKER=true
shift
;;
--python-version)
PYTHON_VERSION="$2"
shift
shift
;;
--just)
JUST=true
shift
;;
*)
echo "Unknown option $1"
exit 1
;;
esac
done

chmod +x "$(dirname "$0")/../clean.sh"
"$(dirname "$0")/../clean.sh"

chmod +x "$(dirname "$0")/../clean_venv.sh"
"$(dirname "$0")/../clean_venv.sh"

chmod +x "$(dirname "$0")/../../common/update_brew.sh"
"$(dirname "$0")/../../common/update_brew.sh"

# chmod +x "$(dirname "$0")/../../common/setup_gcloud.sh"
# "$(dirname "$0")/../../common/setup_gcloud.sh"

chmod +x "$(dirname "$0")/../setup_pyenv.sh"
"$(dirname "$0")/../setup_pyenv.sh"

chmod +x "$(dirname "$0")/../setup_pipx.sh"
"$(dirname "$0")/../setup_pipx.sh"

chmod +x "$(dirname "$0")/setup_poetry.sh"
"$(dirname "$0")/setup_poetry.sh"

if [[ "$COLIMA_DOCKER" == "true" ]]; then
echo "Ensure colima and docker are installed."
brew install colima docker --quiet
fi

if [[ "$JUST" == "true" ]]; then
echo "Ensure just are installed."
brew install just --quiet
fi

echo "Setup local python to ${PYTHON_VERSION}"
pyenv install "${PYTHON_VERSION}" --skip-existing

echo "Setup .venv"
poetry env use "python${PYTHON_VERSION}"

chmod +x "$(dirname "$0")/../setup_venv_zshrc.sh"
"$(dirname "$0")/../setup_venv_zshrc.sh"

poetry install
poetry run pre-commit install
8 changes: 8 additions & 0 deletions python/poetry/setup_poetry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -ex

pipx install poetry
pipx ensurepath
poetry config virtualenvs.in-project true
pipx inject poetry keyrings.google-artifactregistry-auth
2 changes: 1 addition & 1 deletion python/setup_pipx.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

brew install pipx
pipx upgrade-all
Expand Down
21 changes: 21 additions & 0 deletions python/setup_pyenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -ex

brew install pyenv --quiet
if [ ! -d "$(pyenv root)/plugins/pyenv-update" ]; then
git clone https://github.com/pyenv/pyenv-update.git "$(pyenv root)/plugins/pyenv-update"
fi
pyenv update

chmod +x "$(dirname "$0")/setup_pyenv_zshrc.sh"
"$(dirname "$0")/setup_pyenv_zshrc.sh"

LATEST_PYTHON_VERSION=$(
pyenv install --list |
grep -E '^\s*[0-9]+\.[0-9]+\.[0-9]+$' |
tail -1 |
xargs
)
pyenv install "$LATEST_PYTHON_VERSION" --skip-existing
pyenv global "$LATEST_PYTHON_VERSION"
21 changes: 21 additions & 0 deletions python/setup_pyenv_zshrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -ex

if ! grep -q "# >>> pyenv initialize >>>" ~/.zshrc; then
if [ -s ~/.zshrc ] && [ "$(tail -c 1 ~/.zshrc | wc -l)" -eq 0 ]; then
echo "" >>~/.zshrc
fi
{
echo ""
echo "# >>> pyenv initialize >>>"
echo "export PYENV_ROOT=\"\$HOME/.pyenv\""
echo "export PATH=\"\$PYENV_ROOT/bin:\$PATH\""
echo "eval \"\$(pyenv init --path)\""
echo "eval \"\$(pyenv init -)\""
echo "# <<< pyenv initialize <<<"
} >>~/.zshrc
echo "Added pyenv initialization to ~/.zshrc"
else
echo "pyenv initialization already exists in ~/.zshrc"
fi
20 changes: 20 additions & 0 deletions python/setup_venv_zshrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -ex

if ! grep -q "# >>> .venv initialize >>>" ~/.zshrc; then
if [ -s ~/.zshrc ] && [ "$(tail -c 1 ~/.zshrc | wc -l)" -eq 0 ]; then
echo "" >>~/.zshrc
fi
{
echo ""
echo "# >>> .venv initialize >>>"
echo "if [ -f \".venv/bin/activate\" ]; then"
echo " source .venv/bin/activate"
echo "fi"
echo "# <<< .venv initialize <<<"
} >>~/.zshrc
echo "Added .venv auto-activation to ~/.zshrc"
else
echo ".venv initialization already exists in ~/.zshrc"
fi
2 changes: 1 addition & 1 deletion rust/assert_setup_dev.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

echo "Rust: $(which rustc)"
echo "Cargo: $(which cargo)"
Expand Down
2 changes: 1 addition & 1 deletion rust/setup_dev.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

brew install rustup
rustup-init -y
Expand Down
2 changes: 1 addition & 1 deletion shell/install_shell_deps.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

if [[ "$OSTYPE" == "darwin"* ]]; then
brew install shfmt shellcheck prettier
Expand Down