2018-08-04 21:07:13 +02:00
|
|
|
from pip._vendor.packaging.utils import canonicalize_name
|
|
|
|
|
2018-10-28 17:42:15 +01:00
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
|
|
|
|
|
|
|
if MYPY_CHECK_RUNNING:
|
2019-02-22 12:17:07 +01:00
|
|
|
from typing import Optional, Set, FrozenSet
|
2018-10-28 17:42:15 +01:00
|
|
|
|
2018-08-04 21:07:13 +02:00
|
|
|
|
|
|
|
class FormatControl(object):
|
2018-11-21 09:53:48 +01:00
|
|
|
"""Helper for managing formats from which a package can be installed.
|
2018-08-04 21:07:13 +02:00
|
|
|
"""
|
2018-11-21 09:53:48 +01:00
|
|
|
|
2018-08-28 19:19:09 +02:00
|
|
|
def __init__(self, no_binary=None, only_binary=None):
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: (Optional[Set], Optional[Set]) -> None
|
2018-11-21 09:53:48 +01:00
|
|
|
if no_binary is None:
|
|
|
|
no_binary = set()
|
|
|
|
if only_binary is None:
|
|
|
|
only_binary = set()
|
|
|
|
|
|
|
|
self.no_binary = no_binary
|
|
|
|
self.only_binary = only_binary
|
2018-08-04 21:07:13 +02:00
|
|
|
|
2018-08-28 17:37:45 +02:00
|
|
|
def __eq__(self, other):
|
|
|
|
return self.__dict__ == other.__dict__
|
2018-08-04 21:07:13 +02:00
|
|
|
|
2018-08-28 19:19:09 +02:00
|
|
|
def __ne__(self, other):
|
|
|
|
return not self.__eq__(other)
|
|
|
|
|
2018-08-28 17:37:45 +02:00
|
|
|
def __repr__(self):
|
|
|
|
return "{}({}, {})".format(
|
|
|
|
self.__class__.__name__,
|
|
|
|
self.no_binary,
|
|
|
|
self.only_binary
|
2018-08-04 21:07:13 +02:00
|
|
|
)
|
|
|
|
|
2018-08-28 17:37:45 +02:00
|
|
|
@staticmethod
|
|
|
|
def handle_mutual_excludes(value, target, other):
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: (str, Optional[Set], Optional[Set]) -> None
|
2018-08-04 21:07:13 +02:00
|
|
|
new = value.split(',')
|
|
|
|
while ':all:' in new:
|
|
|
|
other.clear()
|
|
|
|
target.clear()
|
|
|
|
target.add(':all:')
|
|
|
|
del new[:new.index(':all:') + 1]
|
|
|
|
# Without a none, we want to discard everything as :all: covers it
|
|
|
|
if ':none:' not in new:
|
|
|
|
return
|
|
|
|
for name in new:
|
|
|
|
if name == ':none:':
|
|
|
|
target.clear()
|
|
|
|
continue
|
|
|
|
name = canonicalize_name(name)
|
|
|
|
other.discard(name)
|
|
|
|
target.add(name)
|
|
|
|
|
2018-08-28 17:37:45 +02:00
|
|
|
def get_allowed_formats(self, canonical_name):
|
2018-11-21 09:53:48 +01:00
|
|
|
# type: (str) -> FrozenSet
|
2018-08-04 21:07:13 +02:00
|
|
|
result = {"binary", "source"}
|
|
|
|
if canonical_name in self.only_binary:
|
|
|
|
result.discard('source')
|
|
|
|
elif canonical_name in self.no_binary:
|
|
|
|
result.discard('binary')
|
|
|
|
elif ':all:' in self.only_binary:
|
|
|
|
result.discard('source')
|
|
|
|
elif ':all:' in self.no_binary:
|
|
|
|
result.discard('binary')
|
|
|
|
return frozenset(result)
|
|
|
|
|
2018-08-28 17:37:45 +02:00
|
|
|
def disallow_binaries(self):
|
2018-11-21 09:53:48 +01:00
|
|
|
# type: () -> None
|
2018-08-28 17:37:45 +02:00
|
|
|
self.handle_mutual_excludes(
|
2018-08-04 21:07:13 +02:00
|
|
|
':all:', self.no_binary, self.only_binary,
|
|
|
|
)
|