-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[stdlib] Implementation of rmtree #2439
base: nightly
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty cool. Please make sure about the Int types though
d2ba422
to
d8debbf
Compare
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch! This could be very nice to have, but there are a bunch of library design questions, as well as implementation details that we should iron out. My main question at this point: do we actually want this right now, given that Python interop already allows one to do this?
While we work on these, I have a couple of suggestions that could help moving this forward: 1) we could use an os.makedirs
with an exist_ok
argument; 2) we could explore (maybe in a design doc) if we could start a tempfile
module to build some testing utilities. @artemiogr97 Would you be interested in working on either of these?
from os.path import islink, isdir, isfile | ||
|
||
|
||
fn rmtree(path: String, ignore_errors: Bool = False) raises: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoeLoser @ConnorGray Do you have any opinions if we should make ignore_errors
keyword-only? Python doesn't do this, but it's not clear if that's just a result of backward compatibility. Otherwise, I always feel a bit strange about flags that can be specified positionally.
|
||
Args: | ||
path: The path to the directory. | ||
ignore_errors: Whether to ignore errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea: Once we have parametric raising, we could introduce overloads that have this as a parameter. In the meanwhile, would it be beneficial to have a separate function that ignores errors and never raises?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that could make sense for now
var cwd_path = Path() | ||
var my_dir_path = cwd_path / "my_dir" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so sure about this. It would be nice if we had some tempfile
-like utilities to create these ephemeral paths. At the same time, tempfile
should probably depend on shutil
, not the other way around.
Idea 1: Maybe we could bring up some basic tempfile
utilities so that we can at least have a platform-independent temporary path.
Idea 2: we could just use python interop in these tests while we get there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess python interop is the best option for now, one idea to prevent testing shutil
with a potential tempfile
module (which logically would depend on shutil
) would be to use something like subprocess.run
and call something like rm -rf my_dir
, but it does not seem like a short-term solution
mkdir(my_dir_path) | ||
_create_some_files_and_dirs(my_dir_path) | ||
|
||
rmtree(my_dir_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing these kinds of functions can actually be tricky: what if the test fails for some reason and the directory isn't deleted? The next time the test is run, mkdir
can fail. One way to fix this is by doing this in a context manager, like tempfile.TemporaryDirectory
. In lieu of that, some manual cleanup logic could also work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's tricky, but doing some manual cleanup is not that simple in this case, what if what is failing is rmdir/unlink
? obviously rmtree
is relying on those functions so what else could be done?
we have the same "issue" in test_remove
and test_mkdir_and_rmdir
I agree that maybe it is a bit soon to start implementing a new module such as
for your point 1, yes, I would like to work on that, everything that could be done to "complete" the
for 2 I'm not sure what there is to explore/discuss about a |
That's awesome, thank you! Please ping me if you have PRs for these, I'm happy to review. I'm assuming these
For now, don't worry about Windows. The existing code in
I would be lazy about this stuff. If the complexity of handling multiple platforms within
Yep, don't worry about this for now.
I see now that you already did quite a bit of work on |
#2430 must be merged first