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

Changed concatenation to f-strings #2300

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 4 additions & 4 deletions scripts/insert_api_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ def list_functions(source_glob):
node = ast.parse(open(sp).read())
# Extract the names of all functions and classes defined in this file
defined.extend(
(n.name, module_name + "." + n.name)
(n.name, f"{module_name}.{n.name}")
for n in node.body
if (isinstance(n, ast.FunctionDef) or isinstance(n, ast.ClassDef))
)
return defined


def replace_backticks(source_path, docs_path):
markdown_glob = docs_path + "/*.md"
source_glob = source_path + "/**/*.py"
markdown_glob = f"{docs_path}/*.md"
source_glob = f"{source_path}/**/*.py"
methods = list_functions(source_glob)
for f in glob.glob(markdown_glob):
for n, m in methods:
# Match backquoted mentions of the function/class name which are
# not already links
pattern = "(?<![[`])(`" + n + "`)"
pattern = f"(?<![[`])(`{n}`)"
link = f"[`{n}`](/api/{m.split('.')[1]}.html#{m})"
lines = open(f).readlines()
for i, l in enumerate(lines):
Expand Down
Loading