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

Updated autogen_magics.py to Pathlib Path #12604

Merged
merged 4 commits into from
Oct 13, 2020
Merged
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
13 changes: 6 additions & 7 deletions docs/autogen_magics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from pathlib import Path
from IPython.core.alias import Alias
from IPython.core.interactiveshell import InteractiveShell
Expand All @@ -10,7 +9,7 @@

def _strip_underline(line):
chars = set(line.strip())
if len(chars) == 1 and ('-' in chars or '=' in chars):
if len(chars) == 1 and ("-" in chars or "=" in chars):
return ""
else:
return line
Expand All @@ -32,7 +31,7 @@ def format_docstring(func):
# Case insensitive sort by name
def sortkey(s): return s[0].lower()

for name, func in sorted(magics['line'].items(), key=sortkey):
for name, func in sorted(magics["line"].items(), key=sortkey):
if isinstance(func, Alias) or isinstance(func, MagicAlias):
# Aliases are magics, but shouldn't be documented here
# Also skip aliases to other magics
Expand All @@ -48,11 +47,11 @@ def sortkey(s): return s[0].lower()
"",
])

for name, func in sorted(magics['cell'].items(), key=sortkey):
for name, func in sorted(magics["cell"].items(), key=sortkey):
if name == "!":
# Special case - don't encourage people to use %%!
continue
if func == magics['line'].get(name, 'QQQP'):
if func == magics["line"].get(name, "QQQP"):
# Don't redocument line magics that double as cell magics
continue
if isinstance(func, MagicAlias):
Expand All @@ -62,6 +61,6 @@ def sortkey(s): return s[0].lower()
format_docstring(func),
""])

here = os.path.dirname(__file__)
dest = Path(os.path.join(here, "source", "interactive", "magics-generated.txt"))
src_path = Path(__file__).parent
dest = src_path.joinpath("source", "interactive", "magics-generated.txt")
dest.write_text("\n".join(output))