Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize extra names passed in #2668

Merged
merged 1 commit into from Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"