Skip to content

Deprecate delete_removed_files from ScratchDir #762

Open
DanielYang59 wants to merge 2 commits intomaterialyzeai:masterfrom
DanielYang59:fix-scratchdir-wipe-cwd
Open

Deprecate delete_removed_files from ScratchDir #762
DanielYang59 wants to merge 2 commits intomaterialyzeai:masterfrom
DanielYang59:fix-scratchdir-wipe-cwd

Conversation

@DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Aug 18, 2025

@Andrew-S-Rosen @shyuep I'm not sure what's the best fix here? Maybe we should remove the argument altogether (not sure if there's any use case for this)?

I assume from a user's prospective one would expect to run a job in a scratch directory, and decide whether or not to copy newly generated files to CWD, in any case I wouldn't expect CWD to be wiped?

@DanielYang59 DanielYang59 changed the title Change delete_removed_files of ScratchDir default to False Remove delete_removed_files from ScratchDir Aug 18, 2025
@DanielYang59 DanielYang59 force-pushed the fix-scratchdir-wipe-cwd branch 2 times, most recently from 55f7630 to 5c89da6 Compare August 18, 2025 16:23
@codecov
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.11%. Comparing base (a0a2265) to head (de9bd37).

Files with missing lines Patch % Lines
src/monty/tempfile.py 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #762      +/-   ##
==========================================
- Coverage   85.27%   85.11%   -0.17%     
==========================================
  Files          27       27              
  Lines        1664     1659       -5     
  Branches      315      314       -1     
==========================================
- Hits         1419     1412       -7     
- Misses        186      187       +1     
- Partials       59       60       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DanielYang59 DanielYang59 marked this pull request as ready for review September 1, 2025 19:36
@Andrew-S-Rosen
Copy link
Contributor

If you are removing functionality altogether, then we should be removing the keyword argument. I am not opposed to its removal because I am generally of the opinion that packages should not delete files unless absolutely necessary --- too much room for disaster.

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Nov 28, 2025

Thanks for the comment, I guess you're suggesting that we just remove the keyword argument directly without deprecation warning (therefore would be breaking)? I'm personally not sure if it's worth it because currently that argument is effectively doing nothing and only issue a warning such that users would have time to react

@Andrew-S-Rosen
Copy link
Contributor

Isn't it currently breaking as the features for the kwarg were removed?

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Nov 28, 2025

emmm I don't think currently it would be breaking? i.e. if someone still try to use after we remove the features:

with ScratchDir(delete_removed_files=True):

It would just be no-op and issue a deprecation warning.

But if we remove delete_removed_files directly it would error out with unexpected keyword argument?

Comment on lines -178 to -182
# Delete any files that are now gone
if self.delete_removed_files:
for f in orig_files - files:
fpath = os.path.join(self.cwd, f)
remove(fpath)
Copy link
Contributor

@Andrew-S-Rosen Andrew-S-Rosen Nov 28, 2025

Choose a reason for hiding this comment

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

This is where I was confused. It looked like this would change the behavior and therefore be a breaking change anyway. My feeling was that if we are already introducing a breaking change and the argument now does literally nothing but raise a warning, then we should just be removing it altogether. We either keep the old behavior with a deprecation warning or we remove altogether, but changing the behavior and adding a deprecation warning does not make sense to me. Perhaps I have misunderstood.

Copy link
Contributor Author

@DanielYang59 DanielYang59 Nov 29, 2025

Choose a reason for hiding this comment

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

It looked like this would change the behavior and therefore be a breaking change anyway.

I understand your point now, so you were suggesting that making the delete_removed_files a no-op would be a "breaking change" as it changes the behaviour (it indeed does). But I'm not sure if this is really the case here as from my understand:

  1. It doesn't change the interface (delete_removed_files is still there for issuing the warning)
  2. The core functionality of ScratchDir is to create a scratch dir and delete_removed_files is for an optional clean up of the CWD (not the temp dir), so it would only be a breaking change if user really relies on the deletion behaviour (again which I consider not the core functionality). As I understand it, the core functionality is desribed below (i.e. create temp dir -> user operates in temp dir -> remove temp dir): https://github.com/materialsvirtuallab/monty/blob/a0a22650dfea5e13848ac8dc26a9da7a32301958/src/monty/tempfile.py#L36-L42

I pasted the question to GPT and here is what I got in case it's helpful for the discussion:
image

image image image image

Copy link
Contributor

@Andrew-S-Rosen Andrew-S-Rosen Nov 29, 2025

Choose a reason for hiding this comment

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

This is mostly semantics at this point, but if delete_removed_files used to delete removed files and now it doesn't, that's a breaking change even if it can have a dangerous side effect. The behavior is changed, and someone could have been relying on that. I disagree with ChatGPT.

This is just my take. And in the end, I personally do not really care what happens here to be quite honest. As long as the dangerous behavior is gone, I'm fine with that. I do not have reservations with this being merged.

Copy link
Contributor Author

@DanielYang59 DanielYang59 Nov 29, 2025

Choose a reason for hiding this comment

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

if delete_removed_files used to delete removed files and now it doesn't, that's a breaking change

I guess current behaviour is confusing/implicit in the first place, as it implicitly depends on copy_to_current_on_exit. Currently behaviour seems to be:
image

So I'm not sure if there is such case as "delete_removed_files used to delete removed files and now it doesn't" as when copy_to_current_on_exit=True, it would either nuke CWD (expected?) or do nothing (unexpected) ...

I also don't have a strong opinion to this end (the priority would be fixing the dangerous behaviour, which we did here), and I agree the rest is semantics. So I would let you decide.

Copy link
Contributor Author

@DanielYang59 DanielYang59 Nov 29, 2025

Choose a reason for hiding this comment

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

@DanielYang59 DanielYang59 force-pushed the fix-scratchdir-wipe-cwd branch 2 times, most recently from a1d1ea3 to 55ba0b0 Compare November 29, 2025 16:57
@DanielYang59 DanielYang59 marked this pull request as draft November 29, 2025 16:57
@DanielYang59 DanielYang59 force-pushed the fix-scratchdir-wipe-cwd branch 6 times, most recently from d813daa to 6059475 Compare November 29, 2025 17:09
@DanielYang59 DanielYang59 marked this pull request as ready for review November 29, 2025 17:12
@elemynt-ong
Copy link

Keep the kwarg and raise a Deprecation Warning and inform user htat this arg does nothing and will be removed in 2027.

@DanielYang59 DanielYang59 force-pushed the fix-scratchdir-wipe-cwd branch from 6059475 to de9bd37 Compare November 30, 2025 18:46
@DanielYang59 DanielYang59 changed the title Remove delete_removed_files from ScratchDir Deprecate delete_removed_files from ScratchDir Dec 6, 2025
@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Dec 6, 2025

@shyuep @elemynt-ong I think this should be ready for review, thanks

remove delete_removed_files ?

remove `delete_removed_files` directly
@DanielYang59 DanielYang59 force-pushed the fix-scratchdir-wipe-cwd branch from de9bd37 to 71287a3 Compare December 10, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ScratchDir("test_dir", copy_to_current_on_exit=True) would wipe current working directory

3 participants