Skip to content

Commit

Permalink
Merge pull request #4 from jasongi/2-fix-s3-prefix
Browse files Browse the repository at this point in the history
Add support for custom S3ManifestStaticStorage subclasses with location set.
  • Loading branch information
jasongi committed Dec 26, 2024
2 parents 96add58 + 4dd2e66 commit 8be3e7d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
django-version: ['>=4.2,<4.3', '>=5.0,<5.1']
python-version: ['3.10', '3.11', '3.12', '3.13']
django-version: ['>=4.2,<4.3', '>=5.0,<5.2']
name: Test Python ${{ matrix.python-version }} Django ${{ matrix.django-version }}
steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Changelog
## 3.2.1
- change minimum django-storages version
- support for Django 5.1 and python 3.13

## 3.2.0
- Add support for custom S3ManifestStaticStorage subclasses with location set.
- Fix edge case where location is in the filename

## 3.1.3
- fixed 2-pass to copy subdirectories

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Install test dependencies and target Django version:

```bash
python3 -m pip install -r test-requirements.txt
python3 -m pip install django==5.0.2
python3 -m pip install django==5.1.4
```

Run test suite:
Expand Down
2 changes: 1 addition & 1 deletion collectfasta/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.1.3"
__version__ = "3.2.1"
10 changes: 8 additions & 2 deletions collectfasta/strategies/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ class WithoutPrefixMixin(StrategyWithLocationProtocol):

def copy_args_hook(self, args: Task) -> Task:
assert isinstance(self.remote_storage, HasLocationProtocol)
if self.remote_storage.location == "" or self.remote_storage.location.endswith(
"/"
):
location = self.remote_storage.location
else:
location = f"{self.remote_storage.location}/"
return (
args[0].replace(self.remote_storage.location, ""),
args[1].replace(self.remote_storage.location, ""),
args[0].replace(location, ""),
args[1].replace(location, ""),
args[2],
)

Expand Down
22 changes: 14 additions & 8 deletions collectfasta/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def deco(f):
S3_STORAGE_BACKEND = "storages.backends.s3.S3Storage"
S3_STATIC_STORAGE_BACKEND = "storages.backends.s3.S3StaticStorage"
S3_MANIFEST_STATIC_STORAGE_BACKEND = "storages.backends.s3.S3ManifestStaticStorage"
S3_CUSTOM_MANIFEST_STATIC_STORAGE_BACKEND = (
"collectfasta.tests.utils.S3ManifestCustomStaticStorage"
)

GOOGLE_CLOUD_STORAGE_BACKEND = "collectfasta.tests.utils.GoogleCloudStorageTest"
FILE_SYSTEM_STORAGE_BACKEND = "django.core.files.storage.FileSystemStorage"

Expand All @@ -39,6 +43,7 @@ def deco(f):
S3_STORAGE_BACKEND,
S3_STATIC_STORAGE_BACKEND,
S3_MANIFEST_STATIC_STORAGE_BACKEND,
S3_CUSTOM_MANIFEST_STATIC_STORAGE_BACKEND,
]
BACKENDS = [
*S3_BACKENDS,
Expand All @@ -63,6 +68,11 @@ def deco(f):
BOTO3_MANIFEST_MEMORY_STRATEGY,
BOTO3_MANIFEST_FILE_SYSTEM_STRATEGY,
],
S3_CUSTOM_MANIFEST_STATIC_STORAGE_BACKEND: [
BOTO3_STRATEGY,
BOTO3_MANIFEST_MEMORY_STRATEGY,
BOTO3_MANIFEST_FILE_SYSTEM_STRATEGY,
],
GOOGLE_CLOUD_STORAGE_BACKEND: [GOOGLE_CLOUD_STRATEGY],
FILE_SYSTEM_STORAGE_BACKEND: [FILE_SYSTEM_STRATEGY, CACHING_FILE_SYSTEM_STRATEGY],
}
Expand Down Expand Up @@ -90,13 +100,6 @@ def params_for_backends():
)


S3_BACKENDS = [
S3_STORAGE_BACKEND,
S3_STATIC_STORAGE_BACKEND,
S3_MANIFEST_STATIC_STORAGE_BACKEND,
]


class StrategyFixture:
def __init__(self, expected_copied_files, backend, strategy, two_pass):
self.backend = backend
Expand All @@ -111,7 +114,10 @@ def strategy(request):
if strategy in (
BOTO3_MANIFEST_MEMORY_STRATEGY,
BOTO3_MANIFEST_FILE_SYSTEM_STRATEGY,
) and backend in (S3_MANIFEST_STATIC_STORAGE_BACKEND):
) and backend in (
S3_MANIFEST_STATIC_STORAGE_BACKEND,
S3_CUSTOM_MANIFEST_STATIC_STORAGE_BACKEND,
):
expected_copied_files = two_n_plus_1
else:
expected_copied_files = n
Expand Down
7 changes: 7 additions & 0 deletions collectfasta/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.conf import settings as django_settings
from django.utils.module_loading import import_string
from storages.backends.gcloud import GoogleCloudStorage
from storages.backends.s3boto3 import S3ManifestStaticStorage
from typing_extensions import Final

from collectfasta import settings
Expand Down Expand Up @@ -49,6 +50,11 @@ def __init__(self, *args, **kwargs):
self._client = get_fake_client()


class S3ManifestCustomStaticStorage(S3ManifestStaticStorage):
location = "prefix"
manifest_name = "prefixfiles.json"


def create_two_referenced_static_files() -> tuple[pathlib.Path, pathlib.Path]:
"""Create a static file, then another file with a reference to the file"""
path = create_static_file()
Expand Down Expand Up @@ -84,6 +90,7 @@ def create_big_static_file() -> pathlib.Path:
def clean_static_dir() -> None:
clean_static_dir_recurse(static_dir.as_posix())
clean_static_dir_recurse(django_settings.AWS_LOCATION)
clean_static_dir_recurse(S3ManifestCustomStaticStorage.location)


def clean_static_dir_recurse(location: str) -> None:
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ classifiers =
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Framework :: Django
author = Anton Agestam, Jason Giancono
author_email = jasongiancono+github@gmail.com
Expand All @@ -26,7 +27,7 @@ include_package_data = True
packages = find:
install_requires =
Django>=4.2
django-storages>=1.6
django-storages>=1.13.2
typing-extensions
python_requires = >=3.9

Expand Down

0 comments on commit 8be3e7d

Please sign in to comment.