Repository: Quantum-Accelerators/quacc
Pull request #1934 (2024-03-21 17:13:06)

Small changes in copy_decompress_files
## Summary of Changes

Attempt to fix https://github.com/Quantum-Accelerators/quacc/issues/1933

### Checklist

- [x] I have read the ["Guidelines" section](https://quantum-accelerators.github.io/quacc/dev/contributing.html#guidelines) of the contributing guide. Don't lie! 😉
- [x] My PR is on a custom branch and is _not_ named `main`.
- [ ] I have added relevant, comprehensive [unit tests](https://quantum-accelerators.github.io/quacc/dev/contributing.html#unit-tests).

### Notes

- Your PR will likely not be merged without proper and thorough tests.
- If you are an external contributor, you will see a comment from [@buildbot-princeton](https://github.com/buildbot-princeton). This is solely for the maintainers.
- When your code is ready for review, ping one of the [active maintainers](https://quantum-accelerators.github.io/quacc/about/contributors.html#active-maintainers).


buildbot-princeton: Can one of the admins verify this patch?
Andrew-S-Rosen: Thanks for the issue report and bug fix, @tomdemeyere! This is a good catch. To really be sure I don't screw this up, we should also add a test to https://github.com/tomdemeyere/quacc/blob/fix_copy_decompress/tests/core/utils/test_files.py for good measure with the **/name.* type pattern.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/Quantum-Accelerators/quacc/pull/1934?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.29%. Comparing base [(`cb99c5e`)](https://app.codecov.io/gh/Quantum-Accelerators/quacc/commit/cb99c5e8f1b150e3f4d15eebfe90093eef5c0c25?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators) to head [(`40fc318`)](https://app.codecov.io/gh/Quantum-Accelerators/quacc/pull/1934?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators).


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #1934      +/-   ##
==========================================
- Coverage   99.29%   99.29%   -0.01%     
==========================================
  Files          81       81              
  Lines        3275     3273       -2     
==========================================
- Hits         3252     3250       -2     
  Misses         23       23              
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/Quantum-Accelerators/quacc/pull/1934?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators).

Andrew-S-Rosen: Thanks, @tomdemeyere! I think I'm fine with it. Later today, I'll just play around with a few edge cases locally to see if anything goes screwy that I need to address. I'll merge it then.

Patch:
diff --git a/docs/install/wflow_engines.md b/docs/install/wflow_engines.md
index 098ba82d..e3961194 100644
--- a/docs/install/wflow_engines.md
+++ b/docs/install/wflow_engines.md
@@ -226,9 +226,9 @@ Using a workflow engine is a crucial component for scaling up quacc calculations
     job_name: quacc_firework
     qos: regular
     pre_rocket: |
-    conda activate MyEnv
-    module load MyModuleName
-    export MyEnvVar=MyEnvValue
+                conda activate MyEnv
+                module load MyModuleName
+                export MyEnvVar=MyEnvValue
     ```
 
     In the above example, you would need to change the path in the `rocket_launch` field to the correct path to your `my_fworker.yaml`. The nodes, walltime, account, and qos are the corresponding parameters for your queuing system. Finally, anything in the `pre_rocket` field will be executed before the job begins running. It is a good place to load modules and set environment variables. A representative example has been provided above.
diff --git a/docs/user/wflow_engine/executors.md b/docs/user/wflow_engine/executors.md
index 10744ae0..b46c7a82 100644
--- a/docs/user/wflow_engine/executors.md
+++ b/docs/user/wflow_engine/executors.md
@@ -936,9 +936,9 @@ First, prepare your `QUACC_VASP_PP_PATH` environment variable in the `~/.bashrc`
     job_name: quacc_firework
     qos: debug
     pre_rocket: |
-    conda activate quacc
-    module load vasp/6.4.1-cpu
-    export QUACC_VASP_PARALLEL_CMD="srun -N 1 --ntasks-per-node=128 --cpu_bind=cores"
+                conda activate quacc
+                module load vasp/6.4.1-cpu
+                export QUACC_VASP_PARALLEL_CMD="srun -N 1 --ntasks-per-node=128 --cpu_bind=cores"
     ```
 
     From the login node of the remote machine, then run the following:
diff --git a/src/quacc/utils/files.py b/src/quacc/utils/files.py
index e3610f67..6413e6c9 100644
--- a/src/quacc/utils/files.py
+++ b/src/quacc/utils/files.py
@@ -136,14 +136,12 @@ def copy_decompress_files(
         filenames = [filenames]
 
     for f in filenames:
-        f_path = Path(f)
         globs_found = list(source_directory.glob(str(f)))
         if not globs_found:
             logger.warning(f"Cannot find file {f} in {source_directory}")
         for source_filepath in globs_found:
-            n_parts_to_keep = len(f_path.parts)
-            destination_filepath = destination_directory / Path(
-                "/".join(source_filepath.parts[-n_parts_to_keep:])
+            destination_filepath = destination_directory / source_filepath.relative_to(
+                source_directory
             )
             Path(destination_filepath.parent).mkdir(parents=True, exist_ok=True)
 


Test patch:
diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
index 451c0380..8de4a428 100644
--- a/.github/workflows/tests.yaml
+++ b/.github/workflows/tests.yaml
@@ -224,7 +224,7 @@ jobs:
       - name: Install conda packages
         run: |
           conda install -n base conda-libmamba-solver
-          conda install psi4 libint==2.8.2 -c conda-forge --solver libmamba
+          conda install psi4 -c conda-forge --solver libmamba
 
       - name: Install pip packages
         run: |
diff --git a/tests/core/utils/test_files.py b/tests/core/utils/test_files.py
index 84144672..df5bf3e0 100644
--- a/tests/core/utils/test_files.py
+++ b/tests/core/utils/test_files.py
@@ -140,6 +140,32 @@ def test_copy_decompress_tree(tmp_path):
     assert not (dst / "dir1" / "symlink1").exists()
 
 
+@pytest.mark.skipif(os.name == "nt", reason="Windows doesn't support symlinks")
+def test_copy_decompress_tree_v2(tmp_path):
+    src = tmp_path / "src"
+    src.mkdir()
+
+    dst = tmp_path / "dst"
+    dst.mkdir()
+
+    Path(src / "dir1").mkdir()
+    Path(src / "dir2" / "dir3").mkdir(parents=True)
+    Path(src / "dir1" / "file2").touch()
+    Path(src / "dir1" / "file1").touch()
+    Path(src / "dir2" / "file1").touch()
+    Path(src / "dir2" / "dir3" / "file1").touch()
+    Path(src / "dir2" / "dir3" / "file2").touch()
+
+    copy_decompress_files(src, Path("**", "file1"), dst)
+
+    assert (dst / "dir1" / "file1").exists()
+    assert (dst / "dir2" / "file1").exists()
+    assert (dst / "dir2" / "dir3" / "file1").exists()
+
+    assert not (dst / "dir1" / "file2").exists()
+    assert not (dst / "dir2" / "dir3" / "file2").exists()
+
+
 def test_check_logfile(tmp_path):
     with open(tmp_path / "logs.out", "w") as f:
         f.write("trigger")