Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tox-dev/tox
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4.2.7
Choose a base ref
...
head repository: tox-dev/tox
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4.2.8
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Jan 12, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8d3d26b View commit details
  2. release 4.2.8

    gaborbernat committed Jan 12, 2023

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    955a7fb View commit details
Showing with 44 additions and 12 deletions.
  1. +8 −0 docs/changelog.rst
  2. +26 −2 src/tox/tox_env/python/pip/req/args.py
  3. +3 −10 src/tox/tox_env/python/pip/req/file.py
  4. +7 −0 tests/tox_env/python/pip/req/test_file.py
8 changes: 8 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -4,6 +4,14 @@ Release History

.. towncrier release notes start
v4.2.8 (2023-01-11)
-------------------

Bugfixes - 4.2.8
~~~~~~~~~~~~~~~~
- Allow using package names with env markers for pip's ``--no-binary`` and ``--only-binary`` options - by :user:`q0w`. (:issue:`2814`)


v4.2.7 (2023-01-11)
-------------------

28 changes: 26 additions & 2 deletions src/tox/tox_env/python/pip/req/args.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
from argparse import Action, ArgumentParser, ArgumentTypeError, Namespace
from typing import IO, Any, NoReturn, Sequence

from tox.tox_env.python.pip.req.util import handle_binary_option


class _OurArgumentParser(ArgumentParser):
def print_usage(self, file: IO[str] | None = None) -> None: # noqa: U100
@@ -33,8 +35,8 @@ def _global_options(parser: ArgumentParser) -> None:
parser.add_argument("-r", "--requirement", action=AddUniqueAction, dest="requirements")
parser.add_argument("-e", "--editable", action=AddUniqueAction, dest="editables")
parser.add_argument("-f", "--find-links", action=AddUniqueAction)
parser.add_argument("--no-binary")
parser.add_argument("--only-binary")
parser.add_argument("--no-binary", action=BinaryAction, nargs="+")
parser.add_argument("--only-binary", action=BinaryAction, nargs="+")
parser.add_argument("--prefer-binary", action="store_true", default=False)
parser.add_argument("--require-hashes", action="store_true", default=False)
parser.add_argument("--pre", action="store_true", default=False)
@@ -90,3 +92,25 @@ def __call__(
current = getattr(namespace, self.dest)
if values not in current:
current.append(values)


class BinaryAction(Action):
def __call__(
self,
parser: ArgumentParser, # noqa: U100
namespace: Namespace,
values: str | Sequence[Any] | None,
option_string: str | None = None, # noqa: U100
) -> None:
if getattr(namespace, "no_binary", None) is None:
namespace.no_binary = set()
if getattr(namespace, "only_binary", None) is None:
namespace.only_binary = set()

args = (
(namespace.no_binary, namespace.only_binary)
if self.dest == "no_binary"
else (namespace.only_binary, namespace.no_binary)
)
assert values is not None
handle_binary_option(values[0], *args)
13 changes: 3 additions & 10 deletions src/tox/tox_env/python/pip/req/file.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
from packaging.requirements import InvalidRequirement, Requirement

from .args import build_parser
from .util import VCS, get_url_scheme, handle_binary_option, is_url, url_to_path
from .util import VCS, get_url_scheme, is_url, url_to_path

# Matches environment variable-style values in '${MY_VARIABLE_1}' with the variable name consisting of only uppercase
# letters, digits or the '_' (underscore). This follows the POSIX standard defined in IEEE Std 1003.1, 2013 Edition.
@@ -341,17 +341,10 @@ def _merge_option_line(self, base_opt: Namespace, opt: Namespace, filename: str)
base_opt.trusted_hosts = []
if host not in base_opt.trusted_hosts:
base_opt.trusted_hosts.append(host)

no_binary = base_opt.no_binary if hasattr(base_opt, "no_binary") else set()
only_binary = base_opt.only_binary if hasattr(base_opt, "only_binary") else set()
if opt.no_binary:
handle_binary_option(opt.no_binary, no_binary, only_binary)
base_opt.no_binary = opt.no_binary
if opt.only_binary:
handle_binary_option(opt.only_binary, only_binary, no_binary)
if no_binary:
base_opt.no_binary = no_binary
if only_binary:
base_opt.only_binary = only_binary
base_opt.only_binary = opt.only_binary

@staticmethod
def _break_args_options(line: str) -> tuple[str, str]:
7 changes: 7 additions & 0 deletions tests/tox_env/python/pip/req/test_file.py
Original file line number Diff line number Diff line change
@@ -177,6 +177,13 @@
["--no-binary", {"foo"}],
id="no-binary-none-first",
),
pytest.param(
"--only-binary foo; sys_platform == 'aix'",
{"only_binary": {"foo;"}},
[],
["--only-binary", {"foo;"}],
id="only-binary-and-env-marker",
),
pytest.param("####### example-requirements.txt #######", {}, [], [], id="comment"),
pytest.param("\t##### Requirements without Version Specifiers ######", {}, [], [], id="tab and comment"),
pytest.param(" # start", {}, [], [], id="space and comment"),