Skip to content
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

Auto-create the dirs #120

Closed
jaraco opened this issue Dec 27, 2022 · 11 comments · Fixed by #155
Closed

Auto-create the dirs #120

jaraco opened this issue Dec 27, 2022 · 11 comments · Fixed by #155
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jaraco
Copy link

jaraco commented Dec 27, 2022

The app_paths project supports an additional interface (property) that will ensure the directory exists before returning it (alongside the classic interface where it's the caller's responsibility to create it). Having this interface is very convenient. Could platformdirs implement something similar?

@gaborbernat
Copy link
Contributor

If you fill a PR for it sure 👍

@ThomasWaldmann
Copy link
Contributor

I initially had a thumbs up on the top post, but I just removed it again.

We are currently working on adopting platformdirs to borgbackup and while dealing with the respective code, it became clear to me that:

  • auto-creating should not be fully automatic, but just if requested
  • whether one actually uses the path returned by platformdirs might depend on other circumstances also, e.g. whether some application-specific overriding env vars are set or not. if such an override happens, one would not want to auto-create a useless directory elsewhere just as a side-effect of querying the path.

@jaraco
Copy link
Author

jaraco commented Feb 4, 2023

Indeed. The way app_paths gave control was by exposing separate properties. Ex. user_data would auto-create while user_data_path would not.

@ThomasWaldmann
Copy link
Contributor

Hmm, is a separate property good enough considering the mode of the auto-created directory?

@jaraco
Copy link
Author

jaraco commented Feb 8, 2023

In my cases, mode was never a consideration. Maybe it will become relevant, but hasn't yet.

@smsearcy
Copy link
Contributor

smsearcy commented Feb 8, 2023

The basic use case of the default mode would suffice for my use cases as well, and I think this would be a very nice to have feature.

A couple thoughts/questions:

  • For the functions like platformdirs.user_data_dir(), would an additional create: bool = False keyword parameter make sense? (That could also include mode support.)
  • For the PlatformDirs class, does it make more sense to have additional properties or having a create: bool = False keyword parameter in the __init__()?

@gaborbernat
Copy link
Contributor

Yeah, a PR with that effect would be accepted.

@gaborbernat
Copy link
Contributor

gaborbernat commented Feb 8, 2023

Though instead of create I'd use ensure_exist. Feels more like what the stdlib would use https://docs.python.org/3/library/os.html#os.makedirs; and implies it would only create it if does not already exist.

@gaborbernat gaborbernat added enhancement New feature or request help wanted Extra attention is needed labels Feb 23, 2023
@Akuli
Copy link

Akuli commented Mar 20, 2023

If I do PlatformDirs("foo", "bar", ensure_exist=True), will it create all the different directories (config, cache, log, site cache, site data, ...) or only the ones I use?

I hope only the used directories will be created. It means that accessing a property will magically create a directory, but it doesn't seem too magical to me.

Edit: Nevermind, this was already discussed above. Should have read more carefully...

@smsearcy
Copy link
Contributor

FYI, I finally started a branch for this. I need to write some tests then I'll open the PR.

@gaborbernat
Copy link
Contributor

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants