diff --git a/README.md b/README.md index 10711f0..e4b0ef4 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,18 @@ Status | Network | Links | Ansible We're using [asdf](https://github.com/asdf-vm/asdf) to make sure that we all use the same versions across tools. Our repositories should contain versions defined in .tools-versions. -You can then use [`./setup.sh`](./asdf-setup.sh) to install all dependencies. +For Python dependencies, we use [uv](https://github.com/astral-sh/uv) - a fast Python package manager that creates and manages virtual environments. + +You can then use [`./setup.sh`](./setup.sh) to install all dependencies. This script will: +1. Install all asdf-managed tools +2. Check for uv installation (and optionally install it) +3. Create a Python virtual environment at `.venv` +4. Install all Python dependencies from `pyproject.toml` + +After running the setup script, activate the virtual environment with: +```shell +source .venv/bin/activate +``` ## Terraform From [`./terraform/devnet-0/`](./terraform/devnet-0/) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..293f465 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[project] +name = "template-devnets" +version = "0.1.0" +description = "Infrastructure code for Dev/Testnets" +requires-python = ">=3.9" +dependencies = [ + "ansible-lint==24.6.0", + "ansible==10.1.0", + "molecule-containers==2.0.0", + "molecule==24.6.0", + "netaddr==1.3.0", + "pip==24.0", + "requests==2.31", # Fix for not being able to run 'molecule test' using docker on mac. Issue: https://github.com/docker/docker-py/issues/3256 +] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.uv] +dev-dependencies = [] \ No newline at end of file diff --git a/setup.sh b/setup.sh index 9e5e95f..b6754af 100755 --- a/setup.sh +++ b/setup.sh @@ -1,5 +1,45 @@ #!/bin/bash -xe +# Check if asdf is installed +if ! command -v asdf &> /dev/null; then + echo "asdf not found. It is required to manage tool versions." + + # Check if Go is installed + if ! command -v go &> /dev/null; then + echo "Go is not installed. Go is required to install asdf." + echo "Please install Go first: https://golang.org/doc/install" + exit 1 + fi + + echo "" + echo "Would you like to install asdf using Go? (y/n)" + read -r response + + if [[ "$response" =~ ^[Yy]$ ]]; then + echo "Installing asdf v0.18.0 via Go..." + go install github.com/asdf-vm/asdf/cmd/asdf@v0.18.0 + + # Add Go bin to PATH for current session if not already there + export PATH="$HOME/go/bin:$PATH" + + # Check if asdf is now available + if command -v asdf &> /dev/null; then + echo "asdf installed successfully!" + echo "" + echo "Add the following to your shell configuration file (.bashrc, .zshrc, etc.):" + echo " export PATH=\"\$HOME/go/bin:\$PATH\"" + else + echo "Failed to install asdf. Please install it manually." + exit 1 + fi + else + echo "Aborting. Please install asdf manually:" + echo " go install github.com/asdf-vm/asdf/cmd/asdf@v0.18.0" + echo "Or visit: https://asdf-vm.com/guide/getting-started.html" + exit 1 + fi +fi + # Uninstall previous asdf plugins that shouldn't be managed anymore under asdf asdf uninstall ansible || true asdf uninstall ansible-lint || true @@ -17,5 +57,34 @@ asdf plugin add awscli || true asdf install asdf reshim -# Install python tools -pip install -r requirements.txt +# Check if uv is installed +if ! command -v uv &> /dev/null; then + echo "uv not found. It is required to manage Python dependencies." + echo "" + echo "Would you like to install uv automatically? (y/n)" + read -r response + + if [[ "$response" =~ ^[Yy]$ ]]; then + echo "Installing uv..." + curl -LsSf https://astral.sh/uv/install.sh | sh + # Add uv to PATH for current session + export PATH="$HOME/.cargo/bin:$PATH" + echo "uv installed successfully!" + else + echo "Aborting. Please install uv manually:" + echo " curl -LsSf https://astral.sh/uv/install.sh | sh" + echo "Or visit: https://github.com/astral-sh/uv" + exit 1 + fi +fi + +# Create virtual environment with uv +echo "Creating virtual environment with uv..." +uv venv .venv + +# Install Python dependencies with uv (doesn't require activation) +echo "Installing Python dependencies with uv..." +uv pip sync pyproject.toml + +echo "Setup complete! Run:" +echo "source .venv/bin/activate"