Skip to content

Commit

Permalink
- Replace Sanic-Plugins-Framework (SPF) with Sanic-Plugin-Toolkit (SPTK)
Browse files Browse the repository at this point in the history
- Remove python 3.6 compatibility
- Remove Pre-Sanic-21.3 compatibility
  • Loading branch information
ashleysommer committed Mar 21, 2021
1 parent dbb65f0 commit 0c51057
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ pip-log.txt
.directory
venv36/
venv35/
.venv/
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
sudo: false
dist: xenial
dist: bionic
cache:
- pip
language: python
python:
- '3.6'
- '3.7'
env:
- SANIC=19.12.2 SPF=0.9.1
- SANIC=21.3.1 SPTK=1.0.0
install:
- pip install -U setuptools pep8 coverage docutils pygments aiohttp sanic==$SANIC sanic-plugins-framework==$SPF
- pip install -U setuptools pep8 coverage docutils pygments aiohttp sanic==$SANIC sanic-plugin-toolkit==$SPTK
script:
- coverage erase
- nosetests --with-coverage --cover-package=sanic_cors
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.0.0
- Replace Sanic-Plugins-Framework (SPF) with Sanic-Plugin-Toolkit (SPTK)
- Remove python 3.6 compatibility
- Remove Pre-Sanic-21.3 compatibility
- If you need to use sanic <= 21.3, use the Sanic-CORS v0.10 branch

## 0.10.0.post3
- Fixes another issue introduced with Sanic 19.12, where automatic_options cannot work when the router is run before
the Sanic-CORS middleware
Expand Down
20 changes: 12 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ credential'ed requests, and please make sure you add some sort of
`CSRF <http://en.wikipedia.org/wiki/Cross-site_request_forgery>`__
protection before doing so!

**Notice:** Please upgrade to Sanic-CORS v0.10.0 if you need compatibility with Sanic v19.12+. See `here <https://github.com/huge-success/sanic/issues/1749#issuecomment-571881532>`_ for more details.
**Notice:**
Please upgrade to Sanic-CORS v1.0.0 if you need compatibility with Sanic v21.3+ (and don't forget to replace SPF with SPTK)

**Older Notice:**
Please upgrade to Sanic-CORS v0.10.0 if you need compatibility with Sanic v19.12+. See `here <https://github.com/huge-success/sanic/issues/1749#issuecomment-571881532>`_ for more details.

Installation
------------
Expand Down Expand Up @@ -85,22 +89,22 @@ with. Simply add ``@cross_origin(app)`` below a call to Sanic's
def hello_world(request):
return text("Hello, cross-origin-world!")
SPF Usage
SPTK Usage
~~~~~~~~~~~~

Sanic-CORS uses Sanic-Plugins-Framework behind the scenes.
That means you can use SPF to load the plugin for you if you are
orchestrating and application with multiple SPF plugins.
Sanic-CORS uses Sanic-Plugin-Toolkit behind the scenes.
That means you can use the SPTK api to load the plugin for you if you are
orchestrating and application with multiple SPTK plugins.

.. code:: python
from sanic import Sanic
from sanic.response import text
from spf import SanicPluginsFramework
from sanic_plugin_toolkit import SanicPluginRealm
from sanic_cors.extension import cors
app = Sanic(__name__)
spf = SanicPluginsFramework(app)
spf.register_plugin(cors, automatic_options=True)
realm = SanicPluginRealm(app)
realm.register_plugin(cors, automatic_options=True)
@app.route("/", methods=['GET', 'OPTIONS'])
def hello_world(request):
Expand Down
12 changes: 6 additions & 6 deletions examples/app_config_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sanic import Sanic
from sanic.response import json, text
from sanic.exceptions import ServerError
from spf import SanicPluginsFramework
from sanic_plugin_toolkit import SanicPluginRealm
import logging

app = Sanic('SanicCorsAppBasedExample')
Expand All @@ -19,12 +19,12 @@
# To enable logging for sanic-cors,
logging.getLogger('sanic_cors').level = logging.DEBUG

app.config['SPF_LOAD_INI'] = True
app.config['SPF_INI_FILE'] = 'spf_cors.ini'
spf = SanicPluginsFramework(app)
app.config['SPTK_LOAD_INI'] = True
app.config['SPTK_INI_FILE'] = 'sptk_cors.ini'
realm = SanicPluginRealm(app)

# We can get the assoc object from SPF, it is already registered
assoc = spf.get_plugin_assoc('CORS')
# We can get the assoc object from SPTK, it is now already registered
assoc = realm.get_plugin_assoc('CORS')


@app.route("/")
Expand Down
4 changes: 2 additions & 2 deletions examples/blueprints_based_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def hello_world(request):

logging.basicConfig(level=logging.INFO)
app = Sanic('SanicCorsBlueprintBasedExample')
app.register_blueprint(api_v1)
app.register_blueprint(public_routes)
app.blueprint(api_v1)
app.blueprint(public_routes)


if __name__ == "__main__":
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
aiohttp>=2.3.0,<=3.2.1
sanic-testing>=0.3.0
nose
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sanic-plugins-framework>=0.9.0
sanic>=18.12.0
sanic-plugin-toolkit>=1.0.0,<2
sanic>=21.3.1,<22
2 changes: 1 addition & 1 deletion sanic_cors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Sanic-CORS is a simple extension to Sanic allowing you to support cross
origin resource sharing (CORS) using a simple decorator.
:copyright: (c) 2020 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:copyright: (c) 2021 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:license: MIT, see LICENSE for more details.
"""
from .decorator import cross_origin
Expand Down
2 changes: 1 addition & 1 deletion sanic_cors/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
~~~~
Core functionality shared between the extension and the decorator.
:copyright: (c) 2020 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:copyright: (c) 2021 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:license: MIT, see LICENSE for more details.
"""
import re
Expand Down
10 changes: 5 additions & 5 deletions sanic_cors/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
Sanic route with. It accepts all parameters and options as
the CORS extension.
:copyright: (c) 2020 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:copyright: (c) 2021 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:license: MIT, see LICENSE for more details.
"""

from spf import SanicPluginsFramework
from sanic_plugin_toolkit import SanicPluginRealm
from .core import *
from .extension import cors

Expand Down Expand Up @@ -105,14 +105,14 @@ def cross_origin(app, *args, **kwargs):
_real_decorator = cors.decorate(app, *args, run_middleware=False, with_context=False, **kwargs)

def wrapped_decorator(f):
spf = SanicPluginsFramework(app) # get the singleton from the app
realm = SanicPluginRealm(app) # get the singleton from the app
try:
plugin = spf.register_plugin(cors, skip_reg=True)
plugin = realm.register_plugin(cors, skip_reg=True)
except ValueError as e:
# this is normal, if this plugin has been registered previously
assert e.args and len(e.args) > 1
plugin = e.args[1]
context = cors.get_context_from_spf(spf)
context = cors.get_context_from_realm(realm)
log = context.log
log(logging.DEBUG, "Enabled {:s} for cross_origin using options: {}".format(str(f), str(_options)))
return _real_decorator(f)
Expand Down
4 changes: 2 additions & 2 deletions sanic_cors/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Sanic-CORS is a simple extension to Sanic allowing you to support cross
origin resource sharing (CORS) using a simple decorator.
:copyright: (c) 2020 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:copyright: (c) 2021 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:license: MIT, see LICENSE for more details.
"""
from asyncio import iscoroutinefunction
Expand All @@ -15,7 +15,7 @@
from sanic import exceptions, response, __version__ as sanic_version
from sanic.exceptions import MethodNotSupported, NotFound
from sanic.handlers import ErrorHandler
from spf import SanicPlugin
from sanic_plugin_toolkit import SanicPlugin
from .core import *
from distutils.version import LooseVersion
import logging
Expand Down
2 changes: 1 addition & 1 deletion sanic_cors/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.10.0.post3'
__version__ = '1.0.0'
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Sanic-CORS is a simple extension to Sanic allowing you to support cross
origin resource sharing (CORS) using a simple decorator.
:copyright: (c) 2020 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:copyright: (c) 2021 by Ashley Sommer (based on flask-cors by Cory Dolphin).
:license: MIT, see LICENSE for more details.
"""

Expand Down Expand Up @@ -48,9 +48,9 @@
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
Expand Down

0 comments on commit 0c51057

Please sign in to comment.