|
7 | 7 |
|
8 | 8 | from packaging.tags import Tag |
9 | 9 |
|
| 10 | +from poetry.utils.helpers import canonicalize_name |
10 | 11 | from poetry.utils.patterns import wheel_file_re |
11 | 12 |
|
12 | 13 |
|
@@ -60,22 +61,52 @@ class Chooser: |
60 | 61 | def __init__(self, pool: Pool, env: Env) -> None: |
61 | 62 | self._pool = pool |
62 | 63 | self._env = env |
| 64 | + self._no_binary_policy: set[str] = set() |
| 65 | + |
| 66 | + def set_no_binary_policy(self, policy: str) -> None: |
| 67 | + self._no_binary_policy = { |
| 68 | + name.strip() if re.match(r":(all|none):", name) else canonicalize_name(name) |
| 69 | + for name in policy.split(",") |
| 70 | + } |
| 71 | + |
| 72 | + if {":all:", ":none:"} <= self._no_binary_policy: |
| 73 | + raise ValueError( |
| 74 | + "Ambiguous binary policy containing :all: and :none: given." |
| 75 | + ) |
| 76 | + |
| 77 | + def allow_binary(self, package_name: str) -> bool: |
| 78 | + if ":all:" in self._no_binary_policy: |
| 79 | + return False |
| 80 | + |
| 81 | + return ( |
| 82 | + not self._no_binary_policy |
| 83 | + or ":none:" in self._no_binary_policy |
| 84 | + or canonicalize_name(package_name) not in self._no_binary_policy |
| 85 | + ) |
63 | 86 |
|
64 | 87 | def choose_for(self, package: Package) -> Link: |
65 | 88 | """ |
66 | 89 | Return the url of the selected archive for a given package. |
67 | 90 | """ |
68 | 91 | links = [] |
69 | 92 | for link in self._get_links(package): |
70 | | - if link.is_wheel and not Wheel(link.filename).is_supported_by_environment( |
71 | | - self._env |
72 | | - ): |
73 | | - logger.debug( |
74 | | - "Skipping wheel %s as this is not supported by the current" |
75 | | - " environment", |
76 | | - link.filename, |
77 | | - ) |
78 | | - continue |
| 93 | + if link.is_wheel: |
| 94 | + if not self.allow_binary(package.name): |
| 95 | + logger.debug( |
| 96 | + "Skipping wheel for %s as requested in no binary policy for" |
| 97 | + " package (%s)", |
| 98 | + link.filename, |
| 99 | + package.name, |
| 100 | + ) |
| 101 | + continue |
| 102 | + |
| 103 | + if not Wheel(link.filename).is_supported_by_environment(self._env): |
| 104 | + logger.debug( |
| 105 | + "Skipping wheel %s as this is not supported by the current" |
| 106 | + " environment", |
| 107 | + link.filename, |
| 108 | + ) |
| 109 | + continue |
79 | 110 |
|
80 | 111 | if link.ext in {".egg", ".exe", ".msi", ".rpm", ".srpm"}: |
81 | 112 | logger.debug("Skipping unsupported distribution %s", link.filename) |
|
0 commit comments