Skip to content

Commit

Permalink
publish: print on failure, simplify logic
Browse files Browse the repository at this point in the history
Should help with cases like #3397

The existing tests in tests/publishing/test_uploader.py should verify
that this doesn't cause regressions.
  • Loading branch information
hauntsaninja authored and neersighted committed Nov 14, 2021
1 parent 1ae27b0 commit ef0542f
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,39 +207,19 @@ def post_data(self, file: Path) -> Dict[str, Any]:

def _upload(
self, session: requests.Session, url: str, dry_run: Optional[bool] = False
) -> None:
try:
self._do_upload(session, url, dry_run)
except HTTPError as e:
if (
e.response.status_code == 400
and "was ever registered" in e.response.text
):
try:
self._register(session, url)
except HTTPError as e:
raise UploadError(e)

raise UploadError(e)

def _do_upload(
self, session: requests.Session, url: str, dry_run: Optional[bool] = False
) -> None:
for file in self.files:
# TODO: Check existence

resp = self._upload_file(session, url, file, dry_run)

if not dry_run:
resp.raise_for_status()
self._upload_file(session, url, file, dry_run)

def _upload_file(
self,
session: requests.Session,
url: str,
file: Path,
dry_run: Optional[bool] = False,
) -> requests.Response:
) -> None:
from cleo.ui.progress_bar import ProgressBar

data = self.post_data(file)
Expand Down Expand Up @@ -290,6 +270,11 @@ def _upload_file(
"Redirects are not supported. "
"Is the URL missing a trailing slash?"
)
elif resp.status_code == 400 and "was ever registered" in resp.text:
self._register(session, url)
resp.raise_for_status()
else:
resp.raise_for_status()
except (requests.ConnectionError, requests.HTTPError) as e:
if self._io.output.is_decorated():
self._io.overwrite(
Expand All @@ -299,8 +284,6 @@ def _upload_file(
finally:
self._io.write_line("")

return resp

def _register(self, session: requests.Session, url: str) -> requests.Response:
"""
Register a package to a repository.
Expand Down

0 comments on commit ef0542f

Please sign in to comment.