Skip to content

Commit

Permalink
[chores] Updated CI configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Aug 13, 2024
1 parent dcd67a2 commit b4cef3c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 38 deletions.
22 changes: 14 additions & 8 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ Changelog
Verson 1.3.0 [2021-11-29]
-------------------------

- [change] Allow possibility to point swappable dependency to specific migration number
(instead of only to ``__latest__``)
- [change] Allow possibility to point swappable dependency to specific
migration number (instead of only to ``__latest__``)

Version 1.2.0 [2021-11-12]
--------------------------

- [feature] Add possibility to point swappable dependency to ``__latest__``
- [feature] Add possibility to point swappable dependency to
``__latest__``
- [change] Added support for Python 3.9
- [change] Added support for Django 3.2 and Django 4.0a1
- [change] Dropped support for old Django versions (<2.2)
- [change] Dropped support for old Python versions (<3.7)
- [feature] Added optional ``require_ready`` argument to ``load_model`` function
- [feature] Added optional ``require_ready`` argument to ``load_model``
function

Version 1.1.2 [2020-01-15]
--------------------------
Expand All @@ -34,27 +36,31 @@ Version 1.1.0 [2017-05-11]
--------------------------

- [test] Added tests for swapper.split
- `#13 <https://github.com/openwisp/django-swappable-models/pull/13>`_ [fix] Handle contrib apps and apps with dot in app_label.
- `#13 <https://github.com/openwisp/django-swappable-models/pull/13>`_
[fix] Handle contrib apps and apps with dot in app_label.

Version 1.0.0 [2016-08-26]
--------------------------

- [docs] Improved usuability docs
- `86e238 <https://github.com/openwisp/django-swappable-models/commit/86e238>`_:
- `86e238
<https://github.com/openwisp/django-swappable-models/commit/86e238>`_:
[deps] Compatibility with django 1.10 added

Version 0.3.0 [2015-11-17]
--------------------------

- `#9 <https://github.com/openwisp/django-swappable-models/pull/9>`_ [deps] Added support for django 1.9
- `#9 <https://github.com/openwisp/django-swappable-models/pull/9>`_
[deps] Added support for django 1.9

Version 0.2.2 [2015-06-16]
--------------------------

- [deps] Added support for django~=1.6.0
- [deps] Added support for Python 3.3
- [docs] Fix model reference in README
- [docs] Notes for load_model initialization (`for more info see #2 <https://github.com/openwisp/django-swappable-models/issues/2>`_)
- [docs] Notes for load_model initialization (`for more info see #2
<https://github.com/openwisp/django-swappable-models/issues/2>`_)

Version 0.2.1 [2014-11-18]
--------------------------
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def readme():
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.110',
'Framework :: Django',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
Expand All @@ -43,6 +43,8 @@ def readme():
'Framework :: Django :: 3.1',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.0',
'Framework :: Django :: 4.1',
'Framework :: Django :: 4.2',
],
tests_require=['django>=2.0'],
test_suite='tests',
Expand Down
31 changes: 7 additions & 24 deletions swapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@


def swappable_setting(app_label, model):
"""
Returns the setting name to use for the given model (i.e. AUTH_USER_MODEL)
"""
"""Returns the setting name to use for the given model (i.e. AUTH_USER_MODEL)"""
prefix = _prefixes.get(app_label, app_label)
setting = "{prefix}_{model}_MODEL".format(
prefix=prefix.upper(), model=model.upper()
Expand All @@ -23,10 +21,7 @@ def swappable_setting(app_label, model):


def is_swapped(app_label, model):
"""
Returns the value of the swapped setting, or False if the model hasn't
been swapped.
"""
"""Returns the value of the swapped setting, or False if the model hasn't been swapped."""
default_model = join(app_label, model)
setting = swappable_setting(app_label, model)
value = getattr(settings, setting, default_model)
Expand All @@ -37,35 +32,25 @@ def is_swapped(app_label, model):


def get_model_name(app_label, model):
"""
Returns [app_label.model] unless the model has been swapped, in which case
returns the swappable setting value.
"""
"""Returns [app_label.model] unless the model has been swapped, in which case returns the swappable setting value."""
return is_swapped(app_label, model) or join(app_label, model)


def dependency(app_label, model, version=None):
"""
Returns a Django 1.7+ style dependency tuple for inclusion in
migration.dependencies[]
"""
"""Returns a Django 1.7+ style dependency tuple for inclusion in migration.dependencies[]"""
dependencies = swappable_dependency(get_model_name(app_label, model))
if not version:
return dependencies
return dependencies[0], version


def get_model_names(app_label, models):
"""
Map model names to their swapped equivalents for the given app
"""
"""Map model names to their swapped equivalents for the given app"""
return dict((model, get_model_name(app_label, model)) for model in models)


def load_model(app_label, model, required=True, require_ready=True):
"""
Load the specified model class, or the class it was swapped out for.
"""
"""Load the specified model class, or the class it was swapped out for."""
swapped = is_swapped(app_label, model)
if swapped:
app_label, model = split(swapped)
Expand All @@ -83,9 +68,7 @@ def load_model(app_label, model, required=True, require_ready=True):


def set_app_prefix(app_label, prefix):
"""
Set a custom prefix to use for the given app (e.g. WQ)
"""
"""Set a custom prefix to use for the given app (e.g. WQ)"""
_prefixes[app_label] = prefix


Expand Down
1 change: 0 additions & 1 deletion tests/test_swapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


class SwapperTestCase(TestCase):

# Tests that should work whether or not default_app.Type is swapped
def test_fields(self):
Type = swapper.load_model('default_app', 'Type')
Expand Down
12 changes: 8 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ envlist =
py{37,38}-django22-{noswap,swap}
py{37,38}-django30-{noswap,swap}
py{37,38,39}-django31-{noswap,swap}
py{37,38,39}-django32-{noswap,swap}
py{38,39}-django40-{noswap, swap}
py{37,38,39,310}-django32-{noswap,swap}
py{38,39,310}-django40-{noswap, swap}
py{38,39,310}-django41-{noswap, swap}
py{38,39,310}-django42-{noswap, swap}
lint

[gh-actions]
python =
3.7: py37
3.8: py38, lint
3.9: py39, lint
3.10: py310, lint

[testenv]
commands =
Expand All @@ -22,7 +24,9 @@ deps =
django30: django~=3.0.0
django31: django~=3.1.0
django32: django~=3.2.0
django40: django~=4.0a1
django40: django~=4.0.0
django41: django~=4.1.0
django42: django~=4.2.0
setenv =
noswap: DJANGO_SETTINGS_MODULE=tests.settings
swap: DJANGO_SETTINGS_MODULE=tests.swap_settings
Expand Down

0 comments on commit b4cef3c

Please sign in to comment.