Use shutil.copyfile instead of os.system("cp") in packing (Windows portability)#1343
Open
rayair250-droid wants to merge 1 commit into
Open
Use shutil.copyfile instead of os.system("cp") in packing (Windows portability)#1343rayair250-droid wants to merge 1 commit into
rayair250-droid wants to merge 1 commit into
Conversation
The two os.system("cp ...") calls in packing.py fail on Windows (cp is
Unix-only) even though mBuild ships on conda-forge win-64. They also shell
out unnecessarily. shutil is already imported and used in this module, so
replace them with shutil.copyfile for a portable, shell-free copy.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1343 +/- ##
=======================================
Coverage 86.07% 86.07%
=======================================
Files 52 52
Lines 4897 4897
=======================================
Hits 4215 4215
Misses 682 682 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
Thanks for the pull request! I agree, using shutil instead of os is better here in general. |
chrisjonesBSU
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
_run_packmol(mbuild/packing.py), two copies shell out tocpviaos.system.cpis a Unix-only command, but mBuild is distributed on conda-forge for win-64, and_check_packmolright below already branches onsys.platform.startswith("win"). On Windows both calls fail, which breaks:<name>_FORCEDover the result, andtemp_file.They also invoke a shell with interpolated filenames unnecessarily (breaks on paths containing spaces).
Change
Replace both
os.system("cp ...")calls withshutil.copyfile(...)— portable, shell-free, and already used elsewhere in this module (shutilis imported at the top). Also drops a no-op single-argumentos.path.join(temp_file).No behavior change on Unix; fixes the code path on Windows. Happy to add a regression test if desired.