Skip to content

Commit

Permalink
Normalize extra names passed in (#2668)
Browse files Browse the repository at this point in the history
Resolves #2655
  • Loading branch information
gaborbernat committed Dec 10, 2022
1 parent 17950f4 commit 8dff357
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2655.bugfix.rst
@@ -0,0 +1 @@
Normalize extra names passed in (fixes extra groups not being picked up during installation) - by :user:`gaborbernat`.
9 changes: 9 additions & 0 deletions src/tox/tox_env/python/runner.py
Expand Up @@ -6,6 +6,8 @@
from functools import partial
from typing import Set

from packaging.utils import canonicalize_name

from tox.report import HandledError
from tox.tox_env.errors import Skip
from tox.tox_env.package import Package
Expand Down Expand Up @@ -65,11 +67,18 @@ def _register_package_conf(self) -> bool:
pkg_type = self.pkg_type
if pkg_type == "skip":
return False

def _normalize_extras(values: set[str]) -> set[str]:
# although _ and . is allowed this will be normalized during packaging to -
# https://packaging.python.org/en/latest/specifications/dependency-specifiers/#grammar
return {canonicalize_name(v) for v in values}

self.conf.add_config(
keys=["extras"],
of_type=Set[str],
default=set(),
desc="extras to install of the target package",
post_process=_normalize_extras,
)
return True

Expand Down
22 changes: 22 additions & 0 deletions tests/tox_env/python/test_python_runner.py
Expand Up @@ -2,6 +2,8 @@

from pathlib import Path

import pytest

from tox.journal import EnvJournal
from tox.pytest import ToxProjectCreator
from tox.tox_env.package import PathPackage
Expand Down Expand Up @@ -99,3 +101,23 @@ def test_package_temp_dir_view(tox_project: ToxProjectCreator, demo_pkg_inline:
msg = f" D package {session_path} links to {Path('.pkg') / 'dist'/ wheel_name} ({project.path/ '.tox'}) "
assert msg in result.out
assert f" D delete package {project.path / '.tox' / session_path}" in result.out


@pytest.mark.parametrize(
("extra", "used_extra"),
[
("d_oc", "d-oc"),
("d-oc", "d-oc"),
("d.oc", "d-oc"),
],
)
def test_extras_are_normalized(
tox_project: ToxProjectCreator,
demo_pkg_inline: Path,
extra: str,
used_extra: str,
) -> None:
project = tox_project({"tox.ini": f"[testenv]\nextras={extra}"})
result = project.run("c", "-e", "py", "--root", str(demo_pkg_inline), "-k", "extras")
result.assert_success()
assert result.out == f"[testenv:py]\nextras = {used_extra}\n"

0 comments on commit 8dff357

Please sign in to comment.