readthedocs.org
7d9a413f - Upgrade STORAGES setting to use Django's standard pattern (#12625)

Commit
45 days ago
Upgrade STORAGES setting to use Django's standard pattern (#12625) Migrates custom storage backends (`build-media`, `build-commands`, `build-tools`) to Django's `STORAGES` setting, enabling use of the standard `django.core.files.storage.storages` API. ### Changes - **Settings**: Added storage aliases to `STORAGES` property in `base.py`, `docker_compose.py`, and `test.py` - **Storage module**: Updated `readthedocs/storage/__init__.py` to use `storages["alias"]` instead of `get_storage_class(settings.RTD_*)` - **Build tasks**: Updated `readthedocs/projects/tasks/storage.py` to retrieve storage classes via `storages` API - **Test files**: Migrated `proxito/tests/base.py` and `rtd_tests/tests/test_imported_file.py` to new pattern - **Deprecation**: Added deprecation warning to `get_storage_class()` function ### Usage ```python # Before from readthedocs.storage import get_storage_class storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)() # After from django.core.files.storage import storages storage = storages["build-media"] ``` The lazy-loaded instances (`build_media_storage`, `build_commands_storage`, etc.) continue to work unchanged. > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses (expand for details)</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `search` > - Triggering command: `/usr/bin/python python -m pytest readthedocs/rtd_tests/tests/test_imported_file.py -v --tb=short` (dns block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to the custom allowlist in this repository's [Copilot coding agent settings](https://github.com/readthedocs/readthedocs.org/settings/copilot/coding_agent) (admins only) > > </details> <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Upgrade `STORAGES` setting to the new pattern</issue_title> > <issue_description>This is a follow up of the changes introduced in: > > * readthedocs/readthedocs.org#12220 > > We upgrade our settings to be like: > > ```python > @property > def STORAGES(self): > return { > "staticfiles": { > "BACKEND": self.RTD_STATICFILES_STORAGE, > "OPTIONS": { > "bucket_acl": "public-read", > "default_acl": "public-read", > "querystring_auth": False, > }, > }, > > "build-media": { > "BACKEND": self.RTD_BUILD_MEDIA_STORAGE, > "OPTIONS": { > "bucket_name": self.S3_MEDIA_STORAGE_BUCKET, > "custom_domain": self.S3_MEDIA_STORAGE_OVERRIDE_HOSTNAME, > "bucket_acl": "public-read", > "default_acl": "public-read", > "querystring_auth": False, > }, > }, > > # ... other storage backends here like `build-tools` and more ... > } > ``` > > With this, we will be able to delete all our classes and mixins to deal with multiple storages and make the code cleaner while using the Django standards: > > * https://github.com/readthedocs/readthedocs.org/blob/humitos%2Fstaticfiles/readthedocs/storage/__init__.py#L43-L46 > * https://github.com/readthedocs/readthedocs.org/blob/humitos%2Fstaticfiles/readthedocs/storage/s3_storage.py#L26-L121</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes readthedocs/readthedocs.org#12221 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: humitos <244656+humitos@users.noreply.github.com> Co-authored-by: Manuel Kaufmann <humitos@gmail.com> Co-authored-by: Santos Gallegos <stsewd@proton.me>
Author
Parents
Loading