Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/enhancement-startup-22805.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "enhancement",
"category": "startup",
"description": "Defer importing ``docutils`` until help output is actually rendered. It was previously imported on every CLI invocation, along with ``pygments`` and ``PIL``, even for commands that never render help."
}
13 changes: 8 additions & 5 deletions awscli/clidriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@
)
from awscli.formatter import get_formatter
from awscli.handlers_registry import MAIN_COMMAND_TABLE_OPS
from awscli.help import (
OperationHelpCommand,
ProviderHelpCommand,
ServiceHelpCommand,
)
from awscli.lazy_emitter import LazyInitEmitter
from awscli.logger import (
disable_crt_logging,
Expand Down Expand Up @@ -534,6 +529,10 @@ def _create_cli_argument(self, option_name, option_params):
)

def create_help_command(self):
# Imported here because the help machinery pulls in docutils,
# which is only needed when help is actually requested.
from awscli.help import ProviderHelpCommand

cli_data = self._get_cli_data()
return ProviderHelpCommand(
self.session,
Expand Down Expand Up @@ -769,6 +768,8 @@ def _add_lineage(self, command_table):
command_obj.lineage = self.lineage + [command_obj]

def create_help_command(self):
from awscli.help import ServiceHelpCommand

command_table = self._get_command_table()
return ServiceHelpCommand(
session=self.session,
Expand Down Expand Up @@ -964,6 +965,8 @@ def __call__(self, args, parsed_globals):
)

def create_help_command(self):
from awscli.help import OperationHelpCommand

return OperationHelpCommand(
self._session,
operation_model=self._operation_model,
Expand Down
16 changes: 11 additions & 5 deletions awscli/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
from subprocess import PIPE, Popen

from botocore.exceptions import ProfileNotFound
from docutils.core import publish_string
from docutils.writers import (
html4css1,
manpage,
)

from awscli import (
_DEFAULT_BASE_REMOTE_URL,
Expand Down Expand Up @@ -239,6 +234,9 @@ class PosixHelpRenderer(PosixPagingHelpRenderer):
"""

def _convert_doc_content(self, contents):
from docutils.core import publish_string
from docutils.writers import manpage

settings_overrides = self._DEFAULT_DOCUTILS_SETTINGS_OVERRIDES.copy()
settings_overrides["report_level"] = 3
man_contents = publish_string(
Expand All @@ -265,6 +263,9 @@ class PosixBrowserHelpRenderer(BrowserHelpRenderer):
"""

def _convert_doc_content(self, contents):
from docutils.core import publish_string
from docutils.writers import manpage

settings_overrides = self._DEFAULT_DOCUTILS_SETTINGS_OVERRIDES.copy()
settings_overrides["report_level"] = 3
man_contents = publish_string(
Expand Down Expand Up @@ -310,6 +311,8 @@ class WindowsHelpRenderer(WindowsPagingHelpRenderer):
"""Render help content on a Windows platform."""

def _convert_doc_content(self, contents):
from docutils.core import publish_string

text_output = publish_string(
contents,
writer=TextWriter(),
Expand All @@ -322,6 +325,9 @@ class WindowsBrowserHelpRenderer(BrowserHelpRenderer):
"""Render help content in the browser on a Windows platform."""

def _convert_doc_content(self, contents):
from docutils.core import publish_string
from docutils.writers import html4css1

text_output = publish_string(
contents,
writer=html4css1.Writer(),
Expand Down
7 changes: 4 additions & 3 deletions awscli/topictags.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import json
import os

import docutils.core


class TopicTagDB:
"""This class acts like a database for the tags of all available topics.
Expand Down Expand Up @@ -182,7 +180,10 @@ def _find_topic_name(self, topic_src_file):

def _add_tag_and_values_from_content(self, topic_name, content):
# Retrieves tags and values and adds from content of topic file
# to the dictionary.
# to the dictionary. Imported here because docutils is only
# needed when the topic index is (re)generated or queried.
import docutils.core

doctree = docutils.core.publish_doctree(content).asdom()
fields = doctree.getElementsByTagName('field')
for field in fields:
Expand Down