Skip to content

Conversation

msto
Copy link
Contributor

@msto msto commented Jul 19, 2025

Summary

Hey @ayushkamat @rahuldesai1

I'm starting to migrate some of our workflows away from the deprecated LatchFile/LatchDir API to LPath. I'm appreciating the ways the LPath API seems to mirror the standard library's pathlib - it should make for an easy transition.

Would you be open to adding an exists() method to LPath, analogous to pathlib.Path.exists()?

There seems to be a couple ways it could be implemented - I used self.fetch_metadata(), but we could just as easily borrow the existence check from LPath.mkdirp() which uses NodeData.exists(). I thought it'd be preferable to use self.fetch_metadata() because when the user checks if a path exists, then the metadata will be cached for any following operations.

Let me know if there are any edge cases (not sure if mounts or account roots need special handling), or if there are any tests I should add or update.

@msto msto requested a review from ayushkamat as a code owner July 19, 2025 18:33
@ayushkamat
Copy link
Contributor

Hi @msto this is a good approach, here are some things that we should do before merging:

  1. We would like to cache the .exists() value, so we need to change the schema of self._cache
  2. Follow the convention of other metadata getters and pass a load_if_missing kw parameter with appropriate logic to not call self.fetch_metadata() and use the cached value if False

@msto
Copy link
Contributor Author

msto commented Jul 20, 2025

Thanks Ayush!

I did see that pattern in the other getters, but I deliberately omitted it here because I don't think an existence check should rely on cached metadata. I am typically using this functionality to prevent a workflow from overwriting an existing output, or from attempting to write to a non-existent directory. It's important that these checks use up-to-date information.

I'd prefer to leave the implementation as-is, for safety, but I'd be open to adding the caching if we can also introduce a boolean parameter (e.g. refresh or use_cache) that permits the user to bypass the cache.

What do you think?

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.

2 participants