Skip to content

feat(toolchain): allow users easily override coverage #3902

Open

Description

@aignas

This ticket I am going to repurpose for implementing some sort of method to allow users override coverage library used.

Things that we could do:

  • Get rid of the py script calling pip -> vendor the bzl file to load from. This is somewhat hard to maintain and when new toolchain version get added (or removed) the file may get stale. Goal state is - We have bzlmod API to set the versions and we have a diff_test to actually do the vendoring of the .bzl file. We should leverage uv.lock files to actually do the configuration, they can be either user or rules_python supplied.
  • Make the coverage package more similar to regular pip packages. Currently it is just an http_archive, but in reality we could have potentially something that is more similar to how it is configured. Potentials:
    • Create a coverage_collector rule that would not require us patching the coverage wheel.
    • Change the coverage collector bootstrap to not require patching.
    • Just include the py_library into the venv and let the rest work out naturally.
  • Have a some sort of hub for the coverage tool that is created by pip.parse(hub="coverage") where we use_repo("coverage") and then have in @rules_python an alias for the coverage tool. The python.toolchain then has python.default(coverage="@rules_python//python/private:coverage_alias"). The main idea is that this configuration could accept a regular target. Maybe we can depend on extracted_whl_srcs.

Out of scope:

  • Make pip.dep somehow provide package version, markers, etc to download a particular package. This is similar to feat(pypi): add pip.dep to declare abstract pypi dependencies #3850, but the idea is:
    • We (for now only rules_python) can define a default fallback venv to the unified_hub_repo alias, so that if the user does not select anything, it just works.
    • We use @pypi//coverage and it just works, if the user has a different coverage package version in their venv, it gets used instead.
    • The logic for such deps may be that this is for particular tools, like twine, pip, pip-tools, coverage. The interesting thing is that those tools could be each in its own venv if we are using them in exec configuration, i.e. as a tool runner. This suggests that we may need to rething this approach of using @pypi//<dep> and instead have something like @pypi//<dep> or @pypi_tool//<dep> where we should have something similar to the Add optional dependencies to the universal_hub #3923. For now we shall allow users define a different version.

TODO

Note

This list is a working plan and will be updated as the PRs land and the direction gets clearer.

PRs that can be reviewed independently:

Stacked PRs (merge in order, each contains the previous ones):

Follow-ups:

  • Drop coverage.patch once Bazel 7 is no longer supported: the rules_python bootstrap imports coverage in-process, so the sys.path patch of coverage/__main__.py only matters if the entry point is executed as a script (e.g. by the Bazel 7 native rules). The feat(toolchain): allow using the extracted coverage wheel as the coverage_tool #4433 test shows that the unpatched PyPI wheel works.
  • Decide whether the bundled coverage wheels should be deprecated in favour of the user supplied ones.

Done:

Related:

Activity

  1. changed the title [-]Idea - Leverage pip.dep for the coverage tooling[/-] [+]feat(toolchain): allow users easily override coverage[/+] on Nov 7, 2026
  2. self-assigned this
    on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions