Skip to content

Commit

Permalink
py3: s/mkdir_p/os.makedirs/g
Browse files Browse the repository at this point in the history
* closes cylc#2858
  • Loading branch information
oliver-sanders committed Mar 7, 2019
1 parent a50ef5a commit 432d210
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 73 deletions.
2 changes: 0 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ omit=
*/lib/cylc/tests/*
*/lib/cylc/profiler.py
*/lib/cylc/profiling/*
*/lib/cylc/mkdir_p.py
*/lib/parsec/OrderedDictCompat.py
*/lib/isodatetime/*
*/lib/jinja2/*
Expand Down Expand Up @@ -61,7 +60,6 @@ omit=
*/lib/cylc/tests/*
*/lib/cylc/profiler.py
*/lib/cylc/profiling/*
*/lib/cylc/mkdir_p.py
*/lib/parsec/OrderedDictCompat.py
*/lib/isodatetime/*
*/lib/jinja2/*
Expand Down
5 changes: 3 additions & 2 deletions lib/cylc/batch_sys_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
from parsec.OrderedDict import OrderedDict


from cylc.mkdir_p import mkdir_p
from cylc.task_message import (
CYLC_JOB_PID, CYLC_JOB_INIT_TIME, CYLC_JOB_EXIT_TIME, CYLC_JOB_EXIT,
CYLC_MESSAGE)
Expand Down Expand Up @@ -776,7 +775,9 @@ def _jobs_submit_prep_by_stdin(self, job_log_root, job_log_dirs):
elif cur_line.startswith(self.LINE_PREFIX_JOB_LOG_DIR):
job_log_dir = cur_line.replace(
self.LINE_PREFIX_JOB_LOG_DIR, "").strip()
mkdir_p(os.path.join(job_log_root, job_log_dir))
os.makedirs(
os.path.join(job_log_root, job_log_dir),
exist_ok=True)
handle = open(
os.path.join(job_log_root, job_log_dir, "job.tmp"), "wb")

Expand Down
3 changes: 1 addition & 2 deletions lib/cylc/cfgspec/globalcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from cylc.cfgvalidate import (
cylc_config_validate, CylcConfigValidator as VDR, DurationFloat)
from cylc.hostuserutil import get_user_home, is_remote_user
from cylc.mkdir_p import mkdir_p
from cylc.network import Priv
from cylc.version import CYLC_VERSION

Expand Down Expand Up @@ -473,7 +472,7 @@ def roll_directory(self, dir_, name, archlen=0):
def create_directory(dir_, name):
"""Create directory. Raise GlobalConfigError on error."""
try:
mkdir_p(dir_)
os.makedirs(dir_, exist_ok=True)
except OSError as exc:
LOG.exception(exc)
raise GlobalConfigError(
Expand Down
3 changes: 1 addition & 2 deletions lib/cylc/loggingutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@


from cylc.cfgspec.glbl_cfg import glbl_cfg
from cylc.mkdir_p import mkdir_p
from cylc.wallclock import (
get_current_time_string, get_time_string_from_unix_time)

Expand Down Expand Up @@ -119,7 +118,7 @@ def do_rollover(self):
# Generate new file name
self.stamp = get_current_time_string(use_basic_format=True)
filename = self.baseFilename + '.' + self.stamp
mkdir_p(os.path.dirname(filename))
os.makedirs(os.path.dirname(filename), exist_ok=True)
# Touch file
with open(filename, 'w+'):
os.utime(filename, None)
Expand Down
54 changes: 0 additions & 54 deletions lib/cylc/mkdir_p.py

This file was deleted.

7 changes: 3 additions & 4 deletions lib/cylc/suite_srv_files_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from cylc import LOG
from cylc.cfgspec.glbl_cfg import glbl_cfg
import cylc.flags
from cylc.mkdir_p import mkdir_p
from cylc.hostuserutil import (
get_host, get_user, is_remote, is_remote_host, is_remote_user)

Expand Down Expand Up @@ -460,7 +459,7 @@ def register(self, reg=None, source=None, redirect=False):

# Create service dir if necessary.
srv_d = self.get_suite_srv_dir(reg)
mkdir_p(srv_d)
os.makedirs(srv_d, exist_ok=True)

# See if suite already has a source or not
try:
Expand Down Expand Up @@ -505,7 +504,7 @@ def create_auth_files(self, reg):
"""Create or renew passphrase and SSL files for suite 'reg'."""
# Suite service directory.
srv_d = self.get_suite_srv_dir(reg)
mkdir_p(srv_d)
os.makedirs(srv_d, exist_ok=True)

# Create a new passphrase for the suite if necessary.
if not self._locate_item(self.FILE_BASE_PASSPHRASE, srv_d):
Expand All @@ -522,7 +521,7 @@ def _dump_item(path, item, value):
2. The combination of os.fsync and os.rename should guarantee
that we don't end up with an incomplete file.
"""
mkdir_p(path)
os.makedirs(path, exist_ok=True)
from tempfile import NamedTemporaryFile
handle = NamedTemporaryFile(prefix=item, dir=path, delete=False)
try:
Expand Down
3 changes: 1 addition & 2 deletions lib/cylc/task_job_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from cylc.task_job_logs import (
JOB_LOG_JOB, get_task_job_log, get_task_job_job_log,
get_task_job_activity_log, get_task_job_id, NN)
from cylc.mkdir_p import mkdir_p
from cylc.subprocpool import SuiteProcPool
from cylc.subprocctx import SubProcContext
from cylc.task_action_timer import TaskActionTimer
Expand Down Expand Up @@ -352,7 +351,7 @@ def _create_job_log_path(suite, itask):
else:
rmtree(job_file_dir, ignore_errors=True)

mkdir_p(job_file_dir)
os.makedirs(job_file_dir, exist_ok=True)
target = os.path.join(task_log_dir, NN)
source = os.path.basename(job_file_dir)
try:
Expand Down
3 changes: 1 addition & 2 deletions lib/cylc/task_remote_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import tarfile

import cylc.flags
from cylc.mkdir_p import mkdir_p
from cylc.suite_srv_files_mgr import SuiteSrvFilesManager


Expand All @@ -49,7 +48,7 @@ def remote_init(uuid_str, rund, indirect_comm=None):
if orig_uuid_str == uuid_str:
print(REMOTE_INIT_NOT_REQUIRED)
return
mkdir_p(rund)
os.makedirs(rund, exist_ok=True)
oldcwd = os.getcwd()
os.chdir(rund)
try:
Expand Down
8 changes: 5 additions & 3 deletions lib/cylc/tests/test_suite_srv_files_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,18 @@ class TestSuiteSrvFilesManager(unittest.TestCase):
def setUp(self):
self.suite_srv_files_mgr = SuiteSrvFilesManager()

@mock.patch('cylc.suite_srv_files_mgr.mkdir_p')
@mock.patch('cylc.suite_srv_files_mgr.os')
def test_register(self, mocked_os, mocked_mkdir_p):
def test_register(self, mocked_os):
"""Test the SuiteSrvFilesManager register function."""
def mkdirs_standin(_, exist_ok=False):
True

# we do not need to mock these functions
mocked_os.path.basename.side_effect = os.path.basename
mocked_os.path.join = os.path.join
mocked_os.path.normpath = os.path.normpath
mocked_os.path.dirname = os.path.dirname
mocked_mkdir_p.side_effect = lambda x: True
mocked_os.makedirs.side_effect = mkdirs_standin
mocked_os.path.abspath.side_effect = lambda x: x

for reg, source, redirect, cwd, isabs, isfile, \
Expand Down

0 comments on commit 432d210

Please sign in to comment.