Skip to content

Commit ef0542f

Browse files
hauntsaninjaneersighted
authored andcommitted
publish: print on failure, simplify logic
Should help with cases like #3397 The existing tests in tests/publishing/test_uploader.py should verify that this doesn't cause regressions.
1 parent 1ae27b0 commit ef0542f

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

poetry/publishing/uploader.py

+7-24
Original file line numberDiff line numberDiff line change
@@ -207,39 +207,19 @@ def post_data(self, file: Path) -> Dict[str, Any]:
207207

208208
def _upload(
209209
self, session: requests.Session, url: str, dry_run: Optional[bool] = False
210-
) -> None:
211-
try:
212-
self._do_upload(session, url, dry_run)
213-
except HTTPError as e:
214-
if (
215-
e.response.status_code == 400
216-
and "was ever registered" in e.response.text
217-
):
218-
try:
219-
self._register(session, url)
220-
except HTTPError as e:
221-
raise UploadError(e)
222-
223-
raise UploadError(e)
224-
225-
def _do_upload(
226-
self, session: requests.Session, url: str, dry_run: Optional[bool] = False
227210
) -> None:
228211
for file in self.files:
229212
# TODO: Check existence
230213

231-
resp = self._upload_file(session, url, file, dry_run)
232-
233-
if not dry_run:
234-
resp.raise_for_status()
214+
self._upload_file(session, url, file, dry_run)
235215

236216
def _upload_file(
237217
self,
238218
session: requests.Session,
239219
url: str,
240220
file: Path,
241221
dry_run: Optional[bool] = False,
242-
) -> requests.Response:
222+
) -> None:
243223
from cleo.ui.progress_bar import ProgressBar
244224

245225
data = self.post_data(file)
@@ -290,6 +270,11 @@ def _upload_file(
290270
"Redirects are not supported. "
291271
"Is the URL missing a trailing slash?"
292272
)
273+
elif resp.status_code == 400 and "was ever registered" in resp.text:
274+
self._register(session, url)
275+
resp.raise_for_status()
276+
else:
277+
resp.raise_for_status()
293278
except (requests.ConnectionError, requests.HTTPError) as e:
294279
if self._io.output.is_decorated():
295280
self._io.overwrite(
@@ -299,8 +284,6 @@ def _upload_file(
299284
finally:
300285
self._io.write_line("")
301286

302-
return resp
303-
304287
def _register(self, session: requests.Session, url: str) -> requests.Response:
305288
"""
306289
Register a package to a repository.

0 commit comments

Comments
 (0)