### Install Collectfasta Source: https://github.com/jasongi/collectfasta/blob/master/README.md Install the Collectfasta package using pip. Ensure you are using Python 3. ```bash python3 -m pip install Collectfasta ``` -------------------------------- ### Basic Setup for Collectfasta Source: https://context7.com/jasongi/collectfasta/llms.txt Register 'collectfasta' before 'django.contrib.staticfiles' and set the appropriate strategy based on your storage backend. ```python # settings.py # Install: # python3 -m pip install Collectfasta INSTALLED_APPS = [ # ... other apps ... "collectfasta", # must come before django.contrib.staticfiles "django.contrib.staticfiles", ] STORAGES = { "staticfiles": { "BACKEND": "storages.backends.s3boto3.S3Boto3Storage", }, } # Pick the strategy that matches your STORAGES backend: COLLECTFASTA_STRATEGY = "collectfasta.strategies.boto3.Boto3Strategy" # Run exactly like the built-in command: # python manage.py collectstatic ``` -------------------------------- ### Install Test Dependencies and Django Source: https://github.com/jasongi/collectfasta/blob/master/README.md Install project test dependencies and a specific Django version using pip. This is required before running the test suite. ```bash python3 -m pip install -r test-requirements.txt python3 -m pip install django==5.2.3 ``` -------------------------------- ### Install Code Quality Tools Source: https://github.com/jasongi/collectfasta/blob/master/README.md Install code quality tools using pip. These tools are separate from test requirements and may have specific Python version dependencies. ```bash python3 -m pip install -r lint-requirements.txt ``` -------------------------------- ### Configure FileSystemStorage for Collectfasta Source: https://context7.com/jasongi/collectfasta/llms.txt Sets up Django's FileSystemStorage for Collectfasta. Use the CachingFileSystemStrategy for better performance on repeated runs. ```python STORAGES = { "staticfiles": { "BACKEND": "django.core.files.storage.FileSystemStorage", }, } # Without caching: COLLECTFASTA_STRATEGY = "collectfasta.strategies.filesystem.FileSystemStrategy" # With caching (recommended for repeated runs): COLLECTFASTA_STRATEGY = "collectfasta.strategies.filesystem.CachingFileSystemStrategy" STATIC_ROOT = "/var/www/myproject/static/" ``` -------------------------------- ### Run Test Suite Source: https://github.com/jasongi/collectfasta/blob/master/README.md Execute the project's test suite using the make command. This command runs tests against configured environments. ```bash make test ``` -------------------------------- ### Set Up Live Test Credentials Source: https://github.com/jasongi/collectfasta/blob/master/README.md Set environment variables for AWS and Google Cloud API credentials to run live tests. Ensure Google Cloud credentials are Base64 encoded JSON. ```bash export AWS_ACCESS_KEY_ID='...' export AWS_SECRET_ACCESS_KEY='...' export GCLOUD_API_CREDENTIALS_BASE64='{...}' # Google Cloud credentials as Base64'd json ``` -------------------------------- ### Configure Dedicated Cache Backend Source: https://github.com/jasongi/collectfasta/blob/master/README.md Set up a dedicated cache backend for Collectfasta to improve performance. A high TIMEOUT setting is recommended. If not set, the 'default' cache will be used. ```python CACHES = { "default": { # Your default cache }, "collectfasta": { # Your dedicated Collectfasta cache }, } COLLECTFASTA_CACHE = "collectfasta" ``` -------------------------------- ### Google Cloud Storage Strategy Configuration Source: https://context7.com/jasongi/collectfasta/llms.txt Configure Collectfasta to use GoogleCloudStrategy with GoogleCloudStorage for efficient static file collection on GCS. ```python # settings.py — Google Cloud Storage STORAGES = { "staticfiles": { "BACKEND": "storages.backends.gcloud.GoogleCloudStorage", }, } COLLECTFASTA_STRATEGY = "collectfasta.strategies.gcloud.GoogleCloudStrategy" GS_BUCKET_NAME = "my-static-bucket" GS_DEFAULT_ACL = "publicRead" ``` -------------------------------- ### Configure Collectfasta Settings Source: https://github.com/jasongi/collectfasta/blob/master/README.md Configure Collectfasta in your Django settings.py file. Ensure 'collectfasta' is added to INSTALLED_APPS before 'django.contrib.staticfiles'. ```python STORAGES = ( { "staticfiles": { "BACKEND": "storages.backends.s3.S3Storage", }, }, ) COLLECTFASTA_STRATEGY = "collectfasta.strategies.boto3.Boto3Strategy" INSTALLED_APPS = ( # ... "collectfasta", ) ``` -------------------------------- ### Configure Dedicated Cache Backend for Collectfasta Source: https://context7.com/jasongi/collectfasta/llms.txt Configures a separate cache backend for Collectfasta with a custom timeout and maximum entries. Ensure the backend is thread-safe if parallel uploads are enabled. ```python # settings.py — dedicated cache with high MAX_ENTRIES for large projects CACHES = { "default": { "BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache", "LOCATION": "127.0.0.1:11211", }, "collectfasta": { "BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache", "LOCATION": "127.0.0.1:11211", "TIMEOUT": 60 * 60 * 24 * 365, # 1 year "OPTIONS": { "MAX_ENTRIES": 5000, # set >= number of static files }, }, } COLLECTFASTA_CACHE = "collectfasta" # defaults to "default" if unset # To clear the cache entirely (e.g., after a full redeploy): # from django.core.cache import caches # caches["collectfasta"].clear() ``` -------------------------------- ### Run Tests with Docker Source: https://github.com/jasongi/collectfasta/blob/master/README.md Execute the test suite using Docker, targeting localstack or fake-gcs-server. This is useful for isolated testing without live cloud services. ```bash make test-docker ``` -------------------------------- ### Enable Parallel Uploads Source: https://github.com/jasongi/collectfasta/blob/master/README.md Enable parallel file uploads by setting COLLECTFASTA_THREADS. A thread-safe cache backend (not Django's default LocMemCache) must be configured. ```python COLLECTFASTA_THREADS = 20 ``` -------------------------------- ### Implement a Custom Collectfasta Strategy Source: https://context7.com/jasongi/collectfasta/llms.txt Extends `CachingHashStrategy` to support custom storage backends. Requires overriding `get_remote_file_hash` and optionally `post_copy_hook` and `on_skip_hook`. ```python # myapp/strategies.py from typing import Optional from django.core.files.storage import Storage from collectfasta.strategies.base import CachingHashStrategy from myapp.custom_storage import MyCustomStorage class MyCustomStrategy(CachingHashStrategy[MyCustomStorage]): # Exceptions raised by the backend when deleting a non-existent object delete_not_found_exception = (FileNotFoundError,) def get_remote_file_hash(self, prefixed_path: str) -> Optional[str]: """Return the MD5 hex digest of the remote file, or None if missing.""" try: return self.remote_storage.get_md5(prefixed_path) except self.remote_storage.NotFoundError: return None def post_copy_hook(self, path: str, prefixed_path: str, local_storage: Storage) -> None: """Called after a file is successfully uploaded.""" super().post_copy_hook(path, prefixed_path, local_storage) print(f"Uploaded: {path}") def on_skip_hook(self, path: str, prefixed_path: str, local_storage: Storage) -> None: """Called when a file is skipped because it is already up to date.""" print(f"Skipped (unchanged): {path}") # settings.py COLLECTFASTA_STRATEGY = "myapp.strategies.MyCustomStrategy" ``` -------------------------------- ### Azure Blob Storage Strategy Configuration Source: https://context7.com/jasongi/collectfasta/llms.txt Configure Collectfasta to use AzureBlobStrategy with AzureStorage for optimized static file collection on Azure Blob Storage. ```python # settings.py — Azure Blob Storage STORAGES = { "staticfiles": { "BACKEND": "storages.backends.azure_storage.AzureStorage", }, } COLLECTFASTA_STRATEGY = "collectfasta.strategies.azure.AzureBlobStrategy" AZURE_ACCOUNT_NAME = "mystorageaccount" AZURE_ACCOUNT_KEY = "..." AZURE_CONTAINER = "static" ``` -------------------------------- ### AWS S3 Strategy Configuration Source: https://context7.com/jasongi/collectfasta/llms.txt Configure Collectfasta to use Boto3Strategy with S3Boto3Storage or S3StaticStorage for optimized S3 static file collection. ```python # settings.py — S3 standard or static storage STORAGES = { "staticfiles": { "BACKEND": "storages.backends.s3boto3.S3StaticStorage", }, } COLLECTFASTA_STRATEGY = "collectfasta.strategies.boto3.Boto3Strategy" AWS_STORAGE_BUCKET_NAME = "my-static-bucket" AWS_S3_REGION_NAME = "us-east-1" AWS_IS_GZIPPED = True # Collectfasta will hash gzip-compressed content correctly ``` -------------------------------- ### Enable Parallel Uploads with Collectfasta Source: https://context7.com/jasongi/collectfasta/llms.txt Enables multi-threaded uploads using ThreadPoolExecutor. Requires a thread-safe cache backend like RedisCache. ```python # settings.py — parallel uploads with 20 threads COLLECTFASTA_THREADS = 20 # The cache backend MUST be thread-safe; LocMemCache (Django's default) is NOT. CACHES = { "default": { "BACKEND": "django.core.cache.backends.redis.RedisCache", "LOCATION": "redis://127.0.0.1:6379/1", }, "collectfasta": { "BACKEND": "django.core.cache.backends.redis.RedisCache", "LOCATION": "redis://127.0.0.1:6379/2", "TIMEOUT": 31536000, "OPTIONS": {"MAX_ENTRIES": 10000}, }, } COLLECTFASTA_CACHE = "collectfasta" COLLECTFASTA_STRATEGY = "collectfasta.strategies.boto3.Boto3Strategy" ``` -------------------------------- ### AWS S3 Manifest Storage Strategy Source: https://context7.com/jasongi/collectfasta/llms.txt Use Boto3ManifestMemoryStrategy for S3ManifestStaticStorage to perform a first pass in-memory, optimizing uploads for manifest-based storage. ```python # settings.py — S3 manifest storage (two-pass, in-memory first pass) STORAGES = { "staticfiles": { "BACKEND": "storages.backends.s3boto3.S3ManifestStaticStorage", }, } # Recommended for ManifestStaticStorage: COLLECTFASTA_STRATEGY = "collectfasta.strategies.boto3.Boto3ManifestMemoryStrategy" # Alternative: use filesystem for the first pass (useful for very large projects) # COLLECTFASTA_STRATEGY = "collectfasta.strategies.boto3.Boto3ManifestFileSystemStrategy" ``` -------------------------------- ### Run Linters and Type Checks Source: https://github.com/jasongi/collectfasta/blob/master/README.md Execute code linters and static type checking using the make checks command. This ensures code quality and adherence to standards. ```bash make checks ``` -------------------------------- ### Enable Debug Mode for Collectfasta Source: https://context7.com/jasongi/collectfasta/llms.txt Enables debug mode to surface exceptions raised during individual file copies. This helps in diagnosing storage-related errors. ```python # settings.py COLLECTFASTA_DEBUG = True # defaults to the value of Django's DEBUG setting # When True, exceptions during copy_file() propagate immediately rather than # being silently swallowed, making it easier to diagnose storage errors. ``` -------------------------------- ### Enable Debug Mode Source: https://github.com/jasongi/collectfasta/blob/master/README.md Set COLLECTFASTA_DEBUG to True in your Django settings to debug suppressed exceptions during file copying. By default, exceptions are suppressed. ```python COLLECTFASTA_DEBUG = True ``` -------------------------------- ### Disable Collectfasta for a Single Run Source: https://context7.com/jasongi/collectfasta/llms.txt Disables Collectfasta for a single execution of `collectstatic`, falling back to Django's standard behavior. ```bash # Disable for a single run (falls back to standard collectstatic): python manage.py collectstatic --disable-collectfasta ``` -------------------------------- ### Permanently Disable Collectfasta Source: https://context7.com/jasongi/collectfasta/llms.txt Permanently disables Collectfasta by setting a configuration variable in `settings.py`. Useful for local development or CI environments. ```python # settings.py — permanently disable (e.g., in local dev or CI): COLLECTFASTA_ENABLED = False ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.