From 7f9726d50c59915c49b04261d7d8d72d2e9d9e49 Mon Sep 17 00:00:00 2001 From: 1nF0rmed Date: Mon, 15 Nov 2021 11:51:58 +0530 Subject: [PATCH] Refactor file exitence check to `_upload_file` Moves the logic of checking for files existence into the method `_upload_file` as it was handling the process of uploading the file. Changed the error message to be more appropriate to the raised error. Refactored to write error via `self._io`. --- src/poetry/publishing/uploader.py | 8 ++++---- tests/publishing/test_uploader.py | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/poetry/publishing/uploader.py b/src/poetry/publishing/uploader.py index 57ca1ae85bc..82369393c9d 100644 --- a/src/poetry/publishing/uploader.py +++ b/src/poetry/publishing/uploader.py @@ -212,10 +212,6 @@ def _upload( self, session: requests.Session, url: str, dry_run: Optional[bool] = False ) -> None: for file in self.files: - if not file.is_file(): - raise UploadError( - "Wheel or Tar files associated with the Project Package do not exist" - ) self._upload_file(session, url, file, dry_run) @@ -228,6 +224,10 @@ def _upload_file( ) -> None: from cleo.ui.progress_bar import ProgressBar + if not file.is_file(): + self._io.write_error(f"Archive ({file}) does not exist", True) + raise UploadError(f"Archive ({file}) does not exist") + data = self.post_data(file) data.update( { diff --git a/tests/publishing/test_uploader.py b/tests/publishing/test_uploader.py index 4cf01423802..f129be230cb 100644 --- a/tests/publishing/test_uploader.py +++ b/tests/publishing/test_uploader.py @@ -68,6 +68,4 @@ def test_uploader_properly_handles_file_not_existing(mocker, http, uploader): with pytest.raises(UploadError) as e: uploader.upload("https://foo.com") - assert "Wheel or Tar files associated with the Project Package do not exist" == str( - e.value - ) + assert f"Archive ({uploader.files[0]}) does not exist" == str(e.value)