Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Merge 851f92f into 1e9811d
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam committed Oct 3, 2019
2 parents 1e9811d + 851f92f commit dfcc8df
Show file tree
Hide file tree
Showing 28 changed files with 771 additions and 526 deletions.
4 changes: 0 additions & 4 deletions .coveragerc

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*.egg-info
/static/
/static_root/
build/
/build/
dist/
aws-credentials
.mypy_cache
.idea
.python-version
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ python:
- '3.6'
- '3.7'
install:
- pip install --upgrade pip setuptools
- pip install django=="$DJANGO"
- pip install -r test-requirements.txt
# these are only supported on Python 3.7, so we allow the installation to fail
- pip install black sorti || true
# These are not supported on all Python versions, so we allow the installation
# to fail. Linting and static analysis only happens on the Python 3.7 builds.
- pip install -r lint-requirements.txt || true
env:
- DJANGO=1.11
- DJANGO=2.1
Expand All @@ -23,7 +25,7 @@ script:
- 'if [[ $(python --version) == "Python 3.7."* ]]; then flake8; fi'
- 'if [[ $(python --version) == "Python 3.7."* ]]; then black --check .; fi'
- 'if [[ $(python --version) == "Python 3.7."* ]]; then sorti --check .; fi'
- 'if [[ $(python --version) == "Python 3.7."* ]]; then mypy .; fi'
- 'if [[ $(python --version) == "Python 3.7."* && "$DJANGO" != "1.11" ]]; then pip install . && mypy .; fi'
- coverage run --source collectfast ./runtests.py
after_script:
- coveralls
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SHELL := /usr/bin/env bash

test:
. aws-credentials && ./runtests.py

Expand All @@ -8,3 +10,9 @@ distribute:
pip install --upgrade wheel twine setuptools
python setup.py sdist bdist_wheel
twine upload dist/*

lint:
flake8
sorti --check .
black --check .
mypy .
110 changes: 64 additions & 46 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
Collectfast – A Faster Collectstatic
====================================
Collectfast
===========

|Build Status| |Coverage Status|
A faster collectstatic command.

The fast ``collectstatic`` for Django projects with S3 as storage
backend.
|Build Status| |Coverage Status|

**Features**

- Comparing and caching of md5 checksums before uploading
- Parallel file uploads using Python's multiprocessing module
- Compares and caches file checksums before uploading
- Parallelizes file uploads using Python's multiprocessing module

**Supported Storage Backends**

- ``storages.backends.s3boto.S3BotoStorage`` (deprecated)
- ``storages.backends.s3boto3.S3Boto3Storage``

Running Django's ``collectstatic`` command can become really slow as
more and more files are added to a project, especially if heavy
libraries such as jQuery UI are included in the source. This is a custom
management command that compares the md5 sum of files with S3 and
completely ignores ``modified_time``. The results of the hash lookups
are cached locally using your default Django cache. This can make
deploying much faster!
Running Django's ``collectstatic`` command can become painfully slow as more
and more files are added to a project, especially when heavy libraries such as
jQuery UI are included in source code. Collectfast customizes the builtin
``collectstatic`` command, adding different optimizations to make uploading
large amounts of files much faster.


Installation
Expand All @@ -29,47 +31,54 @@ Install the app using pip:

$ pip install Collectfast

Make sure you have this in your settings file and add ``'collectfast'``
to your ``INSTALLED_APPS``:
Make sure you have this in your settings file and add ``'collectfast'`` to your
``INSTALLED_APPS``, before ``'django.contrib.staticfiles'``:

.. code:: python
STATICFILES_STORAGE = "storages.backends.s3boto.S3BotoStorage"
STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy"
INSTALLED_APPS = (
#
# ...
'collectfast',
)
``'collectfast'`` should come before ``'django.contrib.staticfiles'``.
Please note, that failure to do so will cause Django to use
``django.contrib.staticfiles``'s ``collectstatic``.
Collectfast comes with these upload strategies:

**Note:** ``preload_metadata`` of the storage class will be overwritten as
`True`, see `#30 <https://github.com/antonagestam/collectfast/issues/30>`_
- ``collectfast.strategies.boto.BotoStrategy`` for
``storages.backends.s3boto.S3BotoStorage``
- ``collectfast.strategies.boto3.Boto3Strategy`` for
``storages.backends.s3boto3.S3Boto3Storage``

**Note:** ``'collectfast'`` must come before ``'django.contrib.staticfiles'`` in
``INSTALLED_APPS``.

**Note:** Boto strategies will set ``preload_metadata`` on the remote storage to
``True``, see `#30 <https://github.com/antonagestam/collectfast/issues/30>`_.


Usage
-----

Collectfast overrides Django's builtin ``collectstatic`` command so just
run ``python manage.py collectstatic`` as normal. You can disable
Collectfast by using the ``--disable-collectfast`` option.
Collectfast overrides Django's builtin ``collectstatic`` command so just run
``python manage.py collectstatic`` as normal. You can disable Collectfast by
using the ``--disable-collectfast`` option.

You can also disable collectfast by setting
``COLLECTFAST_ENABLED = False`` in your settings file. This is useful
when using a local file storage backend for development.
You can also disable collectfast by setting ``COLLECTFAST_ENABLED = False`` in
your settings file. This is useful when using a local file storage backend for
development.


Setup Dedicated Cache Backend
-----------------------------

It's recommended to setup a dedicated cache backend for Collectfast.
Every time Collectfast does not find a lookup for a file in the cache it
will trigger a lookup to the storage backend, so it's recommended to
have a fairly high ``TIMEOUT`` setting.
It's recommended to setup a dedicated cache backend for Collectfast. Every
time Collectfast does not find a lookup for a file in the cache it will trigger
a lookup to the storage backend, so it's recommended to have a fairly high
``TIMEOUT`` setting.

Set up your dedicated cache in settings.py with the
``COLLECTFAST_CACHE`` setting:
Set up your dedicated cache in settings.py with the ``COLLECTFAST_CACHE``
setting:

.. code:: python
Expand All @@ -86,14 +95,13 @@ Set up your dedicated cache in settings.py with the
By default Collectfast will use the ``default`` cache.

**Note:** Collectfast will never clean the cache of obsolete files. To
clean out the entire cache, use ``cache.clear()``. `Read more about
Django's cache
**Note:** Collectfast will never clean the cache of obsolete files. To clean
out the entire cache, use ``cache.clear()``. `Read more about Django's cache
framework. <https://docs.djangoproject.com/en/stable/topics/cache/>`_

**Note:** We recommend you to set the ``MAX_ENTRIES`` setting if you
have more than 300 static files, see
`#47 <https://github.com/antonagestam/collectfast/issues/47>`_
**Note:** We recommend you to set the ``MAX_ENTRIES`` setting if you have more
than 300 static files, see `#47
<https://github.com/antonagestam/collectfast/issues/47>`_


Enable Parallelization
Expand Down Expand Up @@ -145,21 +153,31 @@ Install test dependencies and target Django version:
pip install -r test-requirements.txt
pip install django==2.2
Run linter and test suite:
Run test suite:

.. code:: bash
flake8
black --check .
make test
Code quality tools are broken out from test requirements because some of them
only install on Python >= 3.7.

.. code:: bash
pip install -r lint-requirements.txt
Run linters and static type check:

.. code:: bash
make lint
License
-------

Collectfast is licensed under the MIT License, see LICENSE file for more
information. Previous versions of Collectfast was licensed under Creative
Commons Attribution-ShareAlike 3.0 Unported License.
information.


.. |Build Status| image:: https://api.travis-ci.org/antonagestam/collectfast.svg?branch=master
Expand Down
1 change: 1 addition & 0 deletions collectfast/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.1.0"
42 changes: 0 additions & 42 deletions collectfast/boto.py

This file was deleted.

117 changes: 0 additions & 117 deletions collectfast/etag.py

This file was deleted.

Loading

0 comments on commit dfcc8df

Please sign in to comment.