diff --git a/twine/cli.py b/twine/cli.py index 46d6d01b..69586ae5 100644 --- a/twine/cli.py +++ b/twine/cli.py @@ -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 @@ -23,6 +24,8 @@ import twine +logger = logging.getLogger(__name__) + args = argparse.Namespace() @@ -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", @@ -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)