Skip to content

Commit d0682cb

Browse files
committed
change to :all: has lower priority
1 parent 3f74504 commit d0682cb

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

docs/configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ This configuration is ignored when `installer.parallel` is set to `false`.
221221

222222
When set, this configuration allows users to disallow the use of binary distribution format for all, none or specific packages.
223223

224-
If both `installer.no-binary` and `installer.only-binary` configurations match a package, `installer.no-binary` takes precedence.
225-
226224
| Configuration | Description |
227225
|------------------------|------------------------------------------------------------|
228226
| `:all:` or `true` | Disallow binary distributions for all packages. |
229227
| `:none:` or `false` | Allow binary distributions for all packages. |
230228
| `package[,package,..]` | Disallow binary distributions for specified packages only. |
231229

230+
If both `installer.no-binary` and `installer.only-binary` are set, explicit package names will take precedence over `:all:`.
231+
232232
{{% note %}}
233233
As with all configurations described here, this is a user specific configuration. This means that this
234234
is not taken into consideration when a lockfile is generated or dependencies are resolved. This is
@@ -271,7 +271,7 @@ across all your projects if incorrectly set.
271271
When set, this configuration allows users to enforce the use of binary distribution format for all, none or
272272
specific packages.
273273

274-
If both `installer.no-binary` and `installer.only-binary` configurations match a package, `installer.no-binary` takes precedence.
274+
If both `installer.no-binary` and `installer.only-binary` are set, explicit package names will take precedence over `:all:`.
275275

276276
{{% note %}}
277277
Please refer to [`installer.no-binary`]({{< relref "configuration#installerno-binary" >}}) for information on allowed

src/poetry/config/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def allows(self, package_name: str) -> bool:
9797
or canonicalize_name(package_name) not in self.packages
9898
)
9999

100+
def has_exact_package(self, package_name: str) -> bool:
101+
return canonicalize_name(package_name) in self.packages
102+
100103
@classmethod
101104
def is_reserved(cls, name: str) -> bool:
102105
return bool(re.match(r":(all|none):", name))

src/poetry/installation/chooser.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ def choose_for(self, package: Package) -> Link:
6161
links_seen += 1
6262

6363
if link.is_wheel:
64-
if not self._no_binary_policy.allows(package.name):
64+
if not self._no_binary_policy.allows(package.name) and (
65+
not self._only_binary_policy.has_exact_package(package.name)
66+
or self._no_binary_policy.has_exact_package(package.name)
67+
):
6568
logger.debug(
6669
"Skipping wheel for %s as requested in no binary policy for"
6770
" package (%s)",
@@ -84,19 +87,22 @@ def choose_for(self, package: Package) -> Link:
8487
logger.debug("Skipping unsupported distribution %s", link.filename)
8588
continue
8689

87-
if link.is_sdist and not self._only_binary_policy.allows(package.name):
88-
if not self._no_binary_policy.allows(package.name):
89-
# no-binary policy takes precedence over only-binary policy
90-
pass
91-
else:
92-
logger.debug(
93-
"Skipping source distribution for %s as requested in only binary policy for"
94-
" package (%s)",
95-
link.filename,
96-
package.name,
97-
)
98-
sdists_skipped += 1
99-
continue
90+
if (
91+
link.is_sdist
92+
and not self._only_binary_policy.allows(package.name)
93+
and (
94+
not self._no_binary_policy.has_exact_package(package.name)
95+
or self._only_binary_policy.has_exact_package(package.name)
96+
)
97+
):
98+
logger.debug(
99+
"Skipping source distribution for %s as requested in only binary policy for"
100+
" package (%s)",
101+
link.filename,
102+
package.name,
103+
)
104+
sdists_skipped += 1
105+
continue
100106

101107
links.append(link)
102108

tests/installation/test_chooser.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,23 @@ def test_chooser_only_binary_policy(
122122
@pytest.mark.parametrize(
123123
("no_binary", "only_binary", "filename"),
124124
[
125-
# no `no_binary` for pytest
125+
# no `no_binary` nor `only_binary`
126126
(":none:", ":none:", "pytest-3.5.0-py2.py3-none-any.whl"),
127-
(":none:", ":all:", "pytest-3.5.0-py2.py3-none-any.whl"),
128127
("black", "black", "pytest-3.5.0-py2.py3-none-any.whl"),
129-
("black", "pytest", "pytest-3.5.0-py2.py3-none-any.whl"),
130-
# `no_binary` but no `only_binary` for pytest
128+
# `no_binary` only
131129
(":all:", ":none:", "pytest-3.5.0.tar.gz"),
132130
("pytest", "black", "pytest-3.5.0.tar.gz"),
133-
# both `no_binary` and `only_binary` for pytest (`no_binary` should take precedence)
134-
("pytest", "pytest", "pytest-3.5.0.tar.gz"),
135-
(":all:", ":all:", "pytest-3.5.0.tar.gz"),
131+
# `only_binary` only
132+
(":none:", ":all:", "pytest-3.5.0-py2.py3-none-any.whl"),
133+
("black", "pytest", "pytest-3.5.0-py2.py3-none-any.whl"),
134+
# both `no_binary` and `only_binary`
135+
("pytest", "pytest", None),
136+
(":all:", ":all:", None),
136137
("pytest", ":all:", "pytest-3.5.0.tar.gz"),
137-
("pytest,black", "pytest,black", "pytest-3.5.0.tar.gz"),
138+
(":all:", "pytest", "pytest-3.5.0-py2.py3-none-any.whl"),
139+
140+
# complex cases
141+
("pytest,black", "pytest,black", None),
138142
],
139143
)
140144
@pytest.mark.parametrize("source_type", ["", "legacy"])

0 commit comments

Comments
 (0)