diff --git a/aiida_test_cache/mock_code/_cli.py b/aiida_test_cache/mock_code/_cli.py index bb18a7c..ed8c3f9 100644 --- a/aiida_test_cache/mock_code/_cli.py +++ b/aiida_test_cache/mock_code/_cli.py @@ -2,7 +2,6 @@ """ Implements the executable for running a mock AiiDA code. """ -import fnmatch import os import shutil import subprocess @@ -68,12 +67,7 @@ def _log(msg: str, error=False) -> None: # back up results to data directory os.makedirs(res_dir) - copy_files( - src_dir=Path('.'), - dest_dir=res_dir, - ignore_files=env.ignore_files, - ignore_paths=env.ignore_paths - ) + copy_files(src_dir=Path('.'), dest_dir=res_dir, ignore_paths=env.ignore_paths) else: # copy outputs from data directory to working directory @@ -87,15 +81,11 @@ def _log(msg: str, error=False) -> None: _log(f"Can not copy '{path.name}'.", error=True) -def copy_files( - src_dir: Path, dest_dir: Path, ignore_files: ty.Iterable[str], ignore_paths: ty.Iterable[str] -) -> None: +def copy_files(src_dir: Path, dest_dir: Path, ignore_paths: ty.Iterable[str]) -> None: """Copy files from source to destination directory while ignoring certain files/folders. :param src_dir: Source directory :param dest_dir: Destination directory - :param ignore_files: A list of file names (UNIX shell style patterns allowed) which are not copied to the - destination. :param ignore_paths: A list of paths (UNIX shell style patterns allowed) which are not copied to the destination. """ exclude_paths: set = {filepath for path in ignore_paths for filepath in src_dir.glob(path)} @@ -115,8 +105,6 @@ def copy_files( continue for filename in filenames: - if any(fnmatch.fnmatch(filename, expr) for expr in ignore_files): - continue if relative_dir / filename in exclude_files: continue diff --git a/aiida_test_cache/mock_code/_env_keys.py b/aiida_test_cache/mock_code/_env_keys.py index 218ebe9..8519497 100644 --- a/aiida_test_cache/mock_code/_env_keys.py +++ b/aiida_test_cache/mock_code/_env_keys.py @@ -22,7 +22,6 @@ class MockVariables: test_name: str data_dir: Path executable_path: str - ignore_files: ty.Iterable[str] ignore_paths: ty.Iterable[str] regenerate_data: bool fail_on_missing: bool @@ -39,7 +38,6 @@ def from_env(cls) -> "MockVariables": test_name=os.environ[_EnvKeys.TEST_NAME.value], data_dir=Path(os.environ[_EnvKeys.DATA_DIR.value]), executable_path=os.environ[_EnvKeys.EXECUTABLE_PATH.value], - ignore_files=os.environ[_EnvKeys.IGNORE_FILES.value].split(":"), ignore_paths=os.environ[_EnvKeys.IGNORE_PATHS.value].split(":"), regenerate_data=os.environ[_EnvKeys.REGENERATE_DATA.value] == "True", fail_on_missing=os.environ[_EnvKeys.FAIL_ON_MISSING.value] == "True", @@ -67,7 +65,6 @@ def to_env(self) -> str: export {_EnvKeys.LABEL.value}="{self.label}" export {_EnvKeys.DATA_DIR.value}="{self.data_dir}" export {_EnvKeys.EXECUTABLE_PATH.value}="{self.executable_path}" - export {_EnvKeys.IGNORE_FILES.value}="{':'.join(self.ignore_files)}" export {_EnvKeys.IGNORE_PATHS.value}="{':'.join(self.ignore_paths)}" export {_EnvKeys.REGENERATE_DATA.value}={'True' if self.regenerate_data else 'False'} export {_EnvKeys.FAIL_ON_MISSING.value}={'True' if self.fail_on_missing else 'False'} @@ -93,7 +90,6 @@ class _EnvKeys(Enum): LABEL = "AIIDA_MOCK_LABEL" DATA_DIR = "AIIDA_MOCK_DATA_DIR" EXECUTABLE_PATH = "AIIDA_MOCK_EXECUTABLE_PATH" - IGNORE_FILES = "AIIDA_MOCK_IGNORE_FILES" IGNORE_PATHS = "AIIDA_MOCK_IGNORE_PATHS" REGENERATE_DATA = "AIIDA_MOCK_REGENERATE_DATA" FAIL_ON_MISSING = "AIIDA_MOCK_FAIL_ON_MISSING" diff --git a/aiida_test_cache/mock_code/_fixtures.py b/aiida_test_cache/mock_code/_fixtures.py index bd7add1..bd81a33 100644 --- a/aiida_test_cache/mock_code/_fixtures.py +++ b/aiida_test_cache/mock_code/_fixtures.py @@ -8,7 +8,6 @@ import shutil import typing as ty import uuid -import warnings import click import pytest @@ -134,7 +133,6 @@ def _get_mock_code( label: str, entry_point: ty.Optional[str] = None, data_dir_abspath: ty.Union[None, str, pathlib.Path] = None, - ignore_files: ty.Iterable[str] = ('_aiidasubmit.sh', ), ignore_paths: ty.Iterable[str] = ('_aiidasubmit.sh', ), executable_name: str = '', hasher: type[InputHasher] = InputHasher, @@ -159,9 +157,6 @@ def _get_mock_code( data_dir_abspath : Absolute path of the directory where the code results are stored. - ignore_files : - A list of file names (UNIX shell style patterns allowed) which are not copied to the results directory - after the code has been executed. ignore_paths : A list of paths (UNIX shell style patterns allowed) that are not copied to the results directory after the code has been executed. @@ -174,21 +169,10 @@ def _get_mock_code( If 'generate', add new key (label) to config dictionary. _regenerate_test_data : If True, regenerate test data instead of reusing. - - .. deprecated:: 0.1.0 - Keyword `ignore_files` is deprecated and will be removed in `v1.0`. Use `ignore_paths` instead. """ - if ignore_files != ('_aiidasubmit.sh', ): - warnings.warn( - 'keyword `ignore_files` is deprecated and will be removed in `v1.0`. Use `ignore_paths` instead.', - DeprecationWarning, - stacklevel=2 - ) - # It's easy to forget the final comma and pass a string, e.g. `ignore_paths = ('_aiidasubmit.sh')` - for arg in (ignore_paths, ignore_files): - assert isinstance(arg, collections.abc.Iterable) and not isinstance(arg, str), \ - f"'ignore_files' and 'ignore_paths' arguments must be tuples or lists, found {type(arg)}" + assert isinstance(ignore_paths, collections.abc.Iterable) and not isinstance(ignore_paths, str), \ + f"'ignore_paths' argument must be tuple or list, found {type(ignore_paths)}" if entry_point is None: entry_point = label @@ -255,7 +239,6 @@ def _get_mock_code( test_name=request.node.name, data_dir=data_dir_pl, executable_path=code_executable_path, - ignore_files=ignore_files, ignore_paths=ignore_paths, regenerate_data=_regenerate_test_data, fail_on_missing=_fail_on_missing, diff --git a/docs/source/user_guide/mock_code.rst b/docs/source/user_guide/mock_code.rst index 573e2f1..7755257 100644 --- a/docs/source/user_guide/mock_code.rst +++ b/docs/source/user_guide/mock_code.rst @@ -30,7 +30,7 @@ First, we want to define a fixture for our mocked code in the ``conftest.py``: data_dir_abspath=DATA_DIR, entry_point='diff', # files *not* to copy into the data directory - ignore_files=('_aiidasubmit.sh', 'file*') + ignore_paths=('_aiidasubmit.sh', 'file*') ) Second, we need to tell the mock executable where to find the *actual* ``diff`` executable by creating a ``.aiida-test-cache-config.yml`` file in the top level of our plugin. diff --git a/tests/mock_code/test_ignore_paths.py b/tests/mock_code/test_ignore_paths.py index a2d7964..303088d 100644 --- a/tests/mock_code/test_ignore_paths.py +++ b/tests/mock_code/test_ignore_paths.py @@ -37,21 +37,12 @@ def test_ignore_paths(run_directory, tmp_path_factory): storage_directory = tmp_path_factory.mktemp('storage') # ignore everything - copy_files( - src_dir=run_directory, dest_dir=storage_directory, ignore_files=(), ignore_paths=('*', ) - ) + copy_files(src_dir=run_directory, dest_dir=storage_directory, ignore_paths=('*', )) assert not (storage_directory / '_aiidasubmit.sh').is_file() # ignore subfolder - copy_files( - src_dir=run_directory, dest_dir=storage_directory, ignore_files=(), ignore_paths=('my/', ) - ) - copy_files( - src_dir=run_directory, - dest_dir=storage_directory, - ignore_files=(), - ignore_paths=('my/subfolder', ) - ) + copy_files(src_dir=run_directory, dest_dir=storage_directory, ignore_paths=('my/', )) + copy_files(src_dir=run_directory, dest_dir=storage_directory, ignore_paths=('my/subfolder', )) assert (storage_directory / '_aiidasubmit.sh').is_file() assert (storage_directory / 'file2.txt').is_file() assert not (storage_directory / 'my' / 'subfolder' / 'file3.txt').is_file() @@ -60,37 +51,10 @@ def test_ignore_paths(run_directory, tmp_path_factory): copy_files( src_dir=run_directory, dest_dir=storage_directory, - ignore_files=(), ignore_paths=('my/subfolder/file3.txt', ) ) assert not (storage_directory / 'my' / 'subfolder' / 'file3.txt').is_file() # all should be there - copy_files(src_dir=run_directory, dest_dir=storage_directory, ignore_files=(), ignore_paths=()) - assert (storage_directory / 'my' / 'subfolder' / 'file3.txt').is_file() - - -def test_ignore_files(run_directory, tmp_path_factory): - """Test that ignore_files works as expected.""" - storage_directory = tmp_path_factory.mktemp('storage') - - # ignore everything - copy_files( - src_dir=run_directory, dest_dir=storage_directory, ignore_files=('*'), ignore_paths=() - ) - assert not (storage_directory / '_aiidasubmit.sh').is_file() - assert not (storage_directory / 'my' / 'subfolder' / 'file3.txt').is_file() - - # ignore only specific file (from subfolder) - copy_files( - src_dir=run_directory, - dest_dir=storage_directory, - ignore_files=('file3.txt', ), - ignore_paths=() - ) - assert not (storage_directory / 'my' / 'subfolder' / 'file3.txt').is_file() - assert (storage_directory / 'file2.txt').is_file() - - # all should be there - copy_files(src_dir=run_directory, dest_dir=storage_directory, ignore_files=(), ignore_paths=()) + copy_files(src_dir=run_directory, dest_dir=storage_directory, ignore_paths=()) assert (storage_directory / 'my' / 'subfolder' / 'file3.txt').is_file()