Skip to content

Unexpected reordering to additional_dependencies, incompatible with pre-commit #1602

Closed

Description

@hehaoqian

Summary

prek deduplicate and reorders the content of additional_dependencies, using FxHashSet, then pass the arguments to uv pip install

pre-commit pass the contents of addtional_dependencies as-is, without reordering.

This causes incompatibility, when additional_dependencies contains arguments that is not dependencies,
such as [--index-url, https://pypi.org/simple]

NOTE: I am actual using other url as the real mirror, the above is just an example.

I know this can be workarounded by combining two arguments into one --index-url=https://pypi.org/simple.


but the current implementation has several problems:

  • This is not consistent with the behavior of pre-commit
  • The order of additional_dependencies is arbitrary, because it uses a HashSet. For a given hook with the deps foo and bar, prek may call uv pip install foo bar one time, and call uv pip install bar foo the other time. prek relies on the package manager ignores the effect of the dep ordering.

I suggest the following fix:

  • The de-duplication is optional, to match the behavior of pre-commit, that deps of [foo, bar], and deps of [bar, foo] are considered different, that should be installed in separate virtual env
  • Addtional options to .pre-commit-config.yaml, to opt-in the de-deduplication
  • When de-duplication is enabled, the arguments should be passed to uv pip install in fixed order, such as in alphabet order

If you don't think it is appropriate to change the current behavior of prek,
note this difference in https://prek.j178.dev/diff/,

but at least I do think relying on the iteration order of FxHashSet is a real bug

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-with-additional-dependencies
      name: Pseudo hook with additional dependencies
      entry: "true"
      language: python
      stages: [pre-commit]
      additional_dependencies:
      • editorconfig==0.17.1
      • platformdirs==4.5.1
      • pyyaml==6.0.3
      • tomli==2.4.0 ; python_full_version < '3.11'
      • --index-url
      • https://pypi.org/simple

Log file

2026-02-08T01:34:52.534443Z DEBUG prek: 0.3.2
2026-02-08T01:34:52.534562Z DEBUG Args: ["prek", "run", "--stage", "pre-commit", "pseudo-hook-with-additional-dependencies", "--config", "sample.yaml", "-vvv"]
2026-02-08T01:34:52.537391Z TRACE get_root: close time.busy=2.69ms time.idle=95.4µs
2026-02-08T01:34:52.537449Z DEBUG Git root: /home/main/src/hooks
2026-02-08T01:34:52.537501Z TRACE Executing /usr/bin/git ls-files --unmerged
2026-02-08T01:34:52.538921Z TRACE Include selectors: pseudo-hook-with-additional-dependencies
2026-02-08T01:34:52.538967Z TRACE Skip selectors: ``
2026-02-08T01:34:52.539029Z DEBUG discover{root="/home/main/src/hooks" config=Some("sample.yaml") refresh=false}: Loading project configuration path=sample.yaml
2026-02-08T01:34:52.539239Z TRACE discover{root="/home/main/src/hooks" config=Some("sample.yaml") refresh=false}: close time.busy=207µs time.idle=40.7µs
2026-02-08T01:34:52.539285Z TRACE Executing /usr/bin/git diff --exit-code --name-only -z sample.yaml
2026-02-08T01:34:52.541412Z TRACE Checking lock resource="store" path=/home/main/.cache/prek/.lock
2026-02-08T01:34:52.541449Z DEBUG Acquired lock resource="store"
2026-02-08T01:34:52.541721Z TRACE Skipping reading PEP 723 metadata for hook `pseudo-hook-with-additional-dependencies` because it already has `additional_dependencies`
2026-02-08T01:34:52.541764Z DEBUG Hooks going to run: ["pseudo-hook-with-additional-dependencies"]
2026-02-08T01:34:52.548219Z TRACE Found compatible uv alongside prek binary uv=/home/main/src/hooks/.venv/bin/uv
2026-02-08T01:34:52.548531Z DEBUG Installing environment hook=pseudo-hook-with-additional-dependencies target=/home/main/.cache/prek/hooks/python-0xAJM65rfUcgJRPRpkYU
2026-02-08T01:34:52.548565Z TRACE Executing `/home/main/src/hooks/.venv/bin/uv venv /home/main/.cache/prek/hooks/python-0xAJM65rfUcgJRPRpkYU --python-preference managed --no-project --project / --no-python-downloads [...]`
2026-02-08T01:34:52.576747Z DEBUG Venv created successfully with no downloads: `/home/main/.cache/prek/hooks/python-0xAJM65rfUcgJRPRpkYU`
2026-02-08T01:34:52.576785Z TRACE Installing additional dependencies: {"editorconfig==0.17.1", "platformdirs==4.5.1", "pyyaml==6.0.3", "https://pypi.org/simple", "--index-url", "tomli==2.4.0 ; python_full_version < '3.11'"}
2026-02-08T01:34:52.576821Z TRACE Executing `/home/main/src/hooks/.venv/bin/uv pip install --project / editorconfig==0.17.1 platformdirs==4.5.1 pyyaml==6.0.3 https://pypi.org/simple --index-url tomli==2.4.0 ; python_full_version < '3.11' [...]`
2026-02-08T01:34:52.583216Z TRACE Released lock path=/home/main/.cache/prek/.lock

Activity

  1. added
    bugSomething isn't working
    on Feb 8, 2026
  2. added a commit that references this issue on Feb 9, 2026
    190a848
  3. added
    documentationImprovements or additions to documentation
    and removed
    bugSomething isn't working
    documentationImprovements or additions to documentation
    on Feb 9, 2026
  4. added 2 commits that reference this issue on Feb 9, 2026
    a9687f7
    2b719ef
  5. added a commit that references this issue on Jul 12, 2026
    61cbcbf
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

    thinkingI'm thinking on this

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions