Skip to content

Commit

Permalink
restore sync examples unasynced by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Mar 22, 2024
1 parent 38cd862 commit 7386dd5
Show file tree
Hide file tree
Showing 28 changed files with 24 additions and 73 deletions.
13 changes: 3 additions & 10 deletions examples/alias_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
will have index set to the concrete index whereas the class refers to the
alias.
"""
import asyncio
import os
from datetime import datetime
from fnmatch import fnmatch

Expand Down Expand Up @@ -125,9 +125,9 @@ def migrate(move_data=True, update_alias=True):
)


def main():
if __name__ == "__main__":
# initiate the default connection to elasticsearch
connections.create_connection(hosts=["http://localhost:9200"])
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])

# create the empty index
setup()
Expand All @@ -143,10 +143,3 @@ def main():

# create new index
migrate()

# close the connection
connections.get_connection().close()


if __name__ == "__main__":
asyncio.run(main())
10 changes: 1 addition & 9 deletions examples/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
that does ascii folding.
"""

import asyncio
import os
from itertools import permutations

Expand Down Expand Up @@ -73,7 +72,7 @@ class Index:
settings = {"number_of_shards": 1, "number_of_replicas": 0}


def main():
if __name__ == "__main__":
# initiate the default connection to elasticsearch
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])

Expand All @@ -98,10 +97,3 @@ def main():
# print out all the options we got
for option in response.suggest.auto_complete[0].options:
print("%10s: %25s (%d)" % (text, option._source.name, option._score))

# close the connection
connections.get_connection().close()


if __name__ == "__main__":
asyncio.run(main())
13 changes: 2 additions & 11 deletions examples/composite_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.

import asyncio
import os

from elasticsearch_dsl import A, Search, connections
Expand All @@ -37,16 +36,15 @@ def run_search(**kwargs):

response = run_search()
while response.aggregations.comp.buckets:
for b in response.aggregations.comp.buckets:
yield b
yield from response.aggregations.comp.buckets
if "after_key" in response.aggregations.comp:
after = response.aggregations.comp.after_key
else:
after = response.aggregations.comp.buckets[-1].key
response = run_search(after=after)


def main():
if __name__ == "__main__":
# initiate the default connection to elasticsearch
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])

Expand All @@ -59,10 +57,3 @@ def main():
"File %s has been modified %d times, first seen at %s."
% (b.key.files, b.doc_count, b.first_seen.value_as_string)
)

# close the connection
connections.get_connection().close()


if __name__ == "__main__":
asyncio.run(main())
14 changes: 2 additions & 12 deletions examples/parent_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
particular parent
"""
import asyncio
import os
from datetime import datetime

Expand Down Expand Up @@ -166,7 +165,7 @@ def get_answers(self):
"""
if "inner_hits" in self.meta and "answer" in self.meta.inner_hits:
return self.meta.inner_hits.answer.hits
return [a for a in self.search_answers()]
return list(self.search_answers())

def save(self, **kwargs):
self.question_answer = "question"
Expand Down Expand Up @@ -209,7 +208,7 @@ def setup():
index_template.save()


def main():
if __name__ == "__main__":
# initiate the default connection to elasticsearch
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])

Expand Down Expand Up @@ -244,12 +243,3 @@ def main():
)
question.save()
answer = question.add_answer(honza, "Just use `elasticsearch-py`!")

# close the connection
connections.get_connection().close()

return answer


if __name__ == "__main__":
asyncio.run(main())
10 changes: 1 addition & 9 deletions examples/percolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.

import asyncio
import os

from elasticsearch_dsl import (
Expand Down Expand Up @@ -92,15 +91,8 @@ def setup():
).save(refresh=True)


def main():
if __name__ == "__main__":
# initiate the default connection to elasticsearch
connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]])

setup()

# close the connection
connections.get_connection().close()


if __name__ == "__main__":
asyncio.run(main())

This file was deleted.

1 change: 0 additions & 1 deletion tests/test_integration/test_examples/_async/completion.py

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tests/test_integration/test_examples/_async/percolate.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from . import alias_migration
from .alias_migration import ALIAS, PATTERN, BlogPost, migrate
from ..async_examples import alias_migration
from ..async_examples.alias_migration import ALIAS, PATTERN, BlogPost, migrate


async def test_alias_migration(async_write_client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.


from .completion import Person
from ..async_examples.completion import Person


async def test_person_suggests_on_all_variants_of_name(async_write_client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from elasticsearch_dsl import A, AsyncSearch

from .composite_agg import scan_aggs
from ..async_examples.composite_agg import scan_aggs


async def test_scan_aggs_exhausts_all_files(async_data_client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from elasticsearch_dsl import Q

from .parent_child import Answer, Comment, Question, User, setup
from ..async_examples.parent_child import Answer, Comment, Question, User, setup

honza = User(
id=42,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from .percolate import BlogPost, setup
from ..async_examples.percolate import BlogPost, setup


async def test_post_gets_tagged_automatically(async_write_client):
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion tests/test_integration/test_examples/_sync/completion.py

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tests/test_integration/test_examples/_sync/parent_child.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/test_integration/test_examples/_sync/percolate.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from . import alias_migration
from .alias_migration import ALIAS, PATTERN, BlogPost, migrate
from ..examples import alias_migration
from ..examples.alias_migration import ALIAS, PATTERN, BlogPost, migrate


def test_alias_migration(write_client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.


from .completion import Person
from ..examples.completion import Person


def test_person_suggests_on_all_variants_of_name(write_client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from elasticsearch_dsl import A, Search

from .composite_agg import scan_aggs
from ..examples.composite_agg import scan_aggs


def test_scan_aggs_exhausts_all_files(data_client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from elasticsearch_dsl import Q

from .parent_child import Answer, Comment, Question, User, setup
from ..examples.parent_child import Answer, Comment, Question, User, setup

honza = User(
id=42,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from .percolate import BlogPost, setup
from ..examples.percolate import BlogPost, setup


def test_post_gets_tagged_automatically(write_client):
Expand Down
1 change: 1 addition & 0 deletions tests/test_integration/test_examples/async_examples
1 change: 1 addition & 0 deletions tests/test_integration/test_examples/examples
1 change: 1 addition & 0 deletions utils/run-unasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def main(check=False):
"async_data_client": "data_client",
"async_write_client": "write_client",
"async_pull_request": "pull_request",
"async_examples": "examples",
"assert_awaited_once_with": "assert_called_once_with",
}
rules = [
Expand Down

0 comments on commit 7386dd5

Please sign in to comment.