Skip to content

Feature Request: Toplevel Environment Variables #2195

@swanysimon

Description

@swanysimon

I'm using prek with monorepo support in a Python repository, where I have several projects managed by uv. I also am using mise-en-place to manage other tools in the repository, and have uv_auto_venv so that I don't have to prefix things with uv run. This is standard on the team. Project structure, simplified:

root/
  prek.toml
  project1/      <-- python 3.14
    pyproject.toml
    prek.toml
  project2/      <-- python 3.13
    pyproject.toml
    prek.toml

All projects have some variation of the following hooks:

[[repos]]
repo = "local"

[[repos.hooks]]
id = "ruff-format"
name = "format python"
entry = "uv run ruff format"
language = "system"
pass_filenames = false
files = '''
(?x)^(
  pyproject\.toml |
  uv\.lock |
  .*\.py
)$
'''
priority = 10

[[repos.hooks]]
id = "ruff-check"
name = "lint python"
entry = "uv run ruff check"
language = "system"
pass_filenames = false
files = '''
(?x)^(
  pyproject\.toml |
  uv\.lock |
  .*\.py
)$
'''
priority = 20

What we do is to only operate on one project at a time. So I cd into project1 and do my work. When my prek hooks run, they run just fine. But when I update my local branch by merging in changes that include project2, my pre-push hooks now run against that other project. Because I'm in a uv virtual environment, those checks fail.

Would it be possible/reasonable to have a global configuration to set environment variables? Right now what I do is specify at each hook level:

env = {
    UV_PYTHON = "",
    VIRTUAL_ENV = "",
}

This prevents uv from picking up the project1 virtual environment (warning) and Python version (error), but it's very annoying to put into every hook. Could there be a toplevel config option to set environment variables?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaJust an idea

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions