From 82ec7c7d093bb834d448c1c447e0dd3762bac94b Mon Sep 17 00:00:00 2001 From: Jon Clucas Date: Tue, 12 Apr 2022 15:20:39 -0400 Subject: [PATCH] :bug: Fix makedirs permission issue --- .gitignore | 4 +++- src/cpac/backends/platform.py | 2 +- src/cpac/helpers/__init__.py | 5 +---- src/cpac/helpers/cpac_read_crash.py | 1 - src/cpac/utils/utils.py | 2 ++ tests/CONSTANTS.py | 2 +- tests/test_cpac_run.py | 1 - tests/test_cpac_utils.py | 1 - 8 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b457ca9f..5a226a96 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ __pycache__/* .cache/* .*.swp */.ipynb_checkpoints/* +tmp # Project files .ropeproject @@ -49,4 +50,5 @@ MANIFEST .venv*/ # Singularity Images -**/*.simg \ No newline at end of file +**/*.simg +**/*.sif \ No newline at end of file diff --git a/src/cpac/backends/platform.py b/src/cpac/backends/platform.py index 6458099c..a612effc 100644 --- a/src/cpac/backends/platform.py +++ b/src/cpac/backends/platform.py @@ -331,7 +331,7 @@ def _prep_binding(self, volume: Volume, ) if not os.path.exists(volume.local): try: - os.makedirs(volume.local, mode=777) + os.makedirs(volume.local, exist_ok=True) except PermissionError as perm: if second_try: raise perm diff --git a/src/cpac/helpers/__init__.py b/src/cpac/helpers/__init__.py index 3a7f16ef..dce15153 100644 --- a/src/cpac/helpers/__init__.py +++ b/src/cpac/helpers/__init__.py @@ -10,10 +10,7 @@ 'persists, run\n ' r'2. `docker attach `' '\n ' - r'3. `exit`', - 'permission_denied': 'Pytest is getting "permission denied" errors ' - 'writing to tmp directories, but running ' - 'outside of Pytest is working locally'} + r'3. `exit`'} def get_extra_arg_value(extra_args, argument): diff --git a/src/cpac/helpers/cpac_read_crash.py b/src/cpac/helpers/cpac_read_crash.py index 480f9090..000fb784 100755 --- a/src/cpac/helpers/cpac_read_crash.py +++ b/src/cpac/helpers/cpac_read_crash.py @@ -7,7 +7,6 @@ import os import re - from sys import argv path_regex = re.compile( diff --git a/src/cpac/utils/utils.py b/src/cpac/utils/utils.py index 4091b34b..46303398 100644 --- a/src/cpac/utils/utils.py +++ b/src/cpac/utils/utils.py @@ -188,6 +188,8 @@ def __init__(self, local: str, bind: str = None, def __init__(self, local, bind=None, mode=None): # noqa: E301 self.local = local self.bind = bind if bind is not None else local + if self.bind is not None and not self.bind.startswith('/'): + self.bind = os.path.abspath(self.bind) if isinstance(mode, PermissionMode): self.mode = mode elif mode is not None: diff --git a/tests/CONSTANTS.py b/tests/CONSTANTS.py index 0fe90457..9018fa7d 100644 --- a/tests/CONSTANTS.py +++ b/tests/CONSTANTS.py @@ -1,6 +1,6 @@ '''Constants for tests''' # pylint: disable=invalid-name -TAGS = [None, 'latest', 'nightly' +TAGS = [None, 'latest', 'nightly'] def args_before_after(argv, args): diff --git a/tests/test_cpac_run.py b/tests/test_cpac_run.py index 8bc577b2..3bc1c229 100644 --- a/tests/test_cpac_run.py +++ b/tests/test_cpac_run.py @@ -38,7 +38,6 @@ def run_test(argv): run_test(f'cpac {argv}'.split(' ')) -@pytest.mark.skip(reason=TODOs['permission_denied']) @pytest.mark.parametrize('argsep', [' ', '=']) @pytest.mark.parametrize('pipeline_file', [None, MINIMAL_CONFIG]) def test_run_test_config(argsep, pipeline_file, tmp_path, platform, tag): diff --git a/tests/test_cpac_utils.py b/tests/test_cpac_utils.py index fd9e7eec..ae64d957 100644 --- a/tests/test_cpac_utils.py +++ b/tests/test_cpac_utils.py @@ -35,7 +35,6 @@ def run_test(argv, platform): run_test(f'cpac {argv}'.split(' '), platform) -@pytest.mark.skip(reason=TODOs['permission_denied']) @pytest.mark.parametrize('argsep', [' ', '=']) def test_utils_new_settings_template(argsep, tmp_path, platform, tag): """Test 'utils data_config new_settings_template' command"""