From 7386dd581aa5444b95e7d8d8ad800b4d116f409a Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Fri, 22 Mar 2024 14:42:29 +0000 Subject: [PATCH] restore sync examples unasynced by mistake --- examples/alias_migration.py | 13 +++---------- examples/completion.py | 10 +--------- examples/composite_agg.py | 13 ++----------- examples/parent_child.py | 14 ++------------ examples/percolate.py | 10 +--------- .../test_examples/_async/alias_migration.py | 1 - .../test_examples/_async/completion.py | 1 - .../test_examples/_async/composite_agg.py | 1 - .../test_examples/_async/parent_child.py | 1 - .../test_examples/_async/percolate.py | 1 - .../test_examples/_async/test_alias_migration.py | 4 ++-- .../test_examples/_async/test_completion.py | 2 +- .../test_examples/_async/test_composite_aggs.py | 2 +- .../test_examples/_async/test_parent_child.py | 2 +- .../test_examples/_async/test_percolate.py | 2 +- .../test_examples/_sync/alias_migration.py | 1 - .../test_examples/_sync/completion.py | 1 - .../test_examples/_sync/composite_agg.py | 1 - .../test_examples/_sync/parent_child.py | 1 - .../test_examples/_sync/percolate.py | 1 - .../test_examples/_sync/test_alias_migration.py | 4 ++-- .../test_examples/_sync/test_completion.py | 2 +- .../test_examples/_sync/test_composite_aggs.py | 2 +- .../test_examples/_sync/test_parent_child.py | 2 +- .../test_examples/_sync/test_percolate.py | 2 +- .../test_integration/test_examples/async_examples | 1 + tests/test_integration/test_examples/examples | 1 + utils/run-unasync.py | 1 + 28 files changed, 24 insertions(+), 73 deletions(-) delete mode 120000 tests/test_integration/test_examples/_async/alias_migration.py delete mode 120000 tests/test_integration/test_examples/_async/completion.py delete mode 120000 tests/test_integration/test_examples/_async/composite_agg.py delete mode 120000 tests/test_integration/test_examples/_async/parent_child.py delete mode 120000 tests/test_integration/test_examples/_async/percolate.py delete mode 120000 tests/test_integration/test_examples/_sync/alias_migration.py delete mode 120000 tests/test_integration/test_examples/_sync/completion.py delete mode 120000 tests/test_integration/test_examples/_sync/composite_agg.py delete mode 120000 tests/test_integration/test_examples/_sync/parent_child.py delete mode 120000 tests/test_integration/test_examples/_sync/percolate.py create mode 120000 tests/test_integration/test_examples/async_examples create mode 120000 tests/test_integration/test_examples/examples diff --git a/examples/alias_migration.py b/examples/alias_migration.py index 645ff0bc5..13d170d44 100644 --- a/examples/alias_migration.py +++ b/examples/alias_migration.py @@ -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 @@ -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() @@ -143,10 +143,3 @@ def main(): # create new index migrate() - - # close the connection - connections.get_connection().close() - - -if __name__ == "__main__": - asyncio.run(main()) diff --git a/examples/completion.py b/examples/completion.py index d4fc4c319..f874968ea 100644 --- a/examples/completion.py +++ b/examples/completion.py @@ -26,7 +26,6 @@ that does ascii folding. """ -import asyncio import os from itertools import permutations @@ -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"]]) @@ -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()) diff --git a/examples/composite_agg.py b/examples/composite_agg.py index f5aa3de60..1a2096e9f 100644 --- a/examples/composite_agg.py +++ b/examples/composite_agg.py @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. -import asyncio import os from elasticsearch_dsl import A, Search, connections @@ -37,8 +36,7 @@ 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: @@ -46,7 +44,7 @@ def run_search(**kwargs): response = run_search(after=after) -def main(): +if __name__ == "__main__": # initiate the default connection to elasticsearch connections.create_connection(hosts=[os.environ["ELASTICSEARCH_URL"]]) @@ -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()) diff --git a/examples/parent_child.py b/examples/parent_child.py index 46db4d19d..9916f5f5b 100644 --- a/examples/parent_child.py +++ b/examples/parent_child.py @@ -39,7 +39,6 @@ particular parent """ -import asyncio import os from datetime import datetime @@ -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" @@ -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"]]) @@ -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()) diff --git a/examples/percolate.py b/examples/percolate.py index 5db0287ee..d588a00bc 100644 --- a/examples/percolate.py +++ b/examples/percolate.py @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. -import asyncio import os from elasticsearch_dsl import ( @@ -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()) diff --git a/tests/test_integration/test_examples/_async/alias_migration.py b/tests/test_integration/test_examples/_async/alias_migration.py deleted file mode 120000 index aa6be78e6..000000000 --- a/tests/test_integration/test_examples/_async/alias_migration.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/async/alias_migration.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_async/completion.py b/tests/test_integration/test_examples/_async/completion.py deleted file mode 120000 index 8b52dd2dc..000000000 --- a/tests/test_integration/test_examples/_async/completion.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/async/completion.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_async/composite_agg.py b/tests/test_integration/test_examples/_async/composite_agg.py deleted file mode 120000 index 7414b1109..000000000 --- a/tests/test_integration/test_examples/_async/composite_agg.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/async/composite_agg.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_async/parent_child.py b/tests/test_integration/test_examples/_async/parent_child.py deleted file mode 120000 index 3cd7d5e72..000000000 --- a/tests/test_integration/test_examples/_async/parent_child.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/async/parent_child.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_async/percolate.py b/tests/test_integration/test_examples/_async/percolate.py deleted file mode 120000 index 61acc4aaf..000000000 --- a/tests/test_integration/test_examples/_async/percolate.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/async/percolate.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_async/test_alias_migration.py b/tests/test_integration/test_examples/_async/test_alias_migration.py index b1a2e985b..9bedd7b28 100644 --- a/tests/test_integration/test_examples/_async/test_alias_migration.py +++ b/tests/test_integration/test_examples/_async/test_alias_migration.py @@ -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): diff --git a/tests/test_integration/test_examples/_async/test_completion.py b/tests/test_integration/test_examples/_async/test_completion.py index 8970b41c7..f71fcb1e6 100644 --- a/tests/test_integration/test_examples/_async/test_completion.py +++ b/tests/test_integration/test_examples/_async/test_completion.py @@ -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): diff --git a/tests/test_integration/test_examples/_async/test_composite_aggs.py b/tests/test_integration/test_examples/_async/test_composite_aggs.py index e5cbbb12d..ba07b4533 100644 --- a/tests/test_integration/test_examples/_async/test_composite_aggs.py +++ b/tests/test_integration/test_examples/_async/test_composite_aggs.py @@ -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): diff --git a/tests/test_integration/test_examples/_async/test_parent_child.py b/tests/test_integration/test_examples/_async/test_parent_child.py index 83e6d63b4..66fdac3c0 100644 --- a/tests/test_integration/test_examples/_async/test_parent_child.py +++ b/tests/test_integration/test_examples/_async/test_parent_child.py @@ -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, diff --git a/tests/test_integration/test_examples/_async/test_percolate.py b/tests/test_integration/test_examples/_async/test_percolate.py index fd0d88de0..a538b9e47 100644 --- a/tests/test_integration/test_examples/_async/test_percolate.py +++ b/tests/test_integration/test_examples/_async/test_percolate.py @@ -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): diff --git a/tests/test_integration/test_examples/_sync/alias_migration.py b/tests/test_integration/test_examples/_sync/alias_migration.py deleted file mode 120000 index db71b4b4b..000000000 --- a/tests/test_integration/test_examples/_sync/alias_migration.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/alias_migration.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_sync/completion.py b/tests/test_integration/test_examples/_sync/completion.py deleted file mode 120000 index 17eff36b5..000000000 --- a/tests/test_integration/test_examples/_sync/completion.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/completion.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_sync/composite_agg.py b/tests/test_integration/test_examples/_sync/composite_agg.py deleted file mode 120000 index 469f462f9..000000000 --- a/tests/test_integration/test_examples/_sync/composite_agg.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/composite_agg.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_sync/parent_child.py b/tests/test_integration/test_examples/_sync/parent_child.py deleted file mode 120000 index 4be9239d0..000000000 --- a/tests/test_integration/test_examples/_sync/parent_child.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/parent_child.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_sync/percolate.py b/tests/test_integration/test_examples/_sync/percolate.py deleted file mode 120000 index 32a5a7278..000000000 --- a/tests/test_integration/test_examples/_sync/percolate.py +++ /dev/null @@ -1 +0,0 @@ -../../../../examples/percolate.py \ No newline at end of file diff --git a/tests/test_integration/test_examples/_sync/test_alias_migration.py b/tests/test_integration/test_examples/_sync/test_alias_migration.py index 531e2bae2..ee8b70cc5 100644 --- a/tests/test_integration/test_examples/_sync/test_alias_migration.py +++ b/tests/test_integration/test_examples/_sync/test_alias_migration.py @@ -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): diff --git a/tests/test_integration/test_examples/_sync/test_completion.py b/tests/test_integration/test_examples/_sync/test_completion.py index 92f6d80a0..0b49400fc 100644 --- a/tests/test_integration/test_examples/_sync/test_completion.py +++ b/tests/test_integration/test_examples/_sync/test_completion.py @@ -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): diff --git a/tests/test_integration/test_examples/_sync/test_composite_aggs.py b/tests/test_integration/test_examples/_sync/test_composite_aggs.py index acc108ad2..0c59b3f70 100644 --- a/tests/test_integration/test_examples/_sync/test_composite_aggs.py +++ b/tests/test_integration/test_examples/_sync/test_composite_aggs.py @@ -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): diff --git a/tests/test_integration/test_examples/_sync/test_parent_child.py b/tests/test_integration/test_examples/_sync/test_parent_child.py index 423c24951..2aad5f64b 100644 --- a/tests/test_integration/test_examples/_sync/test_parent_child.py +++ b/tests/test_integration/test_examples/_sync/test_parent_child.py @@ -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, diff --git a/tests/test_integration/test_examples/_sync/test_percolate.py b/tests/test_integration/test_examples/_sync/test_percolate.py index 30fcf972b..ef81a1099 100644 --- a/tests/test_integration/test_examples/_sync/test_percolate.py +++ b/tests/test_integration/test_examples/_sync/test_percolate.py @@ -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): diff --git a/tests/test_integration/test_examples/async_examples b/tests/test_integration/test_examples/async_examples new file mode 120000 index 000000000..1cebed2ce --- /dev/null +++ b/tests/test_integration/test_examples/async_examples @@ -0,0 +1 @@ +../../../examples/async \ No newline at end of file diff --git a/tests/test_integration/test_examples/examples b/tests/test_integration/test_examples/examples new file mode 120000 index 000000000..9f9d1de88 --- /dev/null +++ b/tests/test_integration/test_examples/examples @@ -0,0 +1 @@ +../../../examples \ No newline at end of file diff --git a/utils/run-unasync.py b/utils/run-unasync.py index 53845d252..45aa61c66 100644 --- a/utils/run-unasync.py +++ b/utils/run-unasync.py @@ -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 = [