Skip to content

Different cwd compared to pre-commit when installing additional_deps of repo: localΒ #1603

Closed

Description

@hehaoqian

Summary

The behavior of repo: local between pre-commit and prek is different

In prek, the cwd during virtualenv installation of repo: local is the current repo.

In pre-commit, the cwd during virtualenv installation of repo: local is a pseudo repo.


For repo: local,

The pre-commit creates pseudo directory inside ~/.cache/pre-commit,
with pseduo setup scripts, such as setup.py

from setuptools import setup

setup(name='pre-commit-placeholder-package', version='0.0.0', py_modules=[])

During the installation of virtualenv, the cwd is inside that pseudo directory,
so that specify . in additional_dependencies does not work in the same way as many people expected,
and so specify python extra dependencies like .[foo] does not work either.

I think this is a good design of pre-commit that should be maintained,
that need to ensure additional_dependencies: does not depend on the content of local repository,
otherwise it is not safe to reuse the cached virtualenv, as the content of local repository may change.

Platform

Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 GNU/Linux

Version

prek 0.3.2

.pre-commit-config.yaml

repos:

  • repo: local
    hooks:
    • id: pseudo-hook-additional-dep-is-dot
      name: Additional Dependencies Is Dot
      entry: "true"
      language: python
      stages: [pre-commit]
      additional_dependencies:
      • .

Log file

Not needed

Activity

  1. changed the title [-]Different cwd compared to `pre-commit` when installing addidtional_deps of `repo: local`[/-] [+]Different cwd compared to `pre-commit` when installing additional_deps of `repo: local`[/+] on Feb 8, 2026
  2. added
    bugSomething isn't working
    on Feb 8, 2026
  3. added 3 commits that reference this issue on Feb 9, 2026
    190a848
    a9687f7
    2b719ef
  4. CarliJoy commented on Mar 12, 2026

    @CarliJoy

    This behaviour is not documented.
    I find quite confusing that pre-commit behaves this way.

    Is the only reason for this confusing behaviour of pre-commit reusing the cached virtualenv?

    If this is the case, could we not simply not cache the venv for local hooks but instead recreate it every run?
    As prek is using uv under the hood this should reduce the speed only minimal.
    uv already caches packages and only harldinks the their files if possible.
    Only overhead would be dependency resolution which is quite fast as well.

    Doing that prek would behave more like users would expect it.

  5. added a commit that references this issue on Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingthinkingI'm thinking on this

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions