From a3e6bbc02fa64686d1ece2d54f71ba8742ba4dcb Mon Sep 17 00:00:00 2001 From: Casey Howard Date: Tue, 1 Jun 2021 18:42:39 -0400 Subject: [PATCH 1/5] Add pip-style publish --- poetry/console/commands/publish.py | 25 +++++++++++++++++++++--- poetry/repositories/legacy_repository.py | 4 ++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/poetry/console/commands/publish.py b/poetry/console/commands/publish.py index bd777bb65d2..df21964f2ca 100644 --- a/poetry/console/commands/publish.py +++ b/poetry/console/commands/publish.py @@ -1,3 +1,4 @@ +import logging from pathlib import Path from typing import Optional @@ -5,6 +6,8 @@ from .command import Command +from poetry.installation.authenticator import Authenticator + class PublishCommand(Command): @@ -75,10 +78,26 @@ def handle(self) -> Optional[int]: Path(self.option("client-cert")) if self.option("client-cert") else None ) + + repository_name = self.option("repository") + username, password = self.option("username"), self.option("password") + if not username and not password: + for repository in self.poetry.pool.repositories: + try: + if repository_name == repository.name: + auth = repository.auth + except AttributeError: + logging.info('Attempted to access name of PyPI repository') + else: + if auth: + username = auth.username + password = auth.password + break + publisher.publish( - self.option("repository"), - self.option("username"), - self.option("password"), + repository_name, + username, + password, cert, client_cert, self.option("dry-run"), diff --git a/poetry/repositories/legacy_repository.py b/poetry/repositories/legacy_repository.py index 60fd8c8b6fa..69ccab9d9a8 100644 --- a/poetry/repositories/legacy_repository.py +++ b/poetry/repositories/legacy_repository.py @@ -217,6 +217,10 @@ def __init__( self._disable_cache = disable_cache + @property + def auth(self) -> Optional[requests.auth.HTTPBasicAuth]: + return self._authenticator.session.auth + @property def cert(self) -> Optional[Path]: return self._cert From d1a93fe259d4f9ffc3708d89b7f4e30a3cb7d4c0 Mon Sep 17 00:00:00 2001 From: Casey Howard Date: Tue, 1 Jun 2021 18:52:30 -0400 Subject: [PATCH 2/5] remove superfluous import --- poetry/console/commands/publish.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/poetry/console/commands/publish.py b/poetry/console/commands/publish.py index df21964f2ca..6f8c160bd42 100644 --- a/poetry/console/commands/publish.py +++ b/poetry/console/commands/publish.py @@ -6,8 +6,6 @@ from .command import Command -from poetry.installation.authenticator import Authenticator - class PublishCommand(Command): From 006a638dfec0a78854d2a3dfdabd3e9b609ab20c Mon Sep 17 00:00:00 2001 From: Casey Howard Date: Wed, 2 Jun 2021 10:21:03 -0400 Subject: [PATCH 3/5] Improve lookup and error handling --- poetry/console/commands/publish.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/poetry/console/commands/publish.py b/poetry/console/commands/publish.py index 6f8c160bd42..a82cd5bd7db 100644 --- a/poetry/console/commands/publish.py +++ b/poetry/console/commands/publish.py @@ -1,4 +1,3 @@ -import logging from pathlib import Path from typing import Optional @@ -80,17 +79,17 @@ def handle(self) -> Optional[int]: repository_name = self.option("repository") username, password = self.option("username"), self.option("password") if not username and not password: - for repository in self.poetry.pool.repositories: - try: - if repository_name == repository.name: - auth = repository.auth - except AttributeError: - logging.info('Attempted to access name of PyPI repository') - else: - if auth: - username = auth.username - password = auth.password - break + try: + repository = self.poetry.pool.repository(repository_name) + auth = repository.auth + except AttributeError as error: + raise AttributeError(f'No credentials available for {repository_name}') from error + except ValueError as error: + raise ValueError(f'No repository named {repository_name} found') + else: + if auth: + username = auth.username + password = auth.password publisher.publish( repository_name, From 46555d90030fb4d399d8571d8ae8a349053ce585 Mon Sep 17 00:00:00 2001 From: Casey Howard Date: Wed, 2 Jun 2021 10:43:47 -0400 Subject: [PATCH 4/5] Correct cert and cert_client errors as flagged by pytest --- poetry/console/commands/publish.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poetry/console/commands/publish.py b/poetry/console/commands/publish.py index a82cd5bd7db..975ddd0daff 100644 --- a/poetry/console/commands/publish.py +++ b/poetry/console/commands/publish.py @@ -78,7 +78,7 @@ def handle(self) -> Optional[int]: repository_name = self.option("repository") username, password = self.option("username"), self.option("password") - if not username and not password: + if repository_name and not username and not password: try: repository = self.poetry.pool.repository(repository_name) auth = repository.auth From 61f147a8810f4747fe2e4ed992c6059140fa510b Mon Sep 17 00:00:00 2001 From: Casey Howard Date: Thu, 3 Jun 2021 11:43:54 -0400 Subject: [PATCH 5/5] Correcting pre-commit failures --- poetry/console/commands/publish.py | 9 +++++---- poetry/repositories/legacy_repository.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/poetry/console/commands/publish.py b/poetry/console/commands/publish.py index 975ddd0daff..6ec2cf3480a 100644 --- a/poetry/console/commands/publish.py +++ b/poetry/console/commands/publish.py @@ -75,7 +75,6 @@ def handle(self) -> Optional[int]: Path(self.option("client-cert")) if self.option("client-cert") else None ) - repository_name = self.option("repository") username, password = self.option("username"), self.option("password") if repository_name and not username and not password: @@ -83,9 +82,11 @@ def handle(self) -> Optional[int]: repository = self.poetry.pool.repository(repository_name) auth = repository.auth except AttributeError as error: - raise AttributeError(f'No credentials available for {repository_name}') from error - except ValueError as error: - raise ValueError(f'No repository named {repository_name} found') + raise AttributeError( + f"No credentials available for {repository_name}" + ) from error + except ValueError: + raise ValueError(f"No repository named {repository_name} found") else: if auth: username = auth.username diff --git a/poetry/repositories/legacy_repository.py b/poetry/repositories/legacy_repository.py index 69ccab9d9a8..4dbb0ec8b38 100644 --- a/poetry/repositories/legacy_repository.py +++ b/poetry/repositories/legacy_repository.py @@ -220,7 +220,7 @@ def __init__( @property def auth(self) -> Optional[requests.auth.HTTPBasicAuth]: return self._authenticator.session.auth - + @property def cert(self) -> Optional[Path]: return self._cert