From 7775943f20f8ac91519f5ca9dc3a446c0786c4d3 2020-10-13 16:57:14 From: Justin Palmer Date: 2020-10-13 16:57:14 Subject: [PATCH] Use pathlib in packaging.py, io.py, and gen_latex_symbols.py * Added pathlib in a few places where it makes sense to. --- diff --git a/IPython/core/magics/packaging.py b/IPython/core/magics/packaging.py index aa5dfa6..bddb587 100644 --- a/IPython/core/magics/packaging.py +++ b/IPython/core/magics/packaging.py @@ -11,6 +11,7 @@ import re import shlex import sys +from Pathlib import Path from pathlib import Path from IPython.core.magic import Magics, magics_class, line_magic diff --git a/IPython/utils/io.py b/IPython/utils/io.py index fab9bae..f591603 100644 --- a/IPython/utils/io.py +++ b/IPython/utils/io.py @@ -14,6 +14,7 @@ import sys import tempfile import warnings from warnings import warn +from pathlib import Path from IPython.utils.decorators import undoc from .capture import CapturedIO, capture_output @@ -204,8 +205,8 @@ def temp_pyfile(src, ext='.py'): (filename, open filehandle) It is the caller's responsibility to close the open file and unlink it. """ - fname = tempfile.mkstemp(ext)[1] - with open(fname,'w') as f: + fname = Path(tempfile.mkstemp(ext)[1]) + with fname.open('w') as f: f.write(src) f.flush() return fname diff --git a/tools/gen_latex_symbols.py b/tools/gen_latex_symbols.py index c3fed12..0574c70 100644 --- a/tools/gen_latex_symbols.py +++ b/tools/gen_latex_symbols.py @@ -9,7 +9,7 @@ # # The original mapping of latex symbols to unicode comes from the `latex_symbols.jl` files from Julia. -import os, sys +from pathlib import Path # Import the Julia LaTeX symbols print('Importing latex_symbols.js from Julia...') @@ -80,9 +80,8 @@ s += """ reverse_latex_symbol = { v:k for k,v in latex_symbols.items()} """ -fn = os.path.join('..','IPython','core','latex_symbols.py') -print("Writing the file: %s" % fn) -with open(fn, 'w', encoding='utf-8') as f: - f.write(s) +fn = Path('..', 'IPython', 'core', 'latex_symbols.py') +print("Writing the file: %s" % str(fn)) +fn.write_text(s, encoding='utf-8')