Skip to content

Commit

Permalink
Refactor file exitence check to _upload_file
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
1nF0rmed committed Nov 15, 2021
1 parent e833fad commit 7f9726d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/poetry/publishing/uploader.py
Expand Up @@ -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)

Expand All @@ -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(
{
Expand Down
4 changes: 1 addition & 3 deletions tests/publishing/test_uploader.py
Expand Up @@ -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)

0 comments on commit 7f9726d

Please sign in to comment.