-
Notifications
You must be signed in to change notification settings - Fork 0
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
Derive DirectoryObject
from Path
?
#13
Comments
💯 I am huge fan of this. Maybe it will require merging The biggest catch I can think of will be to ensure that we exclusively extend rather than modify |
Somewhat related, there has been some activity in Similarly, the stuff with browsing zipped content might be a cool feature to add in. |
Yeah that's actually my biggest concern. Right now I really like the fact that the files and directories are separated, because that's somewhat crucial that each node has its own working directory and file objects are derived from them, and all this is properly conceptualised. |
It sounds like we're on the same page (albeit your page is more densely packed with knowledge). I guess a reasonable attack is to simply try moving forward with the re-parenting as see how it turns out. |
I'm still a fan of this, is it still on your radar @samwaseda? My complaints/wishlist atm is:
|
I gave it a try, but this turned out to be a bit more complicated than I thought. I cannot remember what was the problem but I think I often got into conflicts with some existing methods
I thought our strategy was to create it first and delete it if it's not used? But ok I can also see that the object should be smart enough to know it. |
And I just realized that my last comment didn't answer your question at all. I guess the answer is yes, I still would like to give it a try, but maybe it's also good to think about what kind of interface we want. Since you raised this issue again, I presume you have something in mind? |
For not creating stuff we don't need, I'd be content to start with modifying For |
I just asked ChatGPT what it thinks and this is the answer I got: Deriving Deriving
|
I guess the short answer is ChatGPT thinks we shouldn't |
Hmm, #28 is not really what I had in mind. I was thinking of something more dramatic like replacing both classes with a single Maybe we're coming at this from the wrong perspective though. Perhaps we should start with this: (1) where is In pyiron/pyiron_workflow#413 I no longer depend directly on if filename.parent.exists() and not any(filename.parent.iterdir()):
filename.parent.rmdir() But what I really want is just Concretely, I'm imagining something like this to solve my issues: from pathlib import Path, PosixPath
class SuperPosixPath(PosixPath):
def super_rmdir(
self,
missing_ok=True,
only_empty=True,
):
if not self.exists():
if missing_ok:
return
else:
raise FileNotFoundError()
elif self.exists() and not self.is_dir():
raise NotADirectoryError()
for sub in self.iterdir():
if sub.is_dir():
SuperPosixPath(sub).super_rmdir(only_empty=only_empty)
elif not only_empty:
sub.unlink() # Probably need to care about kwargs here for edge cases
if not any(self.iterdir()):
self.rmdir()
p = Path("my_example")
p1 = p / "sub"
p1f = p1 / "foo.txt"
p2 = p / "sub2"
p1.mkdir(parents=True, exist_ok=True)
p2.mkdir(parents=True, exist_ok=True)
p1f.write_text("blah blah")
super_p = SuperPosixPath(p)
super_p.super_rmdir()
print(p.is_dir(), p1.is_dir(), p1f.is_file(), p2.exists())
# True True True False
super_p.super_rmdir(only_empty=False)
print(p.exists())
# False
super_p.super_rmdir(only_empty=False)
# Does nothing, missing_ok defaults to true! Of course work needs to be done to handle the |
Currently
DirectoryObject
is its own class. There are, however, functionalities that are given almost identically inPath
frompathlib
(whichDirectoryObject
anyway heavily uses). Furthermore there are functionalities that I would love to have but are not implemented inDirectoryObject
yet, such aspath_1 / path_2
etc. So I thought maybe it makes more sense to deriveDirectoryObject
fromPath
, so that people can straightforwardly use the same functionalities. What do you think? @liamhuberThe text was updated successfully, but these errors were encountered: