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

Fix raw strings containing escape sequences #1419

Merged
merged 1 commit into from
Jul 9, 2024
Merged
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
2 changes: 1 addition & 1 deletion nbdev/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def create_output(txt, mime):
def show_src(src, lang='python'): return Markdown(f'```{lang}\n{src}\n```')

# %% ../nbs/api/01_config.ipynb 48
_re_version = re.compile('^__version__\s*=.*$', re.MULTILINE)
_re_version = re.compile(r'^__version__\s*=.*$', re.MULTILINE)
_init = '__init__.py'

def update_version(path=None):
Expand Down
2 changes: 1 addition & 1 deletion nbdev/doclinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _build_modidx(dest=None, nbs_path=None, skip_exists=False):
res['settings'] = {k:v for k,v in get_config().d.items()
if k in ('doc_host','doc_baseurl','lib_path','git_url','branch')}
code_root = dest.parent.resolve()
for file in globtastic(dest, file_glob="*.py", skip_file_re='^_', skip_folder_re="\.ipynb_checkpoints"):
for file in globtastic(dest, file_glob="*.py", skip_file_re='^_', skip_folder_re=r"\.ipynb_checkpoints"):
res['syms'].update(_get_modidx((dest.parent/file).resolve(), code_root, nbs_path=nbs_path))
idxfile.write_text("# Autogenerated by nbdev\n\nd = "+pformat(res, width=140, indent=2, compact=True)+'\n')

Expand Down
6 changes: 3 additions & 3 deletions nbdev/quarto.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _sort(a):
if y.startswith('index.'): return x,'00'
return a
#|export
_def_file_re = '\.(?:ipynb|qmd|html)$'
_def_file_re = r'\.(?:ipynb|qmd|html)$'

@delegates(nbglob_cli)
def _nbglob_docs(
Expand All @@ -87,12 +87,12 @@ def _recursive_parser(
set_index: bool = True): # If `True`, `index` file will be set to href.
for name, val in dir_dict.items():
if type(val) is str:
if re.search('index\..*', re.sub('^\d+_', '', val)) and set_index and section:
if re.search('index\..*', re.sub(r'^\d+_', '', val)) and set_index and section:
section.update({'href': str(dirpath/val)})
else:
contents.append(str(dirpath/val))
elif type(val) is dict:
name = re.sub('^\d+_', '', name)
name = re.sub(r'^\d+_', '', name)
section = {'section': name, 'contents': []}
contents.append(section)
_recursive_parser(val, section['contents'], dirpath/name, section=section)
Expand Down
2 changes: 1 addition & 1 deletion nbdev/showdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _bold(s): return f'**{s}**' if s.strip() else s

# %% ../nbs/api/08_showdoc.ipynb 7
def _escape_markdown(s):
for c in '|^': s = re.sub(rf'\\?\{c}', f'\{c}', s)
for c in '|^': s = re.sub(rf'\\?\{c}', rf'\{c}', s)
return s.replace('\n', '<br>')

# %% ../nbs/api/08_showdoc.ipynb 9
Expand Down
2 changes: 1 addition & 1 deletion nbdev/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _mod_files():
return L(files for mod in midx.d['syms'].values() for _,files in mod.values()).unique()

# %% ../nbs/api/06_sync.ipynb 8
_re_import = re.compile("from\s+\S+\s+import\s+\S")
_re_import = re.compile(r"from\s+\S+\s+import\s+\S")

# %% ../nbs/api/06_sync.ipynb 10
def _to_absolute(code, py_path, lib_dir):
Expand Down
2 changes: 1 addition & 1 deletion nbs/api/01_config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@
"outputs": [],
"source": [
"#|export\n",
"_re_version = re.compile('^__version__\\s*=.*$', re.MULTILINE)\n",
"_re_version = re.compile(r'^__version__\\s*=.*$', re.MULTILINE)\n",
"_init = '__init__.py'\n",
"\n",
"def update_version(path=None):\n",
Expand Down
2 changes: 1 addition & 1 deletion nbs/api/05_doclinks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
" res['settings'] = {k:v for k,v in get_config().d.items()\n",
" if k in ('doc_host','doc_baseurl','lib_path','git_url','branch')}\n",
" code_root = dest.parent.resolve()\n",
" for file in globtastic(dest, file_glob=\"*.py\", skip_file_re='^_', skip_folder_re=\"\\.ipynb_checkpoints\"):\n",
" for file in globtastic(dest, file_glob=\"*.py\", skip_file_re='^_', skip_folder_re=r\"\\.ipynb_checkpoints\"):\n",
" res['syms'].update(_get_modidx((dest.parent/file).resolve(), code_root, nbs_path=nbs_path))\n",
" idxfile.write_text(\"# Autogenerated by nbdev\\n\\nd = \"+pformat(res, width=140, indent=2, compact=True)+'\\n')"
]
Expand Down
2 changes: 1 addition & 1 deletion nbs/api/06_sync.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"outputs": [],
"source": [
"#|export\n",
"_re_import = re.compile(\"from\\s+\\S+\\s+import\\s+\\S\")"
"_re_import = re.compile(r\"from\\s+\\S+\\s+import\\s+\\S\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion nbs/api/08_showdoc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"source": [
"#|export\n",
"def _escape_markdown(s):\n",
" for c in '|^': s = re.sub(rf'\\\\?\\{c}', f'\\{c}', s)\n",
" for c in '|^': s = re.sub(rf'\\\\?\\{c}', rf'\\{c}', s)\n",
" return s.replace('\\n', '<br>')"
]
},
Expand Down
6 changes: 3 additions & 3 deletions nbs/api/14_quarto.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
" if y.startswith('index.'): return x,'00'\n",
" return a\n",
"#|export\n",
"_def_file_re = '\\.(?:ipynb|qmd|html)$'\n",
"_def_file_re = r'\\.(?:ipynb|qmd|html)$'\n",
"\n",
"@delegates(nbglob_cli)\n",
"def _nbglob_docs(\n",
Expand All @@ -186,12 +186,12 @@
" set_index: bool = True): # If `True`, `index` file will be set to href.\n",
" for name, val in dir_dict.items():\n",
" if type(val) is str:\n",
" if re.search('index\\..*', re.sub('^\\d+_', '', val)) and set_index and section:\n",
" if re.search('index\\..*', re.sub(r'^\\d+_', '', val)) and set_index and section:\n",
" section.update({'href': str(dirpath/val)})\n",
" else:\n",
" contents.append(str(dirpath/val))\n",
" elif type(val) is dict:\n",
" name = re.sub('^\\d+_', '', name)\n",
" name = re.sub(r'^\\d+_', '', name)\n",
" section = {'section': name, 'contents': []}\n",
" contents.append(section)\n",
" _recursive_parser(val, section['contents'], dirpath/name, section=section)\n",
Expand Down