Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/pip/_internal/models/format_control.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 from pip._vendor.packaging.utils import canonicalize_name | |
2 | |
3 from pip._internal.exceptions import CommandError | |
4 from pip._internal.utils.typing import MYPY_CHECK_RUNNING | |
5 | |
6 if MYPY_CHECK_RUNNING: | |
7 from typing import FrozenSet, Optional, Set | |
8 | |
9 | |
10 class FormatControl: | |
11 """Helper for managing formats from which a package can be installed. | |
12 """ | |
13 | |
14 __slots__ = ["no_binary", "only_binary"] | |
15 | |
16 def __init__(self, no_binary=None, only_binary=None): | |
17 # type: (Optional[Set[str]], Optional[Set[str]]) -> None | |
18 if no_binary is None: | |
19 no_binary = set() | |
20 if only_binary is None: | |
21 only_binary = set() | |
22 | |
23 self.no_binary = no_binary | |
24 self.only_binary = only_binary | |
25 | |
26 def __eq__(self, other): | |
27 # type: (object) -> bool | |
28 if not isinstance(other, self.__class__): | |
29 return NotImplemented | |
30 | |
31 if self.__slots__ != other.__slots__: | |
32 return False | |
33 | |
34 return all( | |
35 getattr(self, k) == getattr(other, k) | |
36 for k in self.__slots__ | |
37 ) | |
38 | |
39 def __repr__(self): | |
40 # type: () -> str | |
41 return "{}({}, {})".format( | |
42 self.__class__.__name__, | |
43 self.no_binary, | |
44 self.only_binary | |
45 ) | |
46 | |
47 @staticmethod | |
48 def handle_mutual_excludes(value, target, other): | |
49 # type: (str, Set[str], Set[str]) -> None | |
50 if value.startswith('-'): | |
51 raise CommandError( | |
52 "--no-binary / --only-binary option requires 1 argument." | |
53 ) | |
54 new = value.split(',') | |
55 while ':all:' in new: | |
56 other.clear() | |
57 target.clear() | |
58 target.add(':all:') | |
59 del new[:new.index(':all:') + 1] | |
60 # Without a none, we want to discard everything as :all: covers it | |
61 if ':none:' not in new: | |
62 return | |
63 for name in new: | |
64 if name == ':none:': | |
65 target.clear() | |
66 continue | |
67 name = canonicalize_name(name) | |
68 other.discard(name) | |
69 target.add(name) | |
70 | |
71 def get_allowed_formats(self, canonical_name): | |
72 # type: (str) -> FrozenSet[str] | |
73 result = {"binary", "source"} | |
74 if canonical_name in self.only_binary: | |
75 result.discard('source') | |
76 elif canonical_name in self.no_binary: | |
77 result.discard('binary') | |
78 elif ':all:' in self.only_binary: | |
79 result.discard('source') | |
80 elif ':all:' in self.no_binary: | |
81 result.discard('binary') | |
82 return frozenset(result) | |
83 | |
84 def disallow_binaries(self): | |
85 # type: () -> None | |
86 self.handle_mutual_excludes( | |
87 ':all:', self.no_binary, self.only_binary, | |
88 ) |