Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish: print on failure, simplify logic #3549

Merged
merged 1 commit into from
Nov 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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