From 14cdef99d5d6d21c39b23a50169b0aec6ae3fd7b Mon Sep 17 00:00:00 2001 From: Wisaroot Lertthaweedech Date: Tue, 26 Aug 2025 19:29:17 +0700 Subject: [PATCH 1/2] feat: add poetry setup dev --- .amazonq/rules/development-rules.md | 20 +++++++++ common/update_brew.sh | 2 +- node/assert_tools.sh | 2 +- node/load_nvm.sh | 2 +- node/setup_dev.sh | 2 +- node/setup_zshrc_nvm.sh | 2 +- node/update_node.sh | 2 +- python/poetry/assert_setup_dev.sh | 13 ++++++ python/poetry/setup_dev.sh | 65 +++++++++++++++++++++++++++++ python/poetry/setup_poetry.sh | 8 ++++ python/setup_pipx.sh | 2 +- python/setup_pyenv.sh | 21 ++++++++++ python/setup_venv_zshrc.sh | 20 +++++++++ rust/assert_setup_dev.sh | 2 +- rust/setup_dev.sh | 2 +- shell/install_shell_deps.sh | 2 +- 16 files changed, 157 insertions(+), 10 deletions(-) create mode 100644 .amazonq/rules/development-rules.md create mode 100644 python/poetry/assert_setup_dev.sh create mode 100644 python/poetry/setup_dev.sh create mode 100644 python/poetry/setup_poetry.sh create mode 100644 python/setup_pyenv.sh create mode 100644 python/setup_venv_zshrc.sh diff --git a/.amazonq/rules/development-rules.md b/.amazonq/rules/development-rules.md new file mode 100644 index 0000000..aa06201 --- /dev/null +++ b/.amazonq/rules/development-rules.md @@ -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 diff --git a/common/update_brew.sh b/common/update_brew.sh index 28721bf..d09d23d 100755 --- a/common/update_brew.sh +++ b/common/update_brew.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -ex brew update brew upgrade diff --git a/node/assert_tools.sh b/node/assert_tools.sh index 60d3947..244b4cb 100755 --- a/node/assert_tools.sh +++ b/node/assert_tools.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -ex echo "Node: $(which node)" echo "NPM: $(which npm)" diff --git a/node/load_nvm.sh b/node/load_nvm.sh index 7a7a04c..e143a55 100755 --- a/node/load_nvm.sh +++ b/node/load_nvm.sh @@ -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 diff --git a/node/setup_dev.sh b/node/setup_dev.sh index cffd18e..50493e8 100755 --- a/node/setup_dev.sh +++ b/node/setup_dev.sh @@ -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" diff --git a/node/setup_zshrc_nvm.sh b/node/setup_zshrc_nvm.sh index bac5517..859c505 100755 --- a/node/setup_zshrc_nvm.sh +++ b/node/setup_zshrc_nvm.sh @@ -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 diff --git a/node/update_node.sh b/node/update_node.sh index 1151c03..86e7861 100755 --- a/node/update_node.sh +++ b/node/update_node.sh @@ -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" diff --git a/python/poetry/assert_setup_dev.sh b/python/poetry/assert_setup_dev.sh new file mode 100644 index 0000000..5218138 --- /dev/null +++ b/python/poetry/assert_setup_dev.sh @@ -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 +} diff --git a/python/poetry/setup_dev.sh b/python/poetry/setup_dev.sh new file mode 100644 index 0000000..f4112a2 --- /dev/null +++ b/python/poetry/setup_dev.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +set -exx + +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")/../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 diff --git a/python/poetry/setup_poetry.sh b/python/poetry/setup_poetry.sh new file mode 100644 index 0000000..8dce0e1 --- /dev/null +++ b/python/poetry/setup_poetry.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -exx + +pipx install poetry +pipx ensurepath +poetry config virtualenvs.in-project true +pipx inject poetry keyrings.google-artifactregistry-auth diff --git a/python/setup_pipx.sh b/python/setup_pipx.sh index 9a8997e..a3c3cd8 100755 --- a/python/setup_pipx.sh +++ b/python/setup_pipx.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -ex brew install pipx pipx upgrade-all diff --git a/python/setup_pyenv.sh b/python/setup_pyenv.sh new file mode 100644 index 0000000..f4d62b7 --- /dev/null +++ b/python/setup_pyenv.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -exx + +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" diff --git a/python/setup_venv_zshrc.sh b/python/setup_venv_zshrc.sh new file mode 100644 index 0000000..f1bf1b3 --- /dev/null +++ b/python/setup_venv_zshrc.sh @@ -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 diff --git a/rust/assert_setup_dev.sh b/rust/assert_setup_dev.sh index 8c3bbfc..dd7ee92 100755 --- a/rust/assert_setup_dev.sh +++ b/rust/assert_setup_dev.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -ex echo "Rust: $(which rustc)" echo "Cargo: $(which cargo)" diff --git a/rust/setup_dev.sh b/rust/setup_dev.sh index 467f95a..8dc1e84 100755 --- a/rust/setup_dev.sh +++ b/rust/setup_dev.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -ex brew install rustup rustup-init -y diff --git a/shell/install_shell_deps.sh b/shell/install_shell_deps.sh index e9d0f6a..6019616 100755 --- a/shell/install_shell_deps.sh +++ b/shell/install_shell_deps.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -ex if [[ "$OSTYPE" == "darwin"* ]]; then brew install shfmt shellcheck prettier From bfcccc6469b4e0636aa9e8a396e5549e13e0c8a4 Mon Sep 17 00:00:00 2001 From: Wisaroot Lertthaweedech Date: Tue, 26 Aug 2025 19:47:16 +0700 Subject: [PATCH 2/2] fix: correct poetry setup dev --- python/clean.sh | 13 +++++++++++ python/clean_all.sh | 12 ++++++++++ python/clean_venv.sh | 5 ++++ python/poetry/assert_python_poetry.sh | 33 +++++++++++++++++++++++++++ python/poetry/assert_setup_dev.sh | 0 python/poetry/setup_dev.sh | 5 +++- python/poetry/setup_poetry.sh | 2 +- python/setup_pyenv.sh | 2 +- python/setup_pyenv_zshrc.sh | 21 +++++++++++++++++ python/setup_venv_zshrc.sh | 0 10 files changed, 90 insertions(+), 3 deletions(-) create mode 100755 python/clean.sh create mode 100755 python/clean_all.sh create mode 100755 python/clean_venv.sh create mode 100755 python/poetry/assert_python_poetry.sh mode change 100644 => 100755 python/poetry/assert_setup_dev.sh mode change 100644 => 100755 python/poetry/setup_dev.sh mode change 100644 => 100755 python/poetry/setup_poetry.sh mode change 100644 => 100755 python/setup_pyenv.sh create mode 100755 python/setup_pyenv_zshrc.sh mode change 100644 => 100755 python/setup_venv_zshrc.sh diff --git a/python/clean.sh b/python/clean.sh new file mode 100755 index 0000000..de5aff4 --- /dev/null +++ b/python/clean.sh @@ -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 diff --git a/python/clean_all.sh b/python/clean_all.sh new file mode 100755 index 0000000..fadbf7f --- /dev/null +++ b/python/clean_all.sh @@ -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" diff --git a/python/clean_venv.sh b/python/clean_venv.sh new file mode 100755 index 0000000..84a8304 --- /dev/null +++ b/python/clean_venv.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -ex + +rm -rf .venv/ diff --git a/python/poetry/assert_python_poetry.sh b/python/poetry/assert_python_poetry.sh new file mode 100755 index 0000000..9c30992 --- /dev/null +++ b/python/poetry/assert_python_poetry.sh @@ -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 diff --git a/python/poetry/assert_setup_dev.sh b/python/poetry/assert_setup_dev.sh old mode 100644 new mode 100755 diff --git a/python/poetry/setup_dev.sh b/python/poetry/setup_dev.sh old mode 100644 new mode 100755 index f4112a2..6f94b70 --- a/python/poetry/setup_dev.sh +++ b/python/poetry/setup_dev.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -exx +set -ex while [[ $# -gt 0 ]]; do case $1 in @@ -33,6 +33,9 @@ chmod +x "$(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" diff --git a/python/poetry/setup_poetry.sh b/python/poetry/setup_poetry.sh old mode 100644 new mode 100755 index 8dce0e1..6fec4bd --- a/python/poetry/setup_poetry.sh +++ b/python/poetry/setup_poetry.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -exx +set -ex pipx install poetry pipx ensurepath diff --git a/python/setup_pyenv.sh b/python/setup_pyenv.sh old mode 100644 new mode 100755 index f4d62b7..575ff65 --- a/python/setup_pyenv.sh +++ b/python/setup_pyenv.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -exx +set -ex brew install pyenv --quiet if [ ! -d "$(pyenv root)/plugins/pyenv-update" ]; then diff --git a/python/setup_pyenv_zshrc.sh b/python/setup_pyenv_zshrc.sh new file mode 100755 index 0000000..e8d8d55 --- /dev/null +++ b/python/setup_pyenv_zshrc.sh @@ -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 diff --git a/python/setup_venv_zshrc.sh b/python/setup_venv_zshrc.sh old mode 100644 new mode 100755