|
15 | 15 | from poetry.core.packages.project_package import ProjectPackage |
16 | 16 |
|
17 | 17 | from poetry.config.config import Config |
| 18 | +from poetry.exceptions import PoetryException |
18 | 19 | from poetry.json import validate_object |
19 | 20 | from poetry.packages.locker import Locker |
20 | 21 | from poetry.plugins.plugin import Plugin |
|
32 | 33 | from tomlkit.toml_document import TOMLDocument |
33 | 34 |
|
34 | 35 | from poetry.repositories import RepositoryPool |
35 | | - from poetry.repositories.legacy_repository import LegacyRepository |
| 36 | + from poetry.repositories.http_repository import HTTPRepository |
36 | 37 | from poetry.utils.dependency_specification import DependencySpec |
37 | 38 |
|
38 | 39 | logger = logging.getLogger(__name__) |
@@ -134,6 +135,7 @@ def create_pool( |
134 | 135 |
|
135 | 136 | pool = RepositoryPool() |
136 | 137 |
|
| 138 | + explicit_pypi = False |
137 | 139 | for source in sources: |
138 | 140 | repository = cls.create_package_source( |
139 | 141 | source, auth_config, disable_cache=disable_cache |
@@ -163,40 +165,71 @@ def create_pool( |
163 | 165 | io.write_line(message) |
164 | 166 |
|
165 | 167 | pool.add_repository(repository, priority=priority) |
| 168 | + if repository.name.lower() == "pypi": |
| 169 | + explicit_pypi = True |
166 | 170 |
|
167 | 171 | # Only add PyPI if no default repository is configured |
168 | | - if pool.has_default(): |
169 | | - if io.is_debug(): |
170 | | - io.write_line("Deactivating the PyPI repository") |
171 | | - else: |
172 | | - from poetry.repositories.pypi_repository import PyPiRepository |
173 | | - |
174 | | - if pool.has_primary_repositories(): |
175 | | - pypi_priority = Priority.SECONDARY |
| 172 | + if not explicit_pypi: |
| 173 | + if pool.has_default(): |
| 174 | + if io.is_debug(): |
| 175 | + io.write_line("Deactivating the PyPI repository") |
176 | 176 | else: |
177 | | - pypi_priority = Priority.DEFAULT |
| 177 | + from poetry.repositories.pypi_repository import PyPiRepository |
| 178 | + |
| 179 | + if pool.repositories: |
| 180 | + io.write_error_line( |
| 181 | + "<warning>" |
| 182 | + "Warning: In a future version of Poetry, PyPI will be disabled" |
| 183 | + " automatically if at least one custom source is configured" |
| 184 | + " with another priority than 'explicit'. In order to avoid" |
| 185 | + " a breaking change and make your pyproject.toml forward" |
| 186 | + " compatible, add PyPI explicitly via 'poetry source add pypi'." |
| 187 | + " By the way, this has the advantage that you can set the" |
| 188 | + " priority of PyPI as with any other source." |
| 189 | + "</warning>" |
| 190 | + ) |
| 191 | + |
| 192 | + if pool.has_primary_repositories(): |
| 193 | + pypi_priority = Priority.SECONDARY |
| 194 | + else: |
| 195 | + pypi_priority = Priority.DEFAULT |
178 | 196 |
|
179 | | - pool.add_repository( |
180 | | - PyPiRepository(disable_cache=disable_cache), priority=pypi_priority |
| 197 | + pool.add_repository( |
| 198 | + PyPiRepository(disable_cache=disable_cache), priority=pypi_priority |
| 199 | + ) |
| 200 | + |
| 201 | + if not pool.repositories: |
| 202 | + raise PoetryException( |
| 203 | + "At least one source must not be configured as 'explicit'." |
181 | 204 | ) |
182 | 205 |
|
183 | 206 | return pool |
184 | 207 |
|
185 | 208 | @classmethod |
186 | 209 | def create_package_source( |
187 | 210 | cls, source: dict[str, str], auth_config: Config, disable_cache: bool = False |
188 | | - ) -> LegacyRepository: |
| 211 | + ) -> HTTPRepository: |
| 212 | + from poetry.repositories.exceptions import InvalidSourceError |
189 | 213 | from poetry.repositories.legacy_repository import LegacyRepository |
| 214 | + from poetry.repositories.pypi_repository import PyPiRepository |
190 | 215 | from poetry.repositories.single_page_repository import SinglePageRepository |
191 | 216 |
|
192 | | - if "url" not in source: |
193 | | - raise RuntimeError("Unsupported source specified") |
| 217 | + try: |
| 218 | + name = source["name"] |
| 219 | + except KeyError: |
| 220 | + raise InvalidSourceError("Missing [name] in source.") |
| 221 | + |
| 222 | + if name.lower() == "pypi": |
| 223 | + if "url" in source: |
| 224 | + raise InvalidSourceError( |
| 225 | + "The PyPI repository cannot be configured with a custom url." |
| 226 | + ) |
| 227 | + return PyPiRepository(disable_cache=disable_cache) |
194 | 228 |
|
195 | | - # PyPI-like repository |
196 | | - if "name" not in source: |
197 | | - raise RuntimeError("Missing [name] in source.") |
198 | | - name = source["name"] |
199 | | - url = source["url"] |
| 229 | + try: |
| 230 | + url = source["url"] |
| 231 | + except KeyError: |
| 232 | + raise InvalidSourceError(f"Missing [url] in source {name!r}.") |
200 | 233 |
|
201 | 234 | repository_class = LegacyRepository |
202 | 235 |
|
|
0 commit comments