Skip to content

Commit 7f9726d

Browse files
committed
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`.
1 parent e833fad commit 7f9726d

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/poetry/publishing/uploader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ def _upload(
212212
self, session: requests.Session, url: str, dry_run: Optional[bool] = False
213213
) -> None:
214214
for file in self.files:
215-
if not file.is_file():
216-
raise UploadError(
217-
"Wheel or Tar files associated with the Project Package do not exist"
218-
)
219215

220216
self._upload_file(session, url, file, dry_run)
221217

@@ -228,6 +224,10 @@ def _upload_file(
228224
) -> None:
229225
from cleo.ui.progress_bar import ProgressBar
230226

227+
if not file.is_file():
228+
self._io.write_error(f"Archive ({file}) does not exist", True)
229+
raise UploadError(f"Archive ({file}) does not exist")
230+
231231
data = self.post_data(file)
232232
data.update(
233233
{

tests/publishing/test_uploader.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,4 @@ def test_uploader_properly_handles_file_not_existing(mocker, http, uploader):
6868
with pytest.raises(UploadError) as e:
6969
uploader.upload("https://foo.com")
7070

71-
assert "Wheel or Tar files associated with the Project Package do not exist" == str(
72-
e.value
73-
)
71+
assert f"Archive ({uploader.files[0]}) does not exist" == str(e.value)

0 commit comments

Comments
 (0)