Skip to content

Commit

Permalink
PLT-520 update GH actions, python support (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
lolasov authored Jun 23, 2021
1 parent af247c6 commit efa4183
Show file tree
Hide file tree
Showing 23 changed files with 402 additions and 234 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test

on: push

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Setup chromedriver
uses: nanasess/[email protected]

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: |
tox -- -v --selenosis-driver=chrome-headless || \
tox -- -v --selenosis-driver=chrome-headless || \
tox -- -v --selenosis-driver=chrome-headless
47 changes: 0 additions & 47 deletions .travis.yml

This file was deleted.

116 changes: 113 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,125 @@ fields that use the `Select2 javascript
plugin <http://ivaynberg.github.com/select2/>`_. It was created by
developers at `The Atlantic <http://www.theatlantic.com/>`_.

.. contents:: Table of Contents:

Support
=======

Being that Django added select2 support in 2.0, we will support up to that version
for compatibility purposes.

* ~=v2.0.2: Python ~=2.7,~=3.6 | Django >=1.8,<2.1
* ~=v2.1: Python ~=2.7,>=3.6,<3.8 | Django >=1.11,<2.1
* ~=v3.0: __Python >=3.6,<3.9 | Django >=2.0,<2.1 (future release)__
* ~=v3.0: Python >=3.7,<3.9 | Django 2.2,3.1,3.2 (current release)

Local Development & Testing
===========================

The following steps should only need to be done once when you first begin:

Install ``pyenv``
-----------------

These instructions assume that you have `Homebrew <https://brew.sh/>`_ installed,
but not ``pyenv``.

.. code:: bash
brew install pyenv
touch ~/.bash_profile
Add the following line to your ``~/bash_profile`` or ``.zshrc``::

eval "$(pyenv init -)"

Reload your shell:

.. code:: bash
. ~/.bash_profile
or

.. code:: bash
. ~/.zshrc
Python Repository Setup
-----------------------

First, clone the repository and prep your Python environment:

.. code:: bash
git clone https://github.com/theatlantic/django-select2-forms.git
pyenv install 3.7.2
pyenv install 3.8.0
pyenv install 3.9.0
pyenv local 3.7.2 3.8.0 3.9.0
python -V
The output of the previous command should be ``Python 3.7.2``.

Finally:

.. code:: bash
python -m venv venv
Activate Your Environment
-------------------------

From the base directory:

.. code:: bash
deactivate # ignore: -bash: deactivate: command not found
. venv/bin/activate
pip install -U tox
Running tests
-------------

If you have not already done so, set up your environment by chromedriver:

.. code:: bash
brew install --cask chromedriver
Run all tests:

.. code:: bash
tox -- --selenosis-driver=chrome-headless
Show all available ``tox`` commands:

.. code:: bash
tox -av
Run only a specific environment:

.. code:: bash
tox -e <environment-name> -- --selenosis-driver=chrome-headless # example: tox -e py37-django22
Only run a specific test:

.. code:: bash
tox -- pytest -k test_something --selenosis-driver=chrome-headless
Run an arbitrary command in a specific environment:

.. code:: bash
tox -e py37-django22 -- python # runs the Python REPL in that environment
Setup a development environment:

.. code:: bash
tox -e <pyXX-DjangoYY> --develop -r
. .tox/<pyXX-DjangoYY>/bin/activate
Installation
============
Expand Down
20 changes: 0 additions & 20 deletions runtests.py

This file was deleted.

20 changes: 9 additions & 11 deletions select2/fields.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import django
from django import forms
from django.db import models
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.db.models.fields import FieldDoesNotExist
from django.core.exceptions import ImproperlyConfigured, ValidationError, FieldDoesNotExist
from django.forms.models import ModelChoiceIterator
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from django.utils.functional import Promise
from django.utils import six
try:
from django.db.models.fields.related import lazy_related_operation
except ImportError:
Expand Down Expand Up @@ -172,7 +170,7 @@ def clean(self, value):
elif not self.required and not value:
return []

if isinstance(value, six.string_types):
if isinstance(value, str):
value = value.split(',')

if not isinstance(value, (list, tuple)):
Expand All @@ -188,14 +186,14 @@ def clean(self, value):
qs = self.queryset.filter(**{
('%s__in' % key): value,
})
pks = set([force_text(getattr(o, key)) for o in qs])
pks = set([force_str(getattr(o, key)) for o in qs])

# Create a dictionary for storing the original order of the items
# passed from the form
pk_positions = {}

for i, val in enumerate(value):
pk = force_text(val)
pk = force_str(val)
if pk not in pks:
raise ValidationError(self.error_messages['invalid_choice'] % val)
pk_positions[pk] = i
Expand All @@ -209,7 +207,7 @@ def clean(self, value):
sort_value_field_name = self.sort_field.name
objs = []
for i, obj in enumerate(qs):
pk = force_text(getattr(obj, key))
pk = force_str(getattr(obj, key))
setattr(obj, sort_value_field_name, pk_positions[pk])
objs.append(obj)
return sorted(objs, key=lambda obj: getattr(obj, sort_value_field_name))
Expand Down Expand Up @@ -273,15 +271,15 @@ def contribute_to_related_class(self, cls, related):
'field_name': self.name,
'app_label': self.model._meta.app_label,
'object_name': self.model._meta.object_name})
if not callable(self.search_field) and not isinstance(self.search_field, six.string_types):
if not callable(self.search_field) and not isinstance(self.search_field, str):
raise TypeError(
("keyword argument 'search_field' must be either callable or "
"string on field '%(field_name)s' of model "
"%(app_label)s.%(object_name)s") % {
'field_name': self.name,
'app_label': self.model._meta.app_label,
'object_name': self.model._meta.object_name})
if isinstance(self.search_field, six.string_types):
if isinstance(self.search_field, str):
try:
opts = related.parent_model._meta
except AttributeError:
Expand Down Expand Up @@ -354,7 +352,7 @@ def contribute_to_class(self, cls, name):
def resolve_sort_field(field, model, cls):
model._sort_field_name = field.sort_value_field_name
field.sort_field = model._meta.get_field(field.sort_value_field_name)
if isinstance(compat_rel(self).through, six.string_types):
if isinstance(compat_rel(self).through, str):
compat_add_lazy_relation(cls, self, compat_rel(self).through, resolve_sort_field)
else:
resolve_sort_field(self, compat_rel(self).through, cls)
3 changes: 1 addition & 2 deletions select2/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys

from django.db import models
from django.utils import six
from django.apps import apps
from django.db.models.base import ModelBase
from django.utils.functional import SimpleLazyObject
Expand Down Expand Up @@ -68,7 +67,7 @@ def _get_model():
return super_new(cls, name, bases, attrs)


class SortableThroughModel(six.with_metaclass(SortableThroughModelBase, models.Model)):
class SortableThroughModel(models.Model, metaclass=SortableThroughModelBase):

class Meta:
abstract = True
39 changes: 0 additions & 39 deletions select2/tests/fixtures/select2-test-data.xml

This file was deleted.

22 changes: 0 additions & 22 deletions select2/tests/settings.py

This file was deleted.

Loading

0 comments on commit efa4183

Please sign in to comment.