Skip to content

Blacken docs directory #9671

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ repos:
- id: black
exclude: |
(?x)
^docs/|
^src/pip/_internal/commands|
^src/pip/_internal/index|
^src/pip/_internal/models|
Expand Down
106 changes: 60 additions & 46 deletions docs/docs_feedback_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@


def _modify_rst_document_source_on_read(
app: Sphinx,
docname: str,
source: List[str],
app: Sphinx,
docname: str,
source: List[str],
) -> None:
"""Add info block to top and bottom of each document source.

Expand All @@ -25,52 +25,59 @@ def _modify_rst_document_source_on_read(
"""
admonition_type = app.config.docs_feedback_admonition_type
big_doc_lines = app.config.docs_feedback_big_doc_lines
escaped_email = app.config.docs_feedback_email.replace(' ', r'\ ')
escaped_email = app.config.docs_feedback_email.replace(" ", r"\ ")
excluded_documents = set(app.config.docs_feedback_excluded_documents)
questions_list = app.config.docs_feedback_questions_list

valid_admonitions = {
'attention', 'caution', 'danger', 'error', 'hint',
'important', 'note', 'tip', 'warning', 'admonition',
"attention",
"caution",
"danger",
"error",
"hint",
"important",
"note",
"tip",
"warning",
"admonition",
}

if admonition_type not in valid_admonitions:
raise ValueError(
'Expected `docs_feedback_admonition_type` to be one of '
f'{valid_admonitions} but got {admonition_type}.'
"Expected `docs_feedback_admonition_type` to be one of "
f"{valid_admonitions} but got {admonition_type}."
)

if not questions_list:
raise ValueError(
'Expected `docs_feedback_questions_list` to list questions '
'but got none.'
"Expected `docs_feedback_questions_list` to list questions " "but got none."
)

if docname in excluded_documents:
# NOTE: Completely ignore any document
# NOTE: listed in 'docs_feedback_excluded_documents'.
return

is_doc_big = source[0].count('\n') >= big_doc_lines
is_doc_big = source[0].count("\n") >= big_doc_lines

questions_list_rst = '\n'.join(
questions_list_rst = "\n".join(
f'{" " * RST_INDENT}{number!s}. {question}'
for number, question in enumerate(questions_list, 1)
)
questions_list_urlencoded = (
'\n'.join(
"\n".join(
f'\n{" " * RST_INDENT}{number!s}. {question} '
for number, question in enumerate(
chain(
(f'Document: {docname}. Page URL: https://', ),
(f"Document: {docname}. Page URL: https://",),
questions_list,
),
)
).
rstrip('\r\n\t ').
replace('\r', '%0D').
replace('\n', '%0A').
replace(' ', '%20')
)
.rstrip("\r\n\t ")
.replace("\r", "%0D")
.replace("\n", "%0A")
.replace(" ", "%20")
)

admonition_msg = rf"""
Expand All @@ -88,32 +95,39 @@ def _modify_rst_document_source_on_read(
(URL\:\ https\://)\
&body={questions_list_urlencoded}
"""
let_us_know_ending = ':'
let_us_know_ending = ":"

info_block_bottom = (
f'.. {admonition_type}::\n\t\t{admonition_msg.format_map(locals())}\n'
f".. {admonition_type}::\n\t\t{admonition_msg.format_map(locals())}\n"
)

questions_list_rst = ''
questions_list_rst = ""
let_us_know_ending = (
' why you came to this page and what on it helped '
'you and what did not. '
'(:issue:`Read more about this research <8517>`)'
" why you came to this page and what on it helped "
"you and what did not. "
"(:issue:`Read more about this research <8517>`)"
)
info_block_top = '' if is_doc_big else (
f'.. {admonition_type}::\n\t\t{admonition_msg.format_map(locals())}\n'
info_block_top = (
""
if is_doc_big
else (f".. {admonition_type}::\n\t\t{admonition_msg.format_map(locals())}\n")
)

orphan_mark = ':orphan:'
orphan_mark = ":orphan:"
is_orphan = orphan_mark in source[0]
if is_orphan:
source[0] = source[0].replace(orphan_mark, '')
source[0] = source[0].replace(orphan_mark, "")
else:
orphan_mark = ''

source[0] = '\n\n'.join((
orphan_mark, info_block_top, source[0], info_block_bottom,
))
orphan_mark = ""

source[0] = "\n\n".join(
(
orphan_mark,
info_block_top,
source[0],
info_block_bottom,
)
)


def setup(app: Sphinx) -> Dict[str, Union[bool, str]]:
Expand All @@ -124,37 +138,37 @@ def setup(app: Sphinx) -> Dict[str, Union[bool, str]]:

It also declares the extension settings changable via :file:`conf.py`.
"""
rebuild_trigger = 'html' # rebuild full html on settings change
rebuild_trigger = "html" # rebuild full html on settings change
app.add_config_value(
'docs_feedback_admonition_type',
default='important',
"docs_feedback_admonition_type",
default="important",
rebuild=rebuild_trigger,
)
app.add_config_value(
'docs_feedback_big_doc_lines',
"docs_feedback_big_doc_lines",
default=DEFAULT_DOC_LINES_THRESHOLD,
rebuild=rebuild_trigger,
)
app.add_config_value(
'docs_feedback_email',
default='Docs UX Team <docs-feedback@pypa.io>',
"docs_feedback_email",
default="Docs UX Team <docs-feedback@pypa.io>",
rebuild=rebuild_trigger,
)
app.add_config_value(
'docs_feedback_excluded_documents',
"docs_feedback_excluded_documents",
default=set(),
rebuild=rebuild_trigger,
)
app.add_config_value(
'docs_feedback_questions_list',
"docs_feedback_questions_list",
default=(),
rebuild=rebuild_trigger,
)

app.connect('source-read', _modify_rst_document_source_on_read)
app.connect("source-read", _modify_rst_document_source_on_read)

return {
'parallel_read_safe': True,
'parallel_write_safe': True,
'version': 'builtin',
"parallel_read_safe": True,
"parallel_write_safe": True,
"version": "builtin",
}
Loading