Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
git grep -l sage_makedirs | xargs sed -E -i.bak 's/from sage.misc.mis…
Browse files Browse the repository at this point in the history
…c import sage_makedirs/import os/;s/sage_makedirs[(](.*)[)]$/os.makedirs(\1, exist_ok=True)/'
  • Loading branch information
Matthias Koeppe committed Dec 9, 2021
1 parent a9de636 commit 52b810f
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions build/pkgs/database_odlyzko_zeta/spkg-install.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
from sage.all import save
from sage.env import SAGE_SHARE
from sage.misc.misc import sage_makedirs
import os

install_root = os.path.join(SAGE_SHARE, 'odlyzko')
target = os.path.join(install_root, 'zeros.sobj')

if __name__ == '__main__':
sage_makedirs(install_root)
os.makedirs(install_root, exist_ok=True)
print("Creating Odlyzko database.")
F = [float(x) for x in open("src/zeros6").readlines()]
save(F, target)
Original file line number Diff line number Diff line change
Expand Up @@ -2271,10 +2271,10 @@ def _save_data_dig6(n, types='ClassicalExceptional', verbose=False):
data.update(_construct_exceptional_mutation_classes(n))

from sage.env import DOT_SAGE
from sage.misc.misc import sage_makedirs
import os
types_path = os.path.join(DOT_SAGE, 'cluster_algebra_quiver')
types_file = os.path.join(types_path, 'mutation_classes_%s.dig6' % n)
sage_makedirs(types_path)
os.makedirs(types_path, exist_ok=True)
from sage.misc.temporary_file import atomic_write
with atomic_write(types_file, binary=True) as f:
pickle.dump(data, f)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/databases/jones.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _init(self, path):
This takes about 5 seconds.
"""
from sage.misc.misc import sage_makedirs
import os
x = PolynomialRing(RationalField(), 'x').gen()
self.root = {}
self.root[tuple([])] = [x - 1]
Expand All @@ -158,7 +158,7 @@ def _init(self, path):
for Y in os.listdir(Z):
if Y[-3:] == ".gp":
self._load(Z, Y)
sage_makedirs(JONESDATA)
os.makedirs(JONESDATA, exist_ok=True)
save(self.root, JONESDATA + "/jones.sobj")

def unramified_outside(self, S, d=None, var='a'):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/databases/sloane.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def copy_gz_file(gz_source, bz_destination):
- ``bz_destination`` -- string. The name of the newly compressed file.
"""
import gzip
from sage.misc.misc import sage_makedirs
import os

# Read the gzipped input
try:
Expand All @@ -369,7 +369,7 @@ def copy_gz_file(gz_source, bz_destination):

# Write the bzipped output
try:
sage_makedirs(os.path.dirname(bz_destination))
os.makedirs(os.path.dirname(bz_destination), exist_ok=True)
bz2_output = bz2.BZ2File(bz_destination, 'w')
bz2_output.write(db_text)
bz2_output.close()
Expand Down
4 changes: 2 additions & 2 deletions src/sage/interfaces/expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def _do_cleaner(self):
return False

def _start(self, alt_message=None, block_during_init=True):
from sage.misc.misc import sage_makedirs
import os
self.quit() # in case one is already running

self._session_number += 1
Expand All @@ -452,7 +452,7 @@ def _start(self, alt_message=None, block_during_init=True):
if self.__logfilename is None and 'SAGE_PEXPECT_LOG' in os.environ:
from sage.env import DOT_SAGE
logs = os.path.join(DOT_SAGE, 'pexpect_logs')
sage_makedirs(logs)
os.makedirs(logs, exist_ok=True)

filename = '{name}-{pid}-{id}-{session}'.format(
name=self.name(), pid=os.getpid(), id=id(self),
Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/cachefunc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3348,11 +3348,11 @@ class FileCache(object):
sage: FC[((),())]
1
"""
from sage.misc.misc import sage_makedirs
import os
if not dir or dir[-1] != '/':
dir += '/'
self._dir = dir
sage_makedirs(dir)
os.makedirs(dir, exist_ok=True)

self._prefix = prefix + '-'

Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def cython(filename, verbose=0, compile_message=False,
except OSError:
pass
else:
sage_makedirs(target_dir)
os.makedirs(target_dir, exist_ok=True)

if create_local_so_file:
name = base
Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/func_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class func_persist:
definition to cache values it computes to disk.
"""
def __init__(self, f, dir='func_persist'):
from sage.misc.misc import sage_makedirs
import os
self.__func = f
self.__dir = dir
sage_makedirs(dir)
os.makedirs(dir, exist_ok=True)
self.__doc__ = '%s%s%s' % (
f.__name__,
inspect.formatargspec(*inspect.getargs(f.__code__)),
Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ def save_cache_file():
sage: import sage.misc.lazy_import
sage: sage.misc.lazy_import.save_cache_file()
"""
from sage.misc.misc import sage_makedirs
import os
from sage.misc.temporary_file import atomic_write

global star_imports
Expand All @@ -1089,7 +1089,7 @@ def save_cache_file():
cache_file = get_cache_file()
cache_dir = os.path.dirname(cache_file)

sage_makedirs(cache_dir)
os.makedirs(cache_dir, exist_ok=True)
with atomic_write(cache_file, binary=True) as f:
pickle.dump(star_imports, f)

Expand Down
10 changes: 5 additions & 5 deletions src/sage/misc/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ def sage_makedirs(dirname, mode=0o777):
EXAMPLES::
sage: from sage.misc.misc import sage_makedirs
sage: import os
sage: sage_makedirs(DOT_SAGE) # no output
The following fails because we are trying to create a directory in
place of an ordinary file::
sage: filename = tmp_filename()
sage: sage_makedirs(filename)
sage: os.makedirs(filename, exist_ok=True)
Traceback (most recent call last):
...
FileExistsError: [Errno ...] File exists: ...
Expand All @@ -101,7 +101,7 @@ def sage_makedirs(dirname, mode=0o777):
# restrictive permissions, since otherwise possibly just anybody can easily see
# every command you type.

sage_makedirs(DOT_SAGE, mode=0o700)
os.makedirs(DOT_SAGE, mode=0o700, exist_ok=True)


def try_read(obj, splitlines=False):
Expand Down Expand Up @@ -215,11 +215,11 @@ def try_read(obj, splitlines=False):


SAGE_DB = os.path.join(DOT_SAGE, 'db')
sage_makedirs(SAGE_DB)
os.makedirs(SAGE_DB, exist_ok=True)

try:
# Create the matplotlib config directory.
sage_makedirs(os.environ["MPLCONFIGDIR"])
os.makedirs(os.environ["MPLCONFIGDIR"], exist_ok=True)
except KeyError:
pass

Expand Down
20 changes: 10 additions & 10 deletions src/sage_docbuild/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

import sage.all
from sage.misc.cachefunc import cached_method
from sage.misc.misc import sage_makedirs
import os
from sage.env import SAGE_DOC_SRC, SAGE_DOC, SAGE_SRC, DOT_SAGE

from .build_options import (LANGUAGES, SPHINXOPTS, PAPER, OMIT,
Expand Down Expand Up @@ -186,7 +186,7 @@ def _output_dir(self, type):
'.../html/en/tutorial'
"""
d = os.path.join(SAGE_DOC, type, self.lang, self.name)
sage_makedirs(d)
os.makedirs(d, exist_ok=True)
return d

def _doctrees_dir(self):
Expand All @@ -203,7 +203,7 @@ def _doctrees_dir(self):
'.../doctrees/en/tutorial'
"""
d = os.path.join(SAGE_DOC, 'doctrees', self.lang, self.name)
sage_makedirs(d)
os.makedirs(d, exist_ok=True)
return d

def _output_formats(self):
Expand Down Expand Up @@ -345,7 +345,7 @@ def _wrapper(self, name, *args, **kwds):
getattr(get_builder(document), 'inventory')(*args, **kwds)

logger.warning("Building reference manual, second pass.\n")
sage_makedirs(os.path.join(SAGE_DOC, "html", "en", "reference", "_static"))
os.makedirs(os.path.join(SAGE_DOC, "html", "en", "reference", "_static"), exist_ok=True)
for document in refs:
getattr(get_builder(document), name)(*args, **kwds)

Expand Down Expand Up @@ -533,7 +533,7 @@ def _output_dir(self, type, lang=None):
if lang is None:
lang = self.lang
d = os.path.join(SAGE_DOC, type, lang, self.name)
sage_makedirs(d)
os.makedirs(d, exist_ok=True)
return d

def _refdir(self):
Expand Down Expand Up @@ -645,7 +645,7 @@ def _output_dir(self, type, lang=None):
if lang is None:
lang = self.lang
d = os.path.join(SAGE_DOC, type, lang, self.name)
sage_makedirs(d)
os.makedirs(d, exist_ok=True)
return d

def pdf(self):
Expand Down Expand Up @@ -1100,7 +1100,7 @@ def write_auto_rest_file(self, module_name):
if not module_name.startswith('sage'):
return
filename = self.auto_rest_filename(module_name)
sage_makedirs(os.path.dirname(filename))
os.makedirs(os.path.dirname(filename), exist_ok=True)

title = self.get_module_docstring_title(module_name)

Expand Down Expand Up @@ -1226,8 +1226,8 @@ def __init__(self, path):
pass
self.dir = os.path.join(base_dir, 'source')

sage_makedirs(os.path.join(self.dir, "static"))
sage_makedirs(os.path.join(self.dir, "templates"))
os.makedirs(os.path.join(self.dir, "static"), exist_ok=True)
os.makedirs(os.path.join(self.dir, "templates"), exist_ok=True)
# Write self.dir/conf.py
conf = r"""# This file is automatically generated by {}, do not edit!
Expand Down Expand Up @@ -1297,7 +1297,7 @@ def _output_dir(self, type):
"""
base_dir = os.path.split(self.dir)[0]
d = os.path.join(base_dir, "output", type)
sage_makedirs(d)
os.makedirs(d, exist_ok=True)
return d

def _doctrees_dir(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sage_docbuild/ext/multidocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from sphinx.application import Sphinx
from sphinx.util.console import bold
from sage.env import SAGE_DOC
from sage.misc.misc import sage_makedirs
import os
from pathlib import Path

logger = sphinx.util.logging.getLogger(__name__)
Expand Down Expand Up @@ -231,7 +231,7 @@ def citation_dir(app: Sphinx) -> Path:
citedir = (sage_doc / "inventory").joinpath(*tail)
else:
citedir = outdir / "inventory"
sage_makedirs(citedir)
os.makedirs(citedir, exist_ok=True)
return citedir


Expand Down

0 comments on commit 52b810f

Please sign in to comment.