-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dirs_exist_ok
to CloudPath.copytree
#281
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #281 +/- ##
========================================
- Coverage 94.8% 94.4% -0.4%
========================================
Files 20 20
Lines 1318 1320 +2
========================================
- Hits 1250 1247 -3
- Misses 68 73 +5
|
This actually surfaces a tricky issue that I hadn't thought of before. Currently, because
Definitely not. This is intentionally a no-op so we can copy pathlib's implementation logic to our cloud implementations and not have to make changes to take out all of the |
Going through some stale PRs to get them moving. I think that we shouldn't introduce I think I'd go with an implementation that looks something like: def copytree(..., dirs_exist_ok: bool = None) -> Union[Path, "CloudPath"]:
if dirs_exist_ok is None:
warnings.warn("In a future version, `CloudPath.copytree` will have a `dirs_exist_ok=False` kwarg. Please specify `dirs_exist_ok=True` in your code if you do not want that behavior (issue #144).", CloudPathDeprecationWarning)
dirs_exist_ok = True # match current behavior until dirs_exist_ok=False introduced
... |
closes #144
Adds
dirs_exist_ok
argument toCloudPath.copytree
The original issue suggests adding the
dirs_exist_ok
functionality throughmkdir
. Usingmkdir
onS3Path
doesn't actually create a directory, since we can't make empty directories in cloud storage. Adding functionality to a no-opmkdir
seemed misleading, so the new argument doesn't usemkdir
to check if the destination directory exists. Instead the functionality is added tocopytree
outside ofmkdir
with the more explicitif destination.exists() and not dirs_exist_ok
.Questions
Since
.mkdir
doesn't work on eitherGSPath
orS3Path
, should we raise an implementation error when it is called? Currently it runs without error, but doesn't actually create a directory.destination.mkdir
line inCloudPath.copytree
doesn't actually create a cloud directory if it doesn't exist. The directory is created when the first file is copied withsubpath.copy(...)
. It seems like we need this line just for cases when the destination directory is local, is that right?S3Path.mkdir
definition would be:NotImplementedError
, toGSPath.mkdir
There is a note in the comments that empty directories can't be created in other forms of cloud storage (
GSPath
) either. It seems like we can handleGSPath
andS3Path
similarly for addingdirs_exist_ok
, is that right?