cookiecutter-uv

repository·main·Indexed 23 days ago

https://github.com/osprey-oss/cookiecutter-uv

A Python cookiecutter template for bootstrapping projects using uv for dependency management. It provides a complete suite of development, testing, and deployment tools, including GitHub Actions, Docker, VSCode devcontainers, and support for documentation tools like MkDocs or Zensical. Features include automated PyPI publishing, Codecov integration, and Ruff for linting and formatting.

Tokens
5.3K
Snippets
20
Records
44
Agent score
77%

What's inside cookiecutter-uv

  1. Quickstart: Create a new project with cookiecutter-uv

    main

    To initiate a new Python project using this template, use cookiecutter to clone and run the template. You can do this using uvx (recommended if you have uv installed) or via pip.

    1. Navigate to the directory where you want your project to reside.
    2. Run one of the following commands:
      • Using uvx (preferred):
        uvx cookiecutter https://github.com/osprey-oss/cookiecutter-uv.git
      • Using pip:
        pip install cookiecutter
        cookiecutter https://github.com/osprey-oss/cookiecutter-uv.git
    3. Follow the interactive prompts to configure your project settings.
    4. Once the process completes, a new directory will be created. Navigate into that directory and follow the project-specific README.md instructions to finish the setup.
    uvx cookiecutter https://github.com/osprey-oss/cookiecutter-uv.git
  2. Configure repository via ccp prompt arguments

    main

    When running the ccp command, an interactive prompt will start to configure your repository. You will be asked to provide several values that define the project's metadata, structure, and integrated tools.

    Project Metadata

    • author: Your full name.
    • email: Your email address.
    • author_github_handle: Your GitHub handle (e.g., <handle> in https://github.com/<handle>).
    • project_name: The name of your project. Use only alphanumeric characters and hyphens (-).
    • project_slug: The importable name of your project. It defaults to project_name with hyphens replaced by underscores (_). For example, if project_name is my-project, the project_slug will be my_project, allowing you to use from my_project import foo.
    • project_description: A short description of your project.
    • open_source_license: Select a license from the following options:
      1. MIT License
      2. BSD license
      3. ISC license
      4. Apache Software License 2.0
      5. GNU General Public License v3
      6. Not open source

    Project Structure

    • layout: Defines the directory structure. Options are:
      • flat (default): Places the Python module in the root directory.
      • src: Places the Python module inside a src directory.

    Integrated Features and Tools

    • include_github_actions: (y/n) Adds a .github directory with workflows for environment setup, formatting checks, and unit tests.
    • publish_to_pypi: (y/n) Adds functionality to the Makefile and GitHub workflows to simplify publishing via GitHub releases.
    • deptry: (y/n) Adds deptry to development dependencies and the make check command to detect dependency issues.
    • docs_tool: Choose a documentation tool:
      • mkdocs: Uses MkDocs.
      • zensical: Uses Zensical.
      • none: No documentation tool added. Note: Documentation is automatically deployed to GitHub Pages via the release-main workflow upon every new release.
    • codecov: (y/n) Adds code coverage checks using Codecov.
    • dockerfile: (y/n) Adds a simple Dockerfile.
    • devcontainer: (y/n) Adds a DevContainer specification with pre-installed pre-commit hooks and VSCode Python extension configuration.
  3. Upload your project to GitHub

    main

    After generating your project, initialize a Git repository and push it to a new, empty GitHub repository. Replace <project-name> with your project directory name and <github_author_handle> with your GitHub username.

    cd <project_name>
    git init -b main
    git add .
    git commit -m "Init commit"
    git remote add origin git@github.com:<github_author_handle>/<project_name>.git
    git push -u origin main
  4. Configure CI/CD with GitHub Actions

    main

    When generating a project with this template, you can enable GitHub Actions workflows by setting include_github_actions to "y" in your configuration.

    This adds a .github directory containing several workflows:

    • on-pull-request.yml: Runs when a pull request is opened or updated.
    • on-merge-to-main.yml: Runs whenever a new commit is made to the main branch.
    • on-release-main.yml: Runs when a new release is created on the main branch.

    Both on-pull-request.yml and on-merge-to-main.yml execute environment setup, tests, and code formatting checks using local actions defined in .github/workflows/run-checks and .github/workflows/setup-python-env.

    If tox is set to "y", all workflows will additionally check for compatibility across multiple Python versions.

  5. Enable Dockerfile generation in the project template

    main

    To include a Dockerfile in your generated project, set the dockerfile configuration option to "y" during the cookiecutter generation process.

    When enabled, the generated Dockerfile performs the following actions:

    1. Installs uv.
    2. Sets up the project environment.
    3. Executes foo.py as the default entrypoint when the container runs.
  6. How to trigger a release

    main

    To trigger the on-release-main.yml workflow and initiate automated publishing/deployment, you must create a new release on GitHub:

    1. Navigate to your repository on GitHub.
    2. Click Releases in the right-hand sidebar.
    3. Select Draft a new release (or visit https://github./<username>/<repository-name>/releases/new).
    4. Provide a release title.
    5. Create a new tag using the semantic versioning format *.*.* (where * is alphanumeric).
    6. Click Publish release.
  7. Generate a new project with cookiecutter-uv

    main

    To scaffold a new project using this template, navigate to your desired parent directory and run uvx cookiecutter pointing to the repository URL. You will be prompted for various arguments to customize your project.

    uvx cookiecutter https://github.com/osprey-oss/cookiecutter-uv.git
  8. Enable VSCode devcontainers for reproducible environments

    main

    When generating a project using this template, you can enable VSCode devcontainer support by setting the devcontainer option to "y".

    This creates a .devcontainer directory that uses the VSCode devcontainer specification to build a reproducible development environment. The environment automatically:

    • Pre-installs all uv dependencies required for development, testing, and building.
    • Installs pre-commit hooks.
    • Configures the VSCode Python extension to use the correct Python interpreter and pytest paths.
  9. Build and run the container image with Docker or Podman

    main

    Once the Dockerfile is generated, you can build and run the container using either Docker or Podman.

    Building the image

    Use the build command with a tag (-t) to name your image.

    Running in the background

    Use the run command with the -d flag to run the container in detached mode.

    Running in interactive mode

    To explore the container environment, run it in interactive mode (-it) with the --rm flag (to remove the container after exit) and override the entrypoint to bash.