Skip to content

Fix extras with underscores not matching hyphenated metadata#3727

Merged
gaborbernat merged 3 commits intotox-dev:mainfrom
worksbyfriday:fix-extras-normalization
Feb 17, 2026
Merged

Fix extras with underscores not matching hyphenated metadata#3727
gaborbernat merged 3 commits intotox-dev:mainfrom
worksbyfriday:fix-extras-normalization

Conversation

@worksbyfriday
Copy link
Contributor

Summary

Fixes #3433 — extras with underscores in tox.ini (e.g. snake_case) were not matching hyphenated extra names in package metadata (e.g. Provides-Extra: snake-case), causing their dependencies to be silently skipped.

Root cause

dependencies_with_extras_from_markers() compared todo (from tox.ini extras) against extra_markers (from metadata markers) using set intersection, but neither side was normalized. When setuptools normalizes underscores to hyphens in wheel metadata, "snake_case" & {"snake-case"} produces an empty set, skipping all dependencies for that extra.

Fix

Normalize extra names using canonicalize_name() (from packaging.utils, already imported) at three points:

  1. Requested extras from tox.ini — normalized when building the todo set
  2. Extra markers from metadata — normalized when extracting from dependency markers
  3. Recursive extras from req.extras — normalized when discovered during resolution

This ensures underscore/hyphen equivalence throughout the resolution process, consistent with PEP 685.

Tests

Added three test cases:

  • test_extras_underscore_hyphen_matching — underscores in extras match hyphens in markers
  • test_extras_underscore_in_markers — hyphens in extras match underscores in markers
  • test_extras_normalization_with_recursive — recursive extras with underscore/hyphen mismatch

All existing tests pass (the test_load_dependency_no_extra ordering failure is pre-existing on main).

worksbyfriday and others added 3 commits February 17, 2026 17:28
…#3433)

Normalize extra names using canonicalize_name() when matching extras
from tox.ini against extra markers in package metadata. This ensures
that e.g. "snake_case" in tox.ini matches "snake-case" in wheel
Provides-Extra headers and dependency markers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@worksbyfriday worksbyfriday force-pushed the fix-extras-normalization branch from 1b8c269 to 379551f Compare February 17, 2026 17:28
@gaborbernat gaborbernat merged commit 00f79b9 into tox-dev:main Feb 17, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tox is unable to discover all the deps across multiple extras

2 participants