Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: use truststore if available #1045

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions twine/cli.py
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import logging
import logging.config
from typing import Any, List, Tuple

Expand All @@ -23,6 +24,8 @@

import twine

logger = logging.getLogger(__name__)

args = argparse.Namespace()


Expand Down Expand Up @@ -69,6 +72,18 @@ def configure_output() -> None:
)


def init_truststore(required: bool = False) -> None:
try:
import truststore
except ImportError as exc:
logger.debug("Error importing truststore", exc_info=exc)
if required:
raise
else:
# https://truststore.readthedocs.io/en/latest/#using-truststore-with-requests
truststore.inject_into_ssl()


def list_dependencies_and_versions() -> List[Tuple[str, str]]:
deps = (
"importlib-metadata",
Expand Down Expand Up @@ -118,6 +133,8 @@ def dispatch(argv: List[str]) -> Any:

configure_output()

init_truststore()

main = registered_commands[args.command].load() # type: ignore[no-untyped-call] # python/importlib_metadata#288 # noqa: E501

return main(args.args)