Skip to content

Commit

Permalink
use isort to format import
Browse files Browse the repository at this point in the history
  • Loading branch information
Mu Li committed Jan 19, 2021
1 parent 4c8a3e4 commit 96ab562
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions d2lbook/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ast
import astor
from yapf.yapflib.yapf_api import FormatCode
import isort

def _write_header(f):
f.write('# This file is generated automatically through:\n')
Expand Down Expand Up @@ -205,6 +206,9 @@ def replace_alias(nb, tab_lib):
return nb

def format_code(source: str):
if 'import ' in source:
source = isort.code(source)

# fix bug yapf cannot handle jupyter magic
for l in source.splitlines():
if l.startswith('%'):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
'gitpython',
'sphinx_autodoc_typehints',
'astor',
'yapf'
'yapf',
'isort'
]

setup(
Expand Down

0 comments on commit 96ab562

Please sign in to comment.