summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorq0w <43147888+q0w@users.noreply.github.com>2023-01-12 05:33:55 +0300
committerGitHub <noreply@github.com>2023-01-11 18:33:55 -0800
commit8d3d26b6b9b6c021c25ef8157db7e84f2daf166d (patch)
treea5592f27537e5390d260712eaa51c3a7afa3ee80
parentb8e47ce061b3da43d195e17f1782ee8a012e6f55 (diff)
downloadtox-git-8d3d26b6b9b6c021c25ef8157db7e84f2daf166d.tar.gz
Allow package names with env markers with pip binary options (#2853)
Fixes https://github.com/tox-dev/tox/issues/2814#issuecomment-1374804987
-rw-r--r--docs/changelog/2814.bugfix.rst1
-rw-r--r--src/tox/tox_env/python/pip/req/args.py28
-rw-r--r--src/tox/tox_env/python/pip/req/file.py13
-rw-r--r--tests/tox_env/python/pip/req/test_file.py7
4 files changed, 37 insertions, 12 deletions
diff --git a/docs/changelog/2814.bugfix.rst b/docs/changelog/2814.bugfix.rst
new file mode 100644
index 00000000..76a99c53
--- /dev/null
+++ b/docs/changelog/2814.bugfix.rst
@@ -0,0 +1 @@
+Allow using package names with env markers for pip's ``--no-binary`` and ``--only-binary`` options - by :user:`q0w`.
diff --git a/src/tox/tox_env/python/pip/req/args.py b/src/tox/tox_env/python/pip/req/args.py
index 3fd1f677..b1e01cdf 100644
--- a/src/tox/tox_env/python/pip/req/args.py
+++ b/src/tox/tox_env/python/pip/req/args.py
@@ -5,6 +5,8 @@ import re
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 @@ class AddUniqueAction(Action):
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)
diff --git a/src/tox/tox_env/python/pip/req/file.py b/src/tox/tox_env/python/pip/req/file.py
index 495ef194..d8b29558 100644
--- a/src/tox/tox_env/python/pip/req/file.py
+++ b/src/tox/tox_env/python/pip/req/file.py
@@ -15,7 +15,7 @@ import chardet
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 @@ class RequirementsFile:
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]:
diff --git a/tests/tox_env/python/pip/req/test_file.py b/tests/tox_env/python/pip/req/test_file.py
index d947510c..e387a8ac 100644
--- a/tests/tox_env/python/pip/req/test_file.py
+++ b/tests/tox_env/python/pip/req/test_file.py
@@ -177,6 +177,13 @@ _REQ_FILE_TEST_CASES = [
["--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"),