Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kujiy committed Sep 12, 2022
2 parents 1e0a98f + f7f85a5 commit 57c9540
Show file tree
Hide file tree
Showing 45 changed files with 233 additions and 322 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backport.yml
Expand Up @@ -11,6 +11,6 @@ jobs:
name: Backport
steps:
- name: Backport
uses: tibdex/backport
uses: tibdex/backport@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
21 changes: 13 additions & 8 deletions .github/workflows/ci.yml
Expand Up @@ -43,9 +43,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
Expand All @@ -60,29 +60,34 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
python-version: [
"3.6",
"3.7",
"3.8",
"3.9",
]
es-version: [7.0.0, 7.10.0]

steps:
- name: Checkout Repository
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Setup Elasticsearch
run: |
mkdir /tmp/elasticsearch
wget -O - https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${{ matrix.es-version }}-linux-x86_64.tar.gz | tar xz --directory=/tmp/elasticsearch --strip-components=1
/tmp/elasticsearch/bin/elasticsearch -d
- name: Setup Python - ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python 3.8 for Nox
if: matrix.python-version != '3.8'
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3
- name: Install dependencies
run: |
python3.8 -m pip install nox
python3 -m pip install nox
- name: Run Tests
run: |
nox -rs test-${{ matrix.python-version }}
17 changes: 8 additions & 9 deletions docs/conf.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
Expand Down Expand Up @@ -62,8 +61,8 @@
master_doc = "index"

# General information about the project.
project = u"Elasticsearch DSL"
copyright = u"%d, Elasticsearch B.V" % datetime.datetime.now().year
project = "Elasticsearch DSL"
copyright = "%d, Elasticsearch B.V" % datetime.datetime.now().year

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -216,8 +215,8 @@
(
"index",
"Elasticsearch-dsl.tex",
u"Elasticsearch DSL Documentation",
u"Elasticsearch B.V",
"Elasticsearch DSL Documentation",
"Elasticsearch B.V",
"manual",
),
]
Expand Down Expand Up @@ -251,8 +250,8 @@
(
"index",
"elasticsearch-dsl",
u"Elasticsearch DSL Documentation",
[u"Elasticsearch B.V"],
"Elasticsearch DSL Documentation",
["Elasticsearch B.V"],
1,
)
]
Expand All @@ -270,8 +269,8 @@
(
"index",
"Elasticsearch",
u"Elasticsearch Documentation",
u"Elasticsearch B.V",
"Elasticsearch Documentation",
"Elasticsearch B.V",
"Elasticsearch",
"One line description of project.",
"Miscellaneous",
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch_dsl/__init__.py
Expand Up @@ -84,7 +84,7 @@
from .utils import AttrDict, AttrList, DslBase
from .wrappers import Range

VERSION = (7, 2, 0)
VERSION = (8, 0, 0)
__version__ = VERSION
__versionstr__ = ".".join(map(str, VERSION))
__all__ = [
Expand Down
17 changes: 7 additions & 10 deletions elasticsearch_dsl/aggs.py
Expand Up @@ -15,10 +15,7 @@
# specific language governing permissions and limitations
# under the License.

try:
import collections.abc as collections_abc # only works on python 3.3+
except ImportError:
import collections as collections_abc
import collections.abc

from .response.aggs import AggResponse, BucketData, FieldBucketData, TopHitsData
from .utils import DslBase
Expand All @@ -34,7 +31,7 @@ def A(name_or_agg, filter=None, **params):
params["filter"] = filter

# {"terms": {"field": "tags"}, "aggs": {...}}
if isinstance(name_or_agg, collections_abc.Mapping):
if isinstance(name_or_agg, collections.abc.Mapping):
if params:
raise ValueError("A() cannot accept parameters when passing in a dict.")
# copy to avoid modifying in-place
Expand Down Expand Up @@ -79,7 +76,7 @@ def __contains__(self, key):
return False

def to_dict(self):
d = super(Agg, self).to_dict()
d = super().to_dict()
if "meta" in d[self.name]:
d["meta"] = d[self.name].pop("meta")
return d
Expand All @@ -88,7 +85,7 @@ def result(self, search, data):
return AggResponse(self, search, data)


class AggBase(object):
class AggBase:
_param_defs = {
"aggs": {"type": "agg", "hash": True},
}
Expand Down Expand Up @@ -139,7 +136,7 @@ def result(self, search, data):

class Bucket(AggBase, Agg):
def __init__(self, **params):
super(Bucket, self).__init__(**params)
super().__init__(**params)
# remember self for chaining
self._base = self

Expand All @@ -160,10 +157,10 @@ class Filter(Bucket):
def __init__(self, filter=None, **params):
if filter is not None:
params["filter"] = filter
super(Filter, self).__init__(**params)
super().__init__(**params)

def to_dict(self):
d = super(Filter, self).to_dict()
d = super().to_dict()
d[self.name].update(d[self.name].pop("filter", {}))
return d

Expand Down
22 changes: 10 additions & 12 deletions elasticsearch_dsl/analysis.py
Expand Up @@ -15,20 +15,18 @@
# specific language governing permissions and limitations
# under the License.

import six

from .connections import get_connection
from .utils import AttrDict, DslBase, merge

__all__ = ["tokenizer", "analyzer", "char_filter", "token_filter", "normalizer"]


class AnalysisBase(object):
class AnalysisBase:
@classmethod
def _type_shortcut(cls, name_or_instance, type=None, **kwargs):
if isinstance(name_or_instance, cls):
if type or kwargs:
raise ValueError("%s() cannot accept parameters." % cls.__name__)
raise ValueError(f"{cls.__name__}() cannot accept parameters.")
return name_or_instance

if not (type or kwargs):
Expand All @@ -39,20 +37,20 @@ def _type_shortcut(cls, name_or_instance, type=None, **kwargs):
)


class CustomAnalysis(object):
class CustomAnalysis:
name = "custom"

def __init__(self, filter_name, builtin_type="custom", **kwargs):
self._builtin_type = builtin_type
self._name = filter_name
super(CustomAnalysis, self).__init__(**kwargs)
super().__init__(**kwargs)

def to_dict(self):
# only name to present in lists
return self._name

def get_definition(self):
d = super(CustomAnalysis, self).to_dict()
d = super().to_dict()
d = d.pop(self.name)
d["type"] = self._builtin_type
return d
Expand Down Expand Up @@ -92,12 +90,12 @@ def get_analysis_definition(self):
return out


class BuiltinAnalysis(object):
class BuiltinAnalysis:
name = "builtin"

def __init__(self, name):
self._name = name
super(BuiltinAnalysis, self).__init__()
super().__init__()

def to_dict(self):
# only name to present in lists
Expand Down Expand Up @@ -148,7 +146,7 @@ def simulate(self, text, using="default", explain=False, attributes=None):
sec_def = definition.get(section, {})
sec_names = analyzer_def[section]

if isinstance(sec_names, six.string_types):
if isinstance(sec_names, str):
body[section] = sec_def.get(sec_names, sec_names)
else:
body[section] = [
Expand Down Expand Up @@ -213,7 +211,7 @@ def get_definition(self):
if "filters" in d:
d["filters"] = [
# comma delimited string given by user
fs if isinstance(fs, six.string_types) else
fs if isinstance(fs, str) else
# list of strings or TokenFilter objects
", ".join(f.to_dict() if hasattr(f, "to_dict") else f for f in fs)
for fs in self.filters
Expand All @@ -227,7 +225,7 @@ def get_analysis_definition(self):
fs = {}
d = {"filter": fs}
for filters in self.filters:
if isinstance(filters, six.string_types):
if isinstance(filters, str):
continue
fs.update(
{
Expand Down
9 changes: 4 additions & 5 deletions elasticsearch_dsl/connections.py
Expand Up @@ -16,12 +16,11 @@
# under the License.

from elasticsearch import Elasticsearch
from six import string_types

from .serializer import serializer


class Connections(object):
class Connections:
"""
Class responsible for holding connections to different clusters. Used as a
singleton in this module.
Expand Down Expand Up @@ -73,7 +72,7 @@ def remove_connection(self, alias):
errors += 1

if errors == 2:
raise KeyError("There is no connection with alias %r." % alias)
raise KeyError(f"There is no connection with alias {alias!r}.")

def create_connection(self, alias="default", **kwargs):
"""
Expand All @@ -95,7 +94,7 @@ def get_connection(self, alias="default"):
"""
# do not check isinstance(Elasticsearch) so that people can wrap their
# clients
if not isinstance(alias, string_types):
if not isinstance(alias, str):
return alias

# connection already established
Expand All @@ -109,7 +108,7 @@ def get_connection(self, alias="default"):
return self.create_connection(alias, **self._kwargs[alias])
except KeyError:
# no connection and no kwargs to set one up
raise KeyError("There is no connection with alias %r." % alias)
raise KeyError(f"There is no connection with alias {alias!r}.")


connections = Connections()
Expand Down

0 comments on commit 57c9540

Please sign in to comment.