Commit bc661dd7 by Shantanu Jain Committed by Bjorn Neergaard

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.
parent b64f313a
......@@ -208,30 +208,10 @@ class Uploader:
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,
......@@ -239,7 +219,7 @@ class Uploader:
url: str,
file: Path,
dry_run: Optional[bool] = False,
) -> requests.Response:
) -> None:
from cleo.ui.progress_bar import ProgressBar
data = self.post_data(file)
......@@ -290,6 +270,11 @@ class Uploader:
"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(
......@@ -299,8 +284,6 @@ class Uploader:
finally:
self._io.write_line("")
return resp
def _register(self, session: requests.Session, url: str) -> requests.Response:
"""
Register a package to a repository.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment