mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Merge pull request #6026 from pradyunsg/format-control-cleanups
Minor cleanups to format_control.py
This commit is contained in:
commit
74c09b8537
|
@ -3,20 +3,22 @@ from pip._vendor.packaging.utils import canonicalize_name
|
||||||
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
||||||
|
|
||||||
if MYPY_CHECK_RUNNING:
|
if MYPY_CHECK_RUNNING:
|
||||||
from typing import Optional, Set # noqa: F401
|
from typing import Optional, Set, FrozenSet # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
class FormatControl(object):
|
class FormatControl(object):
|
||||||
"""A helper class for controlling formats from which packages are installed.
|
"""Helper for managing formats from which a package can be installed.
|
||||||
If a field is falsy, it isn't set. If it is {':all:'}, it should match all
|
|
||||||
packages except those listed in the other field. Only one field can be set
|
|
||||||
to {':all:'} at a time. The rest of the time exact package name matches
|
|
||||||
are listed, with any given package only showing up in one field at a time.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, no_binary=None, only_binary=None):
|
def __init__(self, no_binary=None, only_binary=None):
|
||||||
# type: (Optional[Set], Optional[Set]) -> None
|
# type: (Optional[Set], Optional[Set]) -> None
|
||||||
self.no_binary = set() if no_binary is None else no_binary
|
if no_binary is None:
|
||||||
self.only_binary = set() if only_binary is None else only_binary
|
no_binary = set()
|
||||||
|
if only_binary is None:
|
||||||
|
only_binary = set()
|
||||||
|
|
||||||
|
self.no_binary = no_binary
|
||||||
|
self.only_binary = only_binary
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self.__dict__ == other.__dict__
|
return self.__dict__ == other.__dict__
|
||||||
|
@ -52,6 +54,7 @@ class FormatControl(object):
|
||||||
target.add(name)
|
target.add(name)
|
||||||
|
|
||||||
def get_allowed_formats(self, canonical_name):
|
def get_allowed_formats(self, canonical_name):
|
||||||
|
# type: (str) -> FrozenSet
|
||||||
result = {"binary", "source"}
|
result = {"binary", "source"}
|
||||||
if canonical_name in self.only_binary:
|
if canonical_name in self.only_binary:
|
||||||
result.discard('source')
|
result.discard('source')
|
||||||
|
@ -64,6 +67,7 @@ class FormatControl(object):
|
||||||
return frozenset(result)
|
return frozenset(result)
|
||||||
|
|
||||||
def disallow_binaries(self):
|
def disallow_binaries(self):
|
||||||
|
# type: () -> None
|
||||||
self.handle_mutual_excludes(
|
self.handle_mutual_excludes(
|
||||||
':all:', self.no_binary, self.only_binary,
|
':all:', self.no_binary, self.only_binary,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue