diff --git a/.coveragerc b/.coveragerc index 6fc8341..32e19da 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,3 +2,4 @@ source = reverse_unique branch = 1 omit = reverse_unique/test* +relative_files = 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ffb240d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,58 @@ +name: Test + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 5 + matrix: + python-version: ['3.6', '3.7', '3.8', '3.9', '3.10'] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Get pip cache dir + id: pip-cache + run: | + echo "::set-output name=dir::$(pip cache dir)" + + - name: Cache + uses: actions/cache@v2 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: + ${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/tox.ini') }} + restore-keys: | + ${{ matrix.python-version }}-v1- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade tox tox-gh-actions + + - name: Tox tests + run: | + tox -v + + - name: Coveralls + uses: AndreMiras/coveralls-python-action@develop + with: + parallel: true + flag-name: Unit Test + + coveralls_finish: + needs: test + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: AndreMiras/coveralls-python-action@develop + with: + parallel-finished: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d6de513..0000000 --- a/.travis.yml +++ /dev/null @@ -1,47 +0,0 @@ -sudo: no - -language: python - -env: - - TOXENV=flake8 - -matrix: - fast_finish: true - include: - - python: 2.7 - env: TOXENV=py27-1.8 - - python: 2.7 - env: TOXENV=py27-1.9 - - python: 2.7 - env: TOXENV=py27-1.10 - - python: 2.7 - env: TOXENV=py27-1.11 - - - python: 3.4 - env: TOXENV=py34-1.8 - - python: 3.4 - env: TOXENV=py34-1.9 - - python: 3.4 - env: TOXENV=py34-1.10 - - python: 3.4 - env: TOXENV=py34-1.11 - - - python: 3.5 - env: TOXENV=py35-1.8 - - python: 3.5 - env: TOXENV=py35-1.9 - - python: 3.5 - env: TOXENV=py35-1.10 - - python: 3.5 - env: TOXENV=py35-1.11 - - - python: 3.6 - env: TOXENV=py36-1.11 - -install: - pip install tox coveralls - -script: - tox - -after_success: coveralls diff --git a/README.rst b/README.rst index 4553ca3..c888430 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ django-reverse-unique ===================== -.. image:: https://travis-ci.org/akaariai/django-reverse-unique.svg?branch=master - :target: https://travis-ci.org/akaariai/django-reverse-unique +.. image:: https://github.com/akaariai/django-reverse-unique/workflows/Test/badge.svg + :target: https://github.com/akaariai/django-reverse-unique/actions :alt: Build Status .. image:: https://coveralls.io/repos/akaariai/django-reverse-unique/badge.svg?branch=master diff --git a/reverse_unique/fields.py b/reverse_unique/fields.py index c95ed0b..f8cd76f 100644 --- a/reverse_unique/fields.py +++ b/reverse_unique/fields.py @@ -128,7 +128,7 @@ def get_filters(self): else: return self.filters - def get_extra_restriction(self, where_class, alias, related_alias): + def _get_extra_restriction(self, alias, related_alias): remote_model = get_remote_field_model(self) qs = remote_model.objects.filter(self.get_filters()).query my_table = self.model._meta.db_table @@ -141,11 +141,17 @@ def get_extra_restriction(self, where_class, alias, related_alias): where.relabel_aliases({my_table: related_alias, rel_table: alias}) return where + if django.VERSION[0] >= 4: + get_extra_restriction = _get_extra_restriction + else: + def get_extra_restriction(self, where_class, alias, related_alias): + return self._get_extra_restriction(alias, related_alias) + def get_extra_descriptor_filter(self, instance): return self.get_filters() - def get_path_info(self, filtered_relation): - ret = super(ReverseUnique, self).get_path_info(filtered_relation) + def get_path_info(self, *args, **kwargs): + ret = super(ReverseUnique, self).get_path_info(*args, **kwargs) assert len(ret) == 1 return [ret[0]._replace(direct=False)] diff --git a/tox.ini b/tox.ini index 166c7db..79c991f 100644 --- a/tox.ini +++ b/tox.ini @@ -2,26 +2,36 @@ args_are_paths = false envlist = flake8, - py39-{2.0,2.1,2.2,3.0,3.1,3.2}, - py310-{3.0,3.1,3.2} + py36-3.2, + py37-3.2, + py38-{3.2,4.0,4.1,main}, + py39-{3.2,4.0,4.1,main}, + py310-{3.2,4.0,4.1,main}, + +[gh-actions] +python = + 3.6: py36, flake8, isort + 3.7: py37 + 3.8: py38 + 3.9: py39 + 3.10: py310 [testenv] usedevelop = true commands = - python -R -Wonce {envbindir}/coverage run {envbindir}/django-admin.py test -v2 --settings=reverse_unique_tests.settings {posargs} + {envpython} -R -Wonce {envbindir}/coverage run -a -m django test -v2 --settings=reverse_unique_tests.settings {posargs} coverage report deps = coverage - 2.0: Django>=2.0,<2.1 - 2.1: Django>=2.1,<2.2 - 2.2: Django>=2.2,<3.0 - 3.0: Django>=3.0,<3.1 - 3.1: Django>=3.1,<3.2 3.2: Django>=3.2,<4.0 4.0: Django>=4.0,<4.1 + 4.1: Django>=4.1,<4.2 + main: https://github.com/django/django/archive/main.tar.gz +passenv = + GITHUB_* [testenv:flake8] -basepython = python3.9 +basepython = python3.6 commands = flake8 reverse_unique deps =