Skip to content

Latest commit

 

History

History
143 lines (101 loc) · 4.27 KB

README.md

File metadata and controls

143 lines (101 loc) · 4.27 KB

uv-example

This project uses uv and task to manage this Python packaging and running all of its development tasks.

  1. Install uv

    Linux / macOS
    curl -LsSf https://astral.sh/uv/install.sh | sh
    brew
    brew install uv
    Windows
    powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  2. Install task

    Linux / macOS
    sh -c "$(curl -LsSf https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin
    brew
    brew install go-task
    Windows

    You can use Chocolatey, Scoop, or Winget. Read more in the task installation guide.

    choco install go-task
    scoop install task
    winget install Task.Task
  3. Build the Virtual Environment

    task install
  4. Activate the Virtual Environment

    source .venv/bin/activate

Using Task

Taskfile Cheat Sheet

Command Description Command Notes
Install Project task install Installs the project and development dependencies
Run Tests task test Runs tests with pytest and coverage
Run Formatting task fmt Runs ruff code formatter
Run Linting task lint Runs ruff code linter
Run Type Checking task check Runs mypy static type checker
Run Code Fixers task fix Runs ruff to format and fix code
Build the Artifacts task build Build the Python Package Artifacts
Build the Docker Image task docker Build the Docker Image with the docker CLI
Run a Command task run Run a shell command: task run -- which python
Run the pre-commit Hooks task pre-commit Runs the pre-commit hooks

To see all available commands, simply ask task:

task --list

Project Decisions

PyPI + CodeArtifact

This project declares two PyPI repositories in the pyproject.toml file:

[[tool.uv.index]]
name = "pypi"
url = "https://pypi.org/simple"

[[tool.uv.index]]
name = "python-packages"
url = "https://smarterdx-166979434163.d.codeartifact.us-east-1.amazonaws.com/pypi/python-packages/simple"

[tool.uv.sources]
snowflake-sdx = {index = "python-packages"}

By default uv will use the first pypi index, but you can specify the python-packages index for internal packages from AWS CodeArtifact. This allows for explicit declaration of internal packages and to use the faster, cached, public PyPI repository for everything else. This also allows for the usage of UV_INDEX_PYTHON_PACKAGES_PASSWORD instead of UV_INDEX_URL / UV_EXTRA_INDEX_URL.

Docker Layer Caching

This project uses a multi-stage Dockerfile to build the final image. The builder stage first installs the project dependencies, and then installs the project itself to optimize for layer caching. The final image copies the virtual environment built in the builder stage to the final image, ensuring that the final image is as small as possible.

The choice to use a virtual environment in the Docker image, rather than installing directly into the system Python come from recommendations in the uv documentation and a simplicity recommendation from this blog post.