Skip to content

Commit

Permalink
make dist-dir optional argument of init Uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-callonnec authored and bcallonnec committed Jan 29, 2024
1 parent b04f101 commit 1d8e2eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/poetry/console/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class PublishCommand(Command):
def handle(self) -> int:
from poetry.publishing.publisher import Publisher

publisher = Publisher(self.poetry, self.io)
dist_dir = self.option("dist-dir")

publisher = Publisher(self.poetry, self.io, Path(dist_dir))

# Building package first, if told
if self.option("build"):
Expand All @@ -68,8 +70,7 @@ def handle(self) -> int:

return 1

output_dir = self.io.input.options["dist-dir"]
self.call("build", args=f"--output {output_dir}")
self.call("build", args=f"--output {dist_dir}")

files = publisher.files
if not files:
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/publishing/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class Publisher:
Registers and publishes packages to remote repositories.
"""

def __init__(self, poetry: Poetry, io: IO) -> None:
def __init__(self, poetry: Poetry, io: IO, dist_dir: Path | None = None) -> None:
self._poetry = poetry
self._package = poetry.package
self._io = io
self._uploader = Uploader(poetry, io)
self._uploader = Uploader(poetry, io, dist_dir)
self._authenticator = Authenticator(poetry.config, self._io)

@property
Expand Down
18 changes: 9 additions & 9 deletions src/poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ def __init__(self, error: ConnectionError | HTTPError | str) -> None:


class Uploader:
def __init__(self, poetry: Poetry, io: IO) -> None:
def __init__(self, poetry: Poetry, io: IO, dist_dir: Path | None = None) -> None:
self._poetry = poetry
self._package = poetry.package
self._io = io
self._dist_dir = dist_dir or self.default_dist_dir
self._username: str | None = None
self._password: str | None = None

Expand All @@ -62,16 +63,15 @@ def user_agent(self) -> str:
return agent

@property
def dist_dir(self) -> Path:
io_dist_dir = "dist"
if "dist-dir" in self._io.input.options: # Option comes with publish command.
io_dist_dir = self._io.input.options["dist-dir"]
dist_dir = Path(io_dist_dir)
def default_dist_dir(self) -> Path:
return self._poetry.file.path.parent / "dist"

if not dist_dir.is_absolute():
dist_dir = self._poetry.file.path.parent / dist_dir
@property
def dist_dir(self) -> Path:
if not self._dist_dir.is_absolute():
return self._poetry.file.path.parent / self._dist_dir

return dist_dir
return self._dist_dir

@property
def files(self) -> list[Path]:
Expand Down

0 comments on commit 1d8e2eb

Please sign in to comment.