Skip to content

Commit

Permalink
fix running in bash environment on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
lainme committed Jan 17, 2025
1 parent c88fc05 commit ef7ea1b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/aiida/cmdline/commands/cmd_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ def _computer_create_temp_file(transport, scheduler, authinfo, computer):

transport.makedirs(workdir, ignore_existing=True)

with tempfile.NamedTemporaryFile(mode='w+') as tempf:
with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tempf:
fname = os.path.split(tempf.name)[1]
remote_file_path = os.path.join(workdir, fname)
tempf.write(file_content)
tempf.flush()
tempf.close()
transport.putfile(tempf.name, remote_file_path)
os.remove(tempf.name)

if not transport.path_exists(remote_file_path):
return False, f'failed to create the file `{remote_file_path}` on the remote'
Expand Down
4 changes: 3 additions & 1 deletion src/aiida/manage/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import json
import os
import uuid
import shutil
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple

Expand Down Expand Up @@ -780,7 +781,8 @@ def _atomic_write(self, filepath=None):
os.umask(umask)

handle.flush()
os.rename(handle.name, self.filepath)
handle.close()
shutil.move(handle.name, self.filepath)

def filepaths(self, profile: Profile):
"""Return the filepaths used by a profile.
Expand Down
3 changes: 2 additions & 1 deletion src/aiida/manage/profile_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import contextlib
import os
import typing
import shutil
from pathlib import Path

import psutil
Expand Down Expand Up @@ -76,7 +77,7 @@ def request_access(self) -> None:
# it will read the incomplete command, won't be able to correctly compare it with its running
# process, and will conclude the record is old and clean it up.
filepath_tmp.write_text(str(self.process.cmdline()))
os.rename(filepath_tmp, filepath_pid)
shutil.move(filepath_tmp, filepath_pid)

# Check again in case a lock was created in the time between the first check and creating the
# access record file.
Expand Down

0 comments on commit ef7ea1b

Please sign in to comment.