diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 895ad48..b8ab3b2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,36 +1,91 @@ name: Unit tests on: - push: - branches: [ master ] pull_request: - branches: [ master ] + push: + branches: + - master + tags: + - "v*" jobs: - build: + test: + runs-on: ubuntu-latest strategy: fail-fast: false matrix: python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, pypy2, pypy3] + + name: Python ${{ matrix.python-version }} + steps: + - uses: actions/checkout@v2 + - name: Get history and tags for SCM versioning to work + run: | + git fetch --prune --unshallow + git fetch --depth=1 origin +refs/tags/*:refs/tags/* + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox + - name: Test with tox + run: tox -e py + + dist: runs-on: ubuntu-latest + needs: [test] + name: Build Python packages + steps: + - uses: actions/checkout@v2 + - name: Get history and tags for SCM versioning to work + run: | + git fetch --prune --unshallow + git fetch --depth=1 origin +refs/tags/*:refs/tags/* + - uses: actions/setup-python@v2 + with: + python-version: "3.8" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade wheel setuptools build + - name: Build package + run: python -m build -s -w -o dist/ + - uses: actions/upload-artifact@v2 + with: + name: dist + path: dist + dist_check: + runs-on: ubuntu-latest + needs: [dist] + name: Twine check + steps: + - uses: actions/setup-python@v2 + with: + python-version: "3.8" + - name: Install dependencies + run: pip install twine + - uses: actions/download-artifact@v2 + with: + name: dist + path: dist + - run: twine check dist/* + + dist_upload: + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') + needs: [dist_check] + name: PyPI upload steps: - - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" - uses: actions/checkout@v2 - - name: Set up Python - ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install tox -r requirements.txt; - - name: Test with pytest - env: - PYTHON_VERSION: ${{ matrix.python-version }} - run: | - # Remove . from python version - ENV_NAME="${PYTHON_VERSION/./}" - # Add "py" suffix for plain python version - [[ ${ENV_NAME} =~ ^[0-9]+$ ]] && ENV_NAME="py${ENV_NAME}" - tox -e "${ENV_NAME}" + - uses: actions/download-artifact@v2 + with: + name: dist + path: dist + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@master + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.gitignore b/.gitignore index 77a95a1..a57a25f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ venv* /.tox /.cache /.pytest_cache +# Generated by setuptools_scm +flask_compress/_version.py diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e3b00..89a2baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to `flask-compress` will be documented in this file. +## 1.10.0 (2021-06-15) + +- Automate the release process with GitHub Actions +- Use `setuptools_scm` to manage package versions +- The layout is now an actual package rather than a single module +- Clean up unused files + ## 1.9.0 (2021-02-12) - Add support for the `identity` value in *accept-encoding*, fixes [#19](https://github.com/colour-science/flask-compress/issues/19) diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index f5458f8..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,4 +0,0 @@ -include LICENSE.txt -include README.md -recursive-include tests * -recursive-exclude tests *.pyc diff --git a/README.md b/README.md index 59570fb..a671e21 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ # Flask-Compress +[](https://github.com/colour-science/flask-compress/actions/workflows/ci.yaml) [](https://pypi.python.org/pypi/Flask-Compress) -[](https://travis-ci.org/libwilliam/flask-compress) -[](https://coveralls.io/github/libwilliam/flask-compress) -[](https://github.com/libwilliam/flask-compress/blob/master/LICENSE.txt) +[](https://pypi.python.org/pypi/Flask-Compress) -Flask-Compress allows you to easily compress your [Flask](http://flask.pocoo.org/) application's responses with gzip, deflate or brotli. +Flask-Compress allows you to easily compress your [Flask](http://flask.pocoo.org/) application's responses with gzip, deflate or brotli. It originally started as a fork of [Flask-gzip](https://github.com/closeio/Flask-gzip). The preferred solution is to have a server (like [Nginx](http://wiki.nginx.org/Main)) automatically compress the static files for you. If you don't have that option Flask-Compress will solve the problem for you. diff --git a/flask_compress/__init__.py b/flask_compress/__init__.py new file mode 100644 index 0000000..0a643ec --- /dev/null +++ b/flask_compress/__init__.py @@ -0,0 +1,9 @@ +from .flask_compress import Compress + +# _version.py is generated by setuptools_scm when building the package, it is not versioned. +# If missing, this means that the imported code was most likely the git repository, that was +# installed without the "editable" mode. +try: + from ._version import __version__ +except ImportError: + __version__ = "0" diff --git a/flask_compress.py b/flask_compress/flask_compress.py similarity index 100% rename from flask_compress.py rename to flask_compress/flask_compress.py diff --git a/index.html b/index.html deleted file mode 100644 index a8212cf..0000000 --- a/index.html +++ /dev/null @@ -1,132 +0,0 @@ - - -
- - -Compress responses in your Flask app with gzip.
- - - - - -Flask-Compress allows you to easily compress your Flask application's responses with gzip.
- -The preferred solution is to have a server (like Nginx) automatically compress the static files for you. If you don't have that option Flask-Compress will solve the problem for you.
- -Flask-Compress both adds the various headers required for a compressed response and gzips the response data. This makes serving gzip compressed static files extremely easy.
- -Internally, every time a request is made the extension will check if it matches one of the compressible MIME types and will automatically attach the appropriate headers.
- -If you use pip then installation is simply:
- -$ pip install flask-compress
or, if you want the latest github version:
- -$ pip install git+git://github.com/libwilliam/flask-compress.git
You can also install Flask-Compress via Easy Install:
- -$ easy_install flask-compress
Flask-Compress is incredibly simple to use. In order to start gzip'ing your Flask application's assets, the first thing to do is let Flask-Compress know about your flask.Flask
application object.
from flask import Flask
-from flask_compress import Compress
-
-app = Flask(__name__)
-Compress(app)
In many cases, however, one cannot expect a Flask instance to be ready at import time, and a common pattern is to return a Flask instance from within a function only after other configuration details have been taken care of. In these cases, Flask-Compress provides a simple function, flask_compress.Compress.init_app
, which takes your application as an argument.
from flask import Flask
-from flask_compress import Compress
-
-compress = Compress()
-
-def start_app():
- app = Flask(__name__)
- compress.init_app(app)
- return app
In terms of automatically compressing your assets using gzip, passing your flask.Flask
object to the flask_compress.Compress
object is all that needs to be done.
Within your Flask application's settings you can provide the following settings to control the behavior of Flask-Compress. None of the settings are required.
- -Option | -Description | -Default | -
---|---|---|
COMPRESS_MIMETYPES |
-Set the list of mimetypes to compress here. | -
-[ 'text/html', 'text/css', 'text/xml', 'application/json', 'application/javascript' ]
- |
-
COMPRESS_LEVEL |
-Specifies the gzip compression level. | -6 |
-
COMPRESS_MIN_SIZE |
-Specifies the minimum file size threshold for compressing files. | -500 |
-