Skip to content

Commit 141f63e

Browse files
committed
pass encoding=utf8 when opening files
1 parent 3acb976 commit 141f63e

File tree

11 files changed

+15
-15
lines changed

11 files changed

+15
-15
lines changed

nbdev/clean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _reconfigure(*strms):
111111
# %% ../nbs/api/11_clean.ipynb 28
112112
def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
113113
if not f_out: f_out = f_in
114-
if isinstance(f_in, (str,Path)): f_in = Path(f_in).open()
114+
if isinstance(f_in, (str,Path)): f_in = Path(f_in).open(encoding="utf-8")
115115
try:
116116
_reconfigure(f_in, f_out)
117117
nb = dict2nb(loads(f_in.read()))

nbdev/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def nbdev_filter(
4242
elif not nb_txt: nb_txt = sys.stdin.read()
4343
nb = dict2nb(loads(nb_txt))
4444
if printit:
45-
with open(os.devnull, 'w') as dn:
45+
with open(os.devnull, 'w', encoding="utf-8") as dn:
4646
with redirect_stdout(dn): filt(nb)
4747
else: filt(nb)
4848
res = nb2str(nb)

nbdev/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def _basic_export_nb(fname, name, dest=None):
271271
exp_funcs = [f for f in funcs if f[0]!='_']
272272

273273
# write out the file
274-
with (dest/name).open('w') as f:
274+
with (dest/name).open('w',encoding="utf-8") as f:
275275
f.write(f"# %% auto 0\n__all__ = {exp_funcs}")
276276
write_cells(cells, f"# %% {fname.relpath(dest)}", f)
277277
f.write('\n')

nbdev/maker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def make(self:ModuleMaker, cells, all_cells=None, lib_path=None):
202202
last_future = self._last_future(cells) if len(all_cells)>0 else 0
203203
tw = TextWrapper(width=120, initial_indent='', subsequent_indent=' '*11, break_long_words=False)
204204
all_str = '\n'.join(tw.wrap(str(_all)))
205-
with self.fname.open('w') as f:
205+
with self.fname.open('w', encoding="utf-8") as f:
206206
f.write(_retr_mdoc(cells))
207207
f.write(f"# AUTOGENERATED! DO NOT EDIT! File to edit: {self.dest2nb}.")
208208
if last_future > 0: write_cells(cells[:last_future], self.hdr, f)
@@ -220,7 +220,7 @@ def _make_exists(self:ModuleMaker, cells, all_cells=None):
220220
"`make` for `is_new=False`"
221221
if all_cells and self.parse:
222222
update_var('__all__', partial(self._update_all, all_cells), fn=self.fname)
223-
with self.fname.open('a') as f: write_cells(cells, self.hdr, f)
223+
with self.fname.open('a', encoding="utf-8") as f: write_cells(cells, self.hdr, f)
224224

225225
# %% ../nbs/api/02_maker.ipynb 44
226226
def _basic_export_nb2(fname, name, dest=None):

nbdev/release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def pypi_details(name):
169169

170170
def _run(cmd):
171171
res = ""
172-
with Popen(shlex.split(cmd), stdout=PIPE, bufsize=1, text=True) as p:
172+
with Popen(shlex.split(cmd), stdout=PIPE, bufsize=1, text=True, encoding="utf-8") as p:
173173
for line in p.stdout:
174174
print(line, end='')
175175
res += line
@@ -188,7 +188,7 @@ def _write_yaml(path, name, d1, d2):
188188
p = path/name
189189
p.mkdir(exist_ok=True, parents=True)
190190
yaml.SafeDumper.ignore_aliases = lambda *args : True
191-
with (p/'meta.yaml').open('w') as f:
191+
with (p/'meta.yaml').open('w', encoding="utf-8") as f:
192192
yaml.safe_dump(d1, f)
193193
yaml.safe_dump(d2, f)
194194

nbs/api/01_config.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@
753753
" exp_funcs = [f for f in funcs if f[0]!='_']\n",
754754
"\n",
755755
" # write out the file\n",
756-
" with (dest/name).open('w') as f:\n",
756+
" with (dest/name).open('w',encoding=\"utf-8\") as f:\n",
757757
" f.write(f\"# %% auto 0\\n__all__ = {exp_funcs}\")\n",
758758
" write_cells(cells, f\"# %% {fname.relpath(dest)}\", f)\n",
759759
" f.write('\\n')"

nbs/api/02_maker.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@
514514
" last_future = self._last_future(cells) if len(all_cells)>0 else 0\n",
515515
" tw = TextWrapper(width=120, initial_indent='', subsequent_indent=' '*11, break_long_words=False)\n",
516516
" all_str = '\\n'.join(tw.wrap(str(_all)))\n",
517-
" with self.fname.open('w') as f:\n",
517+
" with self.fname.open('w', encoding=\"utf-8\") as f:\n",
518518
" f.write(_retr_mdoc(cells))\n",
519519
" f.write(f\"# AUTOGENERATED! DO NOT EDIT! File to edit: {self.dest2nb}.\")\n",
520520
" if last_future > 0: write_cells(cells[:last_future], self.hdr, f)\n",
@@ -661,7 +661,7 @@
661661
" \"`make` for `is_new=False`\"\n",
662662
" if all_cells and self.parse:\n",
663663
" update_var('__all__', partial(self._update_all, all_cells), fn=self.fname)\n",
664-
" with self.fname.open('a') as f: write_cells(cells, self.hdr, f)"
664+
" with self.fname.open('a', encoding=\"utf-8\") as f: write_cells(cells, self.hdr, f)"
665665
]
666666
},
667667
{

nbs/api/11_clean.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@
365365
"#|export\n",
366366
"def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):\n",
367367
" if not f_out: f_out = f_in\n",
368-
" if isinstance(f_in, (str,Path)): f_in = Path(f_in).open()\n",
368+
" if isinstance(f_in, (str,Path)): f_in = Path(f_in).open(encoding=\"utf-8\")\n",
369369
" try:\n",
370370
" _reconfigure(f_in, f_out)\n",
371371
" nb = dict2nb(loads(f_in.read()))\n",

nbs/api/13_cli.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
" elif not nb_txt: nb_txt = sys.stdin.read()\n",
9696
" nb = dict2nb(loads(nb_txt))\n",
9797
" if printit:\n",
98-
" with open(os.devnull, 'w') as dn:\n",
98+
" with open(os.devnull, 'w', encoding=\"utf-8\") as dn:\n",
9999
" with redirect_stdout(dn): filt(nb)\n",
100100
" else: filt(nb)\n",
101101
" res = nb2str(nb)\n",

nbs/api/18_release.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@
494494
"\n",
495495
"def _run(cmd):\n",
496496
" res = \"\"\n",
497-
" with Popen(shlex.split(cmd), stdout=PIPE, bufsize=1, text=True) as p:\n",
497+
" with Popen(shlex.split(cmd), stdout=PIPE, bufsize=1, text=True, encoding=\"utf-8\") as p:\n",
498498
" for line in p.stdout:\n",
499499
" print(line, end='')\n",
500500
" res += line\n",
@@ -527,7 +527,7 @@
527527
" p = path/name\n",
528528
" p.mkdir(exist_ok=True, parents=True)\n",
529529
" yaml.SafeDumper.ignore_aliases = lambda *args : True\n",
530-
" with (p/'meta.yaml').open('w') as f:\n",
530+
" with (p/'meta.yaml').open('w', encoding=\"utf-8\") as f:\n",
531531
" yaml.safe_dump(d1, f)\n",
532532
" yaml.safe_dump(d2, f)"
533533
]

0 commit comments

Comments
 (0)