dronefly-core 0.5.0.dev0__tar.gz → 0.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/PKG-INFO +11 -13
  2. dronefly_core-0.5.1/dronefly/core/__init__.py +1 -0
  3. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/clients/inat.py +21 -1
  4. dronefly_core-0.5.1/dronefly/core/commands/__init__.py +4 -0
  5. dronefly_core-0.5.1/dronefly/core/commands/base.py +125 -0
  6. dronefly_core-0.5.0.dev0/dronefly/core/commands/__init__.py → dronefly_core-0.5.1/dronefly/core/commands/cli.py +169 -174
  7. dronefly_core-0.5.1/dronefly/core/commands/constants.py +12 -0
  8. dronefly_core-0.5.1/dronefly/core/commands/exceptions.py +6 -0
  9. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/constants.py +4 -4
  10. dronefly_core-0.5.1/dronefly/core/controllers/inat/__init__.py +3 -0
  11. dronefly_core-0.5.1/dronefly/core/controllers/inat/observation_controller.py +28 -0
  12. dronefly_core-0.5.1/dronefly/core/controllers/inat/user_controller.py +33 -0
  13. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/formatters/generic.py +295 -28
  14. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/menus/__init__.py +2 -0
  15. dronefly_core-0.5.1/dronefly/core/menus/count.py +65 -0
  16. dronefly_core-0.5.1/dronefly/core/menus/counts.py +146 -0
  17. dronefly_core-0.5.1/dronefly/core/menus/menu.py +36 -0
  18. dronefly_core-0.5.1/dronefly/core/menus/observation_search.py +102 -0
  19. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/menus/taxon.py +32 -5
  20. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/menus/taxon_list.py +52 -28
  21. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/models/__init__.py +1 -1
  22. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/models/base_formatters.py +5 -5
  23. dronefly_core-0.5.1/dronefly/core/models/config.py +65 -0
  24. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/models/context.py +3 -0
  25. dronefly_core-0.5.1/dronefly/core/models/place_count.py +38 -0
  26. dronefly_core-0.5.1/dronefly/core/paginator.py +19 -0
  27. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/parsers/constants.py +4 -0
  28. dronefly_core-0.5.1/dronefly/core/query/formatters.py +94 -0
  29. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/query/query.py +316 -39
  30. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/query/taxon.py +1 -1
  31. dronefly_core-0.5.1/pyproject.toml +53 -0
  32. dronefly_core-0.5.0.dev0/LICENSE +0 -1132
  33. dronefly_core-0.5.0.dev0/dronefly/core/__init__.py +0 -1
  34. dronefly_core-0.5.0.dev0/dronefly/core/menus/menu.py +0 -22
  35. dronefly_core-0.5.0.dev0/dronefly/core/models/config.py +0 -58
  36. dronefly_core-0.5.0.dev0/pyproject.toml +0 -37
  37. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/README.md +0 -0
  38. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/clients/__init__.py +0 -0
  39. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/formatters/__init__.py +0 -0
  40. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/formatters/constants.py +0 -0
  41. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/menus/source.py +0 -0
  42. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/models/controlled_terms.py +0 -0
  43. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/models/taxon_list.py +0 -0
  44. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/models/user.py +0 -0
  45. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/parsers/__init__.py +0 -0
  46. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/parsers/natural.py +0 -0
  47. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/parsers/unixlike.py +0 -0
  48. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/parsers/url.py +0 -0
  49. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/query/__init__.py +0 -0
  50. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/query/base.py +0 -0
  51. {dronefly_core-0.5.0.dev0 → dronefly_core-0.5.1}/dronefly/core/utils/__init__.py +0 -0
@@ -1,21 +1,20 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: dronefly-core
3
- Version: 0.5.0.dev0
3
+ Version: 0.5.1
4
4
  Summary: Core dronefly components
5
- License: AGPL-3.0-or-later
6
5
  Author: Ben Armstrong
7
- Author-email: synrg@debian.org
8
- Requires-Python: >=3.11,<3.13
9
- Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
6
+ Author-email: Ben Armstrong <synrg@debian.org>
7
+ License-Expression: AGPL-3.0-or-later
10
8
  Classifier: Programming Language :: Python :: 3
11
9
  Classifier: Programming Language :: Python :: 3.11
12
10
  Classifier: Programming Language :: Python :: 3.12
13
- Requires-Dist: dateparser (>=1.1.1,<2.0.0)
14
- Requires-Dist: filelock (>=3.13.3,<4.0.0)
15
- Requires-Dist: html2markdown (>=0.1.7,<0.2.0)
16
- Requires-Dist: inflect (>=5.3.0,<6.0.0)
17
- Requires-Dist: pyinaturalist (>=0.20.0,<0.21.0)
18
- Requires-Dist: rich (>=13.4)
11
+ Requires-Dist: pyinaturalist>=0.21.1,<0.22
12
+ Requires-Dist: dateparser>=1.1.1,<2
13
+ Requires-Dist: filelock>=3.13.3,<4
14
+ Requires-Dist: inflect>=5.3.0,<6
15
+ Requires-Dist: html2markdown>=0.1.7,<0.2
16
+ Requires-Dist: rich>=13.4
17
+ Requires-Python: >=3.11, <3.13
19
18
  Description-Content-Type: text/markdown
20
19
 
21
20
  # Dronefly core
@@ -37,4 +36,3 @@ subset of Dronefly Discord bot's capabilities, built solely with Dronefly core.
37
36
  Dronefly Discord bot brings [iNaturalist](https://www.inaturalist.org) taxa,
38
37
  observations, and other data from the site into conversations on the
39
38
  [Discord](https://discord.com) chat platform.
40
-
@@ -0,0 +1 @@
1
+ from .commands import * # noqa: F401, F403
@@ -3,7 +3,7 @@ import asyncio
3
3
  from contextlib import contextmanager
4
4
  from functools import partial
5
5
  from inspect import signature
6
- from typing import Optional
6
+ from typing import Callable, Optional, Type
7
7
 
8
8
  from pyinaturalist import (
9
9
  ClientSession,
@@ -11,8 +11,11 @@ from pyinaturalist import (
11
11
  iNatClient as pyiNatClient,
12
12
  )
13
13
  from pyinaturalist.constants import RequestParams
14
+ from pyinaturalist.models import T
14
15
 
15
16
  from ..constants import INAT_DEFAULTS, RATELIMIT_FILE, RATELIMIT_LOCK_FILE, CACHE_FILE
17
+ from ..controllers.inat import ObservationController, UserController
18
+ from ..paginator import Paginator
16
19
 
17
20
 
18
21
  DRONEFLY_SESSION = ClientSession(
@@ -43,12 +46,17 @@ class iNatClient(pyiNatClient):
43
46
  **kwargs,
44
47
  }
45
48
  super().__init__(*args, **_kwargs)
49
+ self.users = UserController(self)
50
+ self.observations = ObservationController(self)
46
51
  self.annotations.async_all = asyncify(self, self.annotations.all)
47
52
  self.taxa.populate = asyncify(self, self.taxa.populate)
48
53
  self.observations.taxon_summary = asyncify(
49
54
  self, self.observations.taxon_summary
50
55
  )
51
56
  self.observations.life_list = asyncify(self, self.observations.life_list)
57
+ self.observations.species_count = asyncify(
58
+ self, self.observations.species_count
59
+ )
52
60
 
53
61
  def add_defaults(
54
62
  self,
@@ -66,6 +74,18 @@ class iNatClient(pyiNatClient):
66
74
 
67
75
  return _kwargs
68
76
 
77
+ def paginate(
78
+ self,
79
+ request_function: Callable,
80
+ model: Type[T],
81
+ auth: bool = False,
82
+ cls: Type[Paginator] = Paginator,
83
+ **kwargs,
84
+ ) -> Paginator[T]:
85
+ """Return our own Paginator instead of pyiNat's."""
86
+ kwargs = self.add_defaults(request_function, kwargs, auth)
87
+ return cls(request_function, model, loop=self.loop, **kwargs)
88
+
69
89
  @contextmanager
70
90
  def set_ctx(self, ctx):
71
91
  self.ctx = ctx
@@ -0,0 +1,4 @@
1
+ from .base import * # noqa: F401, F403
2
+ from .cli import * # noqa: F401, F403
3
+ from .constants import * # noqa: F401, F403
4
+ from .exceptions import * # noqa: F401, F403
@@ -0,0 +1,125 @@
1
+ import asyncio
2
+ from inspect import signature
3
+ import re
4
+ from typing import Union
5
+
6
+ from rich.markdown import Markdown
7
+ from ..parsers import NaturalParser
8
+ from ..clients.inat import iNatClient
9
+ from ..models import BaseFormatter, load_config, ListFormatter
10
+ from .constants import (
11
+ Format,
12
+ RICH_BQ_END_PAT,
13
+ RICH_BQ_NEWLINE_PAT,
14
+ RICH_NO_BQ_NEWLINE_PAT,
15
+ )
16
+
17
+
18
+ class Command:
19
+ def execute():
20
+ pass
21
+
22
+
23
+ class CommandResponse:
24
+ def format_message():
25
+ pass
26
+
27
+ def start_menu():
28
+ pass
29
+
30
+
31
+ class Commands:
32
+ """A Dronefly command processor."""
33
+
34
+ def __init__(
35
+ self,
36
+ loop: asyncio.BaseEventLoop,
37
+ format: Format = Format.discord_markdown,
38
+ ):
39
+ self.loop = loop
40
+ # TODO: platform: dronefly.Platform
41
+ # - e.g. discord, commandline, web
42
+ self.format = format
43
+ self.inat_client = iNatClient(loop=loop)
44
+ self.parser = NaturalParser()
45
+ self.dronefly_config = load_config()
46
+
47
+ def _parse(self, query_str):
48
+ return self.parser.parse(query_str)
49
+
50
+ async def _get_formatted_page(
51
+ self,
52
+ formatter: Union[ListFormatter, BaseFormatter],
53
+ page_number: int = 0,
54
+ selected: int = 0,
55
+ header: str = None,
56
+ footer: str = None,
57
+ ):
58
+ source = getattr(formatter, "source", None)
59
+ if getattr(formatter, "format_page", None):
60
+ if source:
61
+ page = await source.get_page(page_number)
62
+ sig = signature(formatter.format_page)
63
+ if len(sig.parameters) == 3:
64
+ markdown_text = formatter.format_page(page, page_number, selected)
65
+ last_page = formatter.last_page()
66
+ else:
67
+ markdown_text = formatter.format_page(page)
68
+ last_page = 0
69
+ else:
70
+ markdown_text = formatter.format_page(page_number, selected)
71
+ last_page = formatter.last_page()
72
+ if last_page > 0:
73
+ markdown_text = "\n\n".join(
74
+ [markdown_text, f"Page {page_number + 1}/{last_page + 1}"]
75
+ )
76
+ else:
77
+ markdown_text = formatter.format()
78
+ if header or footer:
79
+ markdown_text = "\n\n".join(
80
+ [item for item in (header, markdown_text, footer) if item is not None]
81
+ )
82
+ return markdown_text
83
+
84
+ def _format_markdown(self, markdown_text: str):
85
+ """Format Rich vs. Discord markdown."""
86
+ if self.format == Format.rich:
87
+ # Richify the markdown:
88
+ # - In Discord markdown, all newlines are rendered as line breaks
89
+ # - In Rich:
90
+ # - Before every newline, emit " \" to force a line break, except
91
+ # for these exceptions to handle blockquotes:
92
+ # - Don't do this for a line preceding a blockquote
93
+ # - Also don't do this on the last line of a blockquote
94
+ # - Ensure the last line of each blockquote has two newlines to
95
+ # end it
96
+
97
+ # Replace all but last newline of blockquote with line break sequence:
98
+ rich_markdown = re.sub(RICH_BQ_NEWLINE_PAT, r"\1 \\\n", markdown_text)
99
+ # Add extra newline at end of blockquote so following text won't be
100
+ # tacked on:
101
+ rich_markdown = re.sub(RICH_BQ_END_PAT, r"\1\n\n", rich_markdown)
102
+ # Finally, on any line that isn't part of a blockquote, isn't empty,
103
+ # and isn't at the end of the string, emit a line break:
104
+ rich_markdown = re.sub(RICH_NO_BQ_NEWLINE_PAT, r"\1 \\\n", rich_markdown)
105
+ response = Markdown(rich_markdown)
106
+ else:
107
+ # Return the literal markdown for Discord to render
108
+ response = markdown_text
109
+ return response
110
+
111
+ def _simple_format_markdown(self, markdown_text: str):
112
+ """Simplified formatter for Rich vs. Discord markdown.
113
+
114
+ Discord vs. Rich linebreak rendering is harder than we thought, e.g.
115
+ `_format_markdown()` doesn't give correct results with point-form
116
+ or numbered lists. If special handling of newlines isn't needed, then
117
+ use this helper instead.
118
+ """
119
+ if self.format == Format.rich:
120
+ # Richify the markdown
121
+ response = Markdown(markdown_text)
122
+ else:
123
+ # Return the literal markdown for Discord to render
124
+ response = markdown_text
125
+ return response