Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 48 additions & 16 deletions .github/workflows/tests_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,31 @@ jobs:
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: '3.11'
python-version: '3.12'

- name: Install packages
run: pip install -r develop_requirements.txt
run: pip install -r requirements_dev.txt

- name: Black
run: |
black --check -l 120 django_opensearch_dsl tests
black --check -l 120 django_opensearch_dsl/ tests/

isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@master
with:
python-version: '3.12'

- name: Install packages
run: pip install -r requirements_dev.txt

- name: Isort
run: |
isort --check django_opensearch_dsl/ tests/

pycodestyle:
runs-on: ubuntu-latest
Expand All @@ -41,14 +58,14 @@ jobs:
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: '3.11'
python-version: '3.12'

- name: Install packages
run: pip install -r develop_requirements.txt
run: pip install -r requirements_dev.txt

- name: Pycodestyle
run: |
pycodestyle django_opensearch_dsl tests
pycodestyle django_opensearch_dsl/ tests/

pydocstyle:
runs-on: ubuntu-latest
Expand All @@ -58,29 +75,44 @@ jobs:
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: '3.11'
python-version: '3.12'

- name: Install packages
run: pip install -r develop_requirements.txt
run: pip install -r requirements_dev.txt

- name: Pydocstyle
run: |
pydocstyle --count django_opensearch_dsl tests
pydocstyle --count django_opensearch_dsl/ tests/

bandit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@master
with:
python-version: '3.12'

- name: Install packages
run: pip install -r requirements_dev.txt

- name: Bandit
run: |
bandit --ini=setup.cfg -ll 2> /dev/null


test:
needs: [black, pycodestyle, pydocstyle]
needs: [black, isort, pycodestyle, pydocstyle, bandit]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9, '3.10', '3.11']
django-version: [ 32, 40, 41 ]
python-version: [ 3.9, '3.10', '3.11', '3.12']
django-version: [ 32, 42, 50 ]
opensearch-version: [ 10, 20 ]
exclude:
- python-version: 3.7
django-version: 40
- python-version: 3.7
django-version: 41
- python-version: 3.9
django-version: 50

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Ready to contribute? Here's how to set up `django-opensearch-dsl` for local deve
```bash
python3 -m venv venv
source venv/bin/activate
pip3 install -r develop_requirements.txt
pip3 install -r requirements.txt
pip3 install -r requirements_dev.txt
```

4. Create a branch for local development:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Django Opensearch DSL
[![PyPI Version](https://badge.fury.io/py/django-opensearch-dsl.svg)](https://badge.fury.io/py/django-opensearch-dsl)
[![Documentation Status](https://readthedocs.org/projects/django-opensearch-dsl/badge/?version=latest)](https://django-opensearch-dsl.readthedocs.io/en/latest/?badge=latest)
![Tests](https://github.com/Codoc-os/django-opensearch-dsl/workflows/Tests/badge.svg)
[![Python 3.7+](https://img.shields.io/badge/Python-3.7+-brightgreen.svg)](#)
[![Python 3.9+](https://img.shields.io/badge/Python-3.9+-brightgreen.svg)](#)
[![Django 3.2+](https://img.shields.io/badge/Django-3.2+-brightgreen.svg)](#)
[![OpenSearch 1.3+, 2.7+](https://img.shields.io/badge/OpenSearch-1.3+-brightgreen.svg)](#)
[![License Apache 2](https://img.shields.io/badge/license-Apache%202-brightgreen.svg)](https://github.com/Codoc-os/django-opensearch-dsl/blob/master/LICENSE)
Expand Down
50 changes: 45 additions & 5 deletions bin/pre_commit.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
#!/bin/bash

BASE_PATH="$(dirname "$0")"

source "$BASE_PATH/colors.sh"

EXIT_CODE=0


################################################################################
# ISORT #
################################################################################
echo -n "${Cyan}Formatting import with isort... $Color_Off"
out=$(isort django_opensearch_dsl/ tests/)
if [ ! -z "$out" ] ; then
echo ""
echo -e "$out"
fi
echo "${Green}Ok ✅ $Color_Off"
echo ""

################################################################################
# BLACK #
################################################################################
echo "${Cyan}Formatting code with black...$Color_Off"
black -l 120 django_opensearch_dsl tests
black -l 120 django_opensearch_dsl/ tests/
echo ""


################################################################################
# PYCODESTYLE #
################################################################################
echo -n "${Cyan}Running pycodestyle... $Color_Off"
out=$(pycodestyle django_opensearch_dsl tests)
if [ "$?" -ne 0 ] ; then
Expand All @@ -22,9 +40,27 @@ fi
echo ""


################################################################################
# PYDOCSTYLE #
################################################################################
echo -n "${Cyan}Running pydocstyle... $Color_Off"
out=$(pydocstyle --count django_opensearch_dsl tests)
if [ "${PIPESTATUS[0]}" -ne 0 ] ; then
out=$(pydocstyle --count django_opensearch_dsl/ tests/)
if [ "$?" -ne 0 ] ; then
echo "${Red}Error !$Color_Off"
echo -e "$out"
EXIT_CODE=1
else
echo "${Green}Ok ✅ $Color_Off"
fi
echo ""


################################################################################
# BANDIT #
################################################################################
echo -n "${Cyan}Running bandit... $Color_Off"
out=$(bandit --ini=setup.cfg -ll 2> /dev/null)
if [ "$?" -ne 0 ] ; then
echo "${Red}Error !$Color_Off"
echo -e "$out"
EXIT_CODE=1
Expand All @@ -34,6 +70,10 @@ fi
echo ""



################################################################################


if [ $EXIT_CODE = 1 ] ; then
echo "${Red}⚠ You must fix the errors before committing ⚠$Color_Off"
exit $EXIT_CODE
Expand Down
8 changes: 0 additions & 8 deletions develop_requirements.txt

This file was deleted.

1 change: 0 additions & 1 deletion django_opensearch_dsl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import django

from django.utils.module_loading import autodiscover_modules

from .documents import Document # noqa
Expand Down
1 change: 0 additions & 1 deletion django_opensearch_dsl/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.apps import AppConfig
from django.conf import settings
from django.utils.module_loading import import_string

from opensearchpy.connection.connections import connections


Expand Down
8 changes: 4 additions & 4 deletions django_opensearch_dsl/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import time
from collections import deque
from functools import partial
from typing import Optional, Iterable
from typing import Iterable, Optional

from django.db import models
from django.db.models import QuerySet, Q
from opensearchpy.helpers.document import Document as DSLDocument
from django.db.models import Q, QuerySet
from opensearchpy.helpers import bulk, parallel_bulk
from opensearchpy.helpers.document import Document as DSLDocument

from . import fields
from .apps import DODConfig
Expand Down Expand Up @@ -210,7 +210,7 @@ def _get_actions(self, object_list, action):
yield self._prepare_action(object_instance, action)

def _bulk(self, *args, parallel=False, using=None, **kwargs):
"""Helper for switching between normal and parallel bulk operation."""
"""Allow switching between normal and parallel bulk operation."""
if parallel:
return self.parallel_bulk(*args, using=using, **kwargs)
return self.bulk(*args, using=using, **kwargs)
Expand Down
1 change: 1 addition & 0 deletions django_opensearch_dsl/management/commands/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.db.models import Q

from django_opensearch_dsl.registries import registry

from ..enums import OpensearchAction
from ..types import parse

Expand Down
4 changes: 2 additions & 2 deletions django_opensearch_dsl/management/types.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import datetime
from typing import Union, List
from typing import List, Union

from dateutil.parser import isoparse
from django.conf import settings
from django.utils.timezone import make_aware, is_aware
from django.utils.timezone import is_aware, make_aware

Nothing = type(Ellipsis)
Values = Union[None, int, float, datetime.datetime, str, List["Values"]]
Expand Down
3 changes: 1 addition & 2 deletions django_opensearch_dsl/registries.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from collections import defaultdict
from copy import deepcopy

from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ImproperlyConfigured
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from opensearchpy.helpers.utils import AttrDict

from .apps import DODConfig
Expand Down
3 changes: 1 addition & 2 deletions django_opensearch_dsl/search.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.db.models import Case, When
from django.db.models.fields import IntegerField

from opensearchpy.helpers.search import Search as DSLSearch
from opensearchpy.connection.connections import connections
from opensearchpy.helpers.search import Search as DSLSearch


class Search(DSLSearch):
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mkdocs~=1.3.0
jinja2<3.1.0
mkdocs~=1.5.3
jinja2~=3.1.3
11 changes: 11 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bandit>=1.7.7, <2.0.0
black>=24.1.1, <25.0.0
coverage>=7.4.4, <8.0.0
flake8>=7.0.0, <8.0.0
isort>=5.13.0, <6.0.0
mkdocs>=1.5.3, <2.0.0
mypy>=1.7.1, <2.0.0
pydocstyle>=6.3.0, <7.0.0
pytest>=8.0.0, <9.0.0
pytest-django>=4.8.0, <5.0.0
tox>=4.13.0, <5.0.0
56 changes: 38 additions & 18 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
########################
[tox:tox]
distshare = {homedir}/.tox/distshare
envlist = py{37,38,39,310,311}-django{32,40,41}-opensearch{10,20}
envlist = py{39,310,311,312}-django{32,42,50}-opensearch{10,20}
skipsdist = true
skip_missing_interpreters = true
indexserver =
Expand All @@ -17,41 +17,61 @@ setenv =
opensearch20: DJANGO_OS_PORT=9220
deps =
-rrequirements.txt
-rrequirements_dev.txt
django32: django>=3.2.0,<3.3.0
django40: django>=4.0.0,<4.1.0
django41: django>=4.1.0,<4.2.0
django42: django>=4.2.0,<4.3.0
django50: django>=5.0.0,<5.1.0
opensearch10: opensearch-py>=2.2.0
opensearch20: opensearch-py>=2.2.0
pycodestyle
pydocstyle
pytest-cov

commands =
pycodestyle django_opensearch_dsl
-pydocstyle --count django_opensearch_dsl
python3 manage.py migrate
coverage run --source=. manage.py test
coverage report -m
coverage xml


####################################
##### PEP 8 & PEP 257 settings #####
####################################
########################
### Checks settings ####
########################
[pycodestyle]
# https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
ignore = W503, W504, E123, E126, E121, W605, W293, E203, E501
count = True
max-line-length = 120
max-doc-length = 100
exclude = venv, .tox
ignore = W503, W504, W605, E121, E123, E126, E203, E501
# W503: Line break occurred before a binary operator
# W504: Line break occurred after a binary operator
# W605: Invalid escape sequence
# E121: Continuation line under-indented for hanging indent
# E123: Closing bracket does not match indentation of opening bracket's line
# E126: Continuation line over-indented for hanging indent
# E203: Whitespace before ':'
# E501: Line too long

[pydocstyle]
convention = numpy
match_dir = (?!django_dummy_app|project|\.).*
add_ignore = D100, D104, D106, D105, D107, D203, D213, D401
match_dir = (?!django_dummy_app|project|venv|migrations|tests|\.).*
match = (?!manage).*\.py
add_ignore = D100, D104, D105, D106
# D100: Missing docstring in public module
# D104: Missing docstring in public package
# D105: Missing docstring in magic method
# D106: Missing docstring in public nested class

[tool:isort]
profile = black
line_length = 120
src_paths = django_opensearch_dsl,tests


[bandit]
targets = django_opensearch_dsl, tests
exclude = venv, .tox
recursive = True
quiet = True
format = custom
msg-template = {abspath}:{line} - {test_id} - {severity} - {msg}

[tool:pytest]
addopts = -vvl


#############################
Expand Down
Loading