Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions arc/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,3 +1864,16 @@ def calculate_arrhenius_rate_coefficient(A: Union[int, float, Sequence[float], n
raise ValueError("All temperature values must be positive")
exp_arg = -Ea_arr / (R * T_arr)
return A_arr * np.power(T_arr, n_arr) * np.exp(exp_arg)


def fill_in_the_blanks(folder_name: str):
"""
Adding backslashes before spaces in the folder name.

Args:
folder_name (str): The string directory we want to modify.

Returns:
str: Modified folder name.
"""
return folder_name.replace(" ", "\ ")
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backslash escaping is incorrect. In Python string literals, you need to escape the backslash itself. This should be folder_name.replace(' ', '\\ ') or use a raw string folder_name.replace(' ', r'\ ').

Suggested change
return folder_name.replace(" ", "\ ")
return folder_name.replace(" ", "\\ ")

Copilot uses AI. Check for mistakes.

Comment on lines +1869 to +1879
Copy link

Copilot AI Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The docstring should clarify that this function is for shell compatibility and mention that it works on any path, not just folder names. Also, the parameter description could be more precise: 'The file or directory path to escape'.

Suggested change
def fill_in_the_blanks(folder_name: str):
"""
Adding backslashes before spaces in the folder name.
Args:
folder_name (str): The string directory we want to modify.
Returns:
str: Modified folder name.
"""
return folder_name.replace(" ", "\ ")
def fill_in_the_blanks(path: str):
"""
Escape spaces in a file or directory path by adding backslashes before spaces for shell compatibility.
This function is useful when constructing shell commands that use paths containing spaces.
Args:
path (str): The file or directory path to escape.
Returns:
str: The modified path string with spaces escaped.
"""
return path.replace(" ", "\ ")

Copilot uses AI. Check for mistakes.

13 changes: 13 additions & 0 deletions arc/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,19 @@ def test_calculate_arrhenius_rate_coefficient(self):
with self.assertRaises(ValueError):
common.calculate_arrhenius_rate_coefficient(A=1e12, n=0.5, Ea=10, T=bad_T, Ea_units='kJ/mol')

def test_fill_in_the_blanks(self):
"""Test the fill_in_the_blanks() function"""
ex1 = "name"
ex2 = "name1 name2"
ex3 = "name 1 name2"
ex4 = "name 1 name2"
ex5 = "/home/user/Code/ARC/Projects/project name/calcs/file.sh"
self.assertEqual(common.fill_in_the_blanks(ex1), "name")
self.assertEqual(common.fill_in_the_blanks(ex2), "name1\\ name2")
self.assertEqual(common.fill_in_the_blanks(ex3), "name\\ 1\\ name2")
self.assertEqual(common.fill_in_the_blanks(ex4), "name\\ 1\\ \\ name2")
self.assertEqual(common.fill_in_the_blanks(ex5), "/home/user/Code/ARC/Projects/project\\ name/calcs/file.sh")

@classmethod
def tearDownClass(cls):
"""
Expand Down
2 changes: 2 additions & 0 deletions arc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ARC_PATH,
check_ess_settings,
delete_check_files,
fill_in_the_blanks,
get_logger,
globalize_path,
initialize_job_types,
Expand Down Expand Up @@ -280,6 +281,7 @@ def __init__(self,
self.verbose = verbose
self.project_directory = project_directory if project_directory is not None \
else os.path.join(ARC_PATH, 'Projects', self.project)
self.project_directory = fill_in_the_blanks(self.project_directory)
if not os.path.exists(self.project_directory):
os.makedirs(self.project_directory)
self.output = output
Expand Down
Loading