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

feat: allow creating parent directories for a file store #3526

Merged
merged 23 commits into from
Jun 13, 2024

Conversation

Murtagy
Copy link
Contributor

@Murtagy Murtagy commented May 25, 2024

Description

Allow mkdir True when creating a file store.

Use case is rather small - initially deploying an application with FileStores used.

@Murtagy Murtagy requested review from a team as code owners May 25, 2024 12:06
@Murtagy Murtagy changed the title mkdir True feat: allow creating parent folders for a file store May 25, 2024
@Murtagy
Copy link
Contributor Author

Murtagy commented May 25, 2024

@all-contributors please add @Murtagy

Copy link
Contributor

@Murtagy

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

Copy link

codecov bot commented May 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.27%. Comparing base (95951db) to head (53fe233).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3526   +/-   ##
=======================================
  Coverage   98.27%   98.27%           
=======================================
  Files         328      328           
  Lines       14819    14824    +5     
  Branches     2361     2362    +1     
=======================================
+ Hits        14564    14569    +5     
  Misses        116      116           
  Partials      139      139           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

litestar/stores/file.py Outdated Show resolved Hide resolved
Copy link
Member

@provinzkraut provinzkraut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Murtagy for the PR :)

In general we can add this but:

  1. It should be configurable
  2. It should happen once during store startup, in the store's __aenter__

litestar/stores/file.py Outdated Show resolved Hide resolved
@Murtagy
Copy link
Contributor Author

Murtagy commented May 26, 2024

Thanks @Murtagy for the PR :)

In general we can add this but:

  1. It should be configurable
  2. It should happen once during store startup, in the store's __aenter__
  1. Why creating 1 folder is fine, but creating 2 has to be configurable. The "allow_create_folders" flag makes sense to me. "allow_create_more_than_1_folder" makes no sense to me.
    Or I misunderstand the flag's purpose?
    UPD: don't mind me, I for some reason thought that 1 dir is made by default, which is not the case
  2. I am a little slow in understanding the idea of scopes and the control flow of the framework, so done as a knee-jerk reaction to the exception, in the place where exception is made. Will look into it...

@Alc-Alc
Copy link
Contributor

Alc-Alc commented May 26, 2024

Thanks @Murtagy for the PR :)
In general we can add this but:

  1. It should be configurable
  2. It should happen once during store startup, in the store's __aenter__
  1. Why creating 1 folder is fine, but creating 2 has to be configurable. The "allow_create_folders" flag makes sense to me. "allow_create_more_than_1_folder" makes no sense to me.
    Or I misunderstand the flag's purpose?
    UPD: don't mind me, I for some reason thought that 1 dir is made by default, which is not the case
  2. I am a little slow in understanding the idea of scopes and the control flow of the framework, so done as a knee-jerk reaction to the exception, in the place where exception is made. Will look into it...

You just need one flag create_folders: bool = False. You can do await self.path.mkdir(exist_ok=True, parents= self.create_folders). The choice of naming is up in the air, I am impartial as long as it's self descriptive.

@Murtagy Murtagy requested a review from provinzkraut May 27, 2024 08:05
@Murtagy
Copy link
Contributor Author

Murtagy commented May 27, 2024

@provinzkraut (and/or others 😄), did this change in correct direction?

Co-authored-by: Jacob Coffee <[email protected]>
Copy link
Member

@provinzkraut provinzkraut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @Murtagy, just one more thing I'm afraid :)
I'd prefer if we change the naming from "folders" to "directories". This is the more commonly used term and is also used throughout Litestar.

cofin and others added 4 commits May 30, 2024 11:58
* chore(docs): updated example for flash messages

* chore: remove redundant store config
Co-authored-by: Jacob Coffee <[email protected]>

rm underscore

fix/already-async

.
@github-actions github-actions bot added the area/dependencies This PR involves changes to the dependencies label May 30, 2024
@github-actions github-actions bot removed the area/dependencies This PR involves changes to the dependencies label May 30, 2024
@Murtagy Murtagy changed the title feat: allow creating parent folders for a file store feat: allow creating parent directories for a file store May 30, 2024
@Murtagy Murtagy requested a review from provinzkraut May 30, 2024 12:21
@Murtagy
Copy link
Contributor Author

Murtagy commented May 30, 2024

codecov was correctly highlighting that the line I added did not run - the store was not going through context manager. The test succeeded, because the directory was created by other tests, so the parent folder already existed.
Fixed that, but overall not sure if the test harness I made is good, I did not work with pytest before

tests/conftest.py Outdated Show resolved Hide resolved
litestar/stores/file.py Outdated Show resolved Hide resolved
litestar/stores/file.py Show resolved Hide resolved
@Murtagy
Copy link
Contributor Author

Murtagy commented Jun 3, 2024

image
How do I get these running?

@Murtagy
Copy link
Contributor Author

Murtagy commented Jun 10, 2024

I think I have addressed all the comments and successfully restarted tests via merging master.
Are we good to go?

@Murtagy Murtagy requested a review from JacobCoffee June 11, 2024 09:38
@provinzkraut provinzkraut enabled auto-merge (squash) June 13, 2024 19:51
@provinzkraut provinzkraut merged commit f179aee into litestar-org:main Jun 13, 2024
24 checks passed
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3526

Alc-Alc pushed a commit that referenced this pull request Jul 26, 2024
---------

Co-authored-by: Maksim R <[email protected]>
Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Janek Nouvertné <[email protected]>
Co-authored-by: Cody Fincher <[email protected]>
Co-authored-by: euri10 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants