dronefly-core 0.3.9.dev1__tar.gz → 0.4.0__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 (29) hide show
  1. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/PKG-INFO +2 -2
  2. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/commands/__init__.py +10 -10
  3. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/menus/__init__.py +1 -0
  4. dronefly_core-0.4.0/dronefly/core/menus/taxon.py +31 -0
  5. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/parsers/constants.py +5 -3
  6. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/parsers/natural.py +8 -0
  7. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/query/query.py +8 -4
  8. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/pyproject.toml +2 -2
  9. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/LICENSE +0 -0
  10. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/README.md +0 -0
  11. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/__init__.py +0 -0
  12. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/clients/__init__.py +0 -0
  13. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/clients/inat.py +0 -0
  14. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/constants.py +0 -0
  15. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/formatters/__init__.py +0 -0
  16. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/formatters/constants.py +0 -0
  17. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/formatters/generic.py +0 -0
  18. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/menus/menu.py +0 -0
  19. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/menus/source.py +0 -0
  20. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/menus/taxon_list.py +0 -0
  21. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/models/__init__.py +0 -0
  22. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/models/config.py +0 -0
  23. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/models/controlled_terms.py +0 -0
  24. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/models/user.py +0 -0
  25. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/parsers/__init__.py +0 -0
  26. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/parsers/unixlike.py +0 -0
  27. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/parsers/url.py +0 -0
  28. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/query/__init__.py +0 -0
  29. {dronefly_core-0.3.9.dev1 → dronefly_core-0.4.0}/dronefly/core/utils/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dronefly-core
3
- Version: 0.3.9.dev1
3
+ Version: 0.4.0
4
4
  Summary: Core dronefly components
5
5
  License: AGPL-3.0-or-later
6
6
  Author: Ben Armstrong
@@ -14,7 +14,7 @@ Requires-Dist: dateparser (>=1.1.1,<2.0.0)
14
14
  Requires-Dist: filelock (>=3.13.3,<4.0.0)
15
15
  Requires-Dist: html2markdown (>=0.1.7,<0.2.0)
16
16
  Requires-Dist: inflect (>=5.3.0,<6.0.0)
17
- Requires-Dist: pyinaturalist (==0.20.0.dev1)
17
+ Requires-Dist: pyinaturalist (>=0.20.0,<0.21.0)
18
18
  Requires-Dist: rich (>=13.4)
19
19
  Description-Content-Type: text/markdown
20
20
 
@@ -176,7 +176,7 @@ class Commands:
176
176
  response = markdown_text
177
177
  return response
178
178
 
179
- def life(self, ctx: Context, *args):
179
+ async def life(self, ctx: Context, *args):
180
180
  _args = " ".join(args) or "by me"
181
181
  query = self._parse(_args)
182
182
  per_rank = query.per or "main"
@@ -247,7 +247,7 @@ class Commands:
247
247
  formatter.pages[0]["header"] = title
248
248
  return self._get_formatted_page(formatter, 0, 0)
249
249
 
250
- def taxon_list(self, ctx: Context, *args):
250
+ async def taxon_list(self, ctx: Context, *args):
251
251
  query = self._parse(" ".join(args))
252
252
  per_rank = query.per or "child"
253
253
  if per_rank not in [*RANK_KEYWORDS, "child"]:
@@ -361,7 +361,7 @@ class Commands:
361
361
  page = self._get_formatted_page(formatter, 0, 0, header=msg)
362
362
  return page
363
363
 
364
- def next(self, ctx: Context):
364
+ async def next(self, ctx: Context):
365
365
  if not ctx.page_formatter:
366
366
  return "Type a command that has pages first"
367
367
  ctx.page += 1
@@ -370,7 +370,7 @@ class Commands:
370
370
  ctx.selected = 0
371
371
  return self._get_formatted_page(ctx.page_formatter, ctx.page, ctx.selected)
372
372
 
373
- def page(self, ctx: Context, page: int = 1):
373
+ async def page(self, ctx: Context, page: int = 1):
374
374
  if not ctx.page_formatter:
375
375
  return "Type a command that has pages first"
376
376
  last_page = ctx.page_formatter.last_page() + 1
@@ -383,7 +383,7 @@ class Commands:
383
383
  ctx.selected = 0
384
384
  return self._get_formatted_page(ctx.page_formatter, ctx.page, ctx.selected)
385
385
 
386
- def sel(self, ctx: Context, sel: int = 1):
386
+ async def sel(self, ctx: Context, sel: int = 1):
387
387
  if not ctx.page_formatter:
388
388
  return "Type a command that has pages first"
389
389
  _page = ctx.page_formatter.get_page_of_taxa(ctx.page)
@@ -396,7 +396,7 @@ class Commands:
396
396
  ctx.selected = sel - 1
397
397
  return self._get_formatted_page(ctx.page_formatter, ctx.page, ctx.selected)
398
398
 
399
- def prev(self, ctx: Context):
399
+ async def prev(self, ctx: Context):
400
400
  if not ctx.page_formatter:
401
401
  return "Type a command that has pages first"
402
402
  ctx.page -= 1
@@ -405,7 +405,7 @@ class Commands:
405
405
  ctx.selected = 0
406
406
  return self._get_formatted_page(ctx.page_formatter, ctx.page, ctx.selected)
407
407
 
408
- def taxon(self, ctx: Context, *args):
408
+ async def taxon(self, ctx: Context, *args):
409
409
  taxon = None
410
410
  if len(args) == 0 or args[0] == "sel":
411
411
  formatter = ctx.page_formatter
@@ -438,7 +438,7 @@ class Commands:
438
438
 
439
439
  return response
440
440
 
441
- def obs(self, ctx: Context, *args):
441
+ async def obs(self, ctx: Context, *args):
442
442
  query = self._parse(" ".join(args))
443
443
  # TODO: Handle all query clauses, not just main.terms
444
444
  # TODO: Doesn't do any ranking or filtering of results
@@ -479,7 +479,7 @@ class Commands:
479
479
 
480
480
  return response
481
481
 
482
- def user(self, ctx: Context, user_id: str):
482
+ async def user(self, ctx: Context, user_id: str):
483
483
  with self.inat_client.set_ctx(ctx) as client:
484
484
  user = None
485
485
  try:
@@ -492,7 +492,7 @@ class Commands:
492
492
 
493
493
  return self._format_markdown(UserFormatter(user).format())
494
494
 
495
- def user_add(self, ctx: Context, user_abbrev: str, user_id: str):
495
+ async def user_add(self, ctx: Context, user_abbrev: str, user_id: str):
496
496
  if user_abbrev != "me":
497
497
  return "Only `user add me <user-id>` is supported at this time."
498
498
  user_config = self.config.user(ctx.author.id)
@@ -1,3 +1,4 @@
1
1
  from .source import * # noqa: F401,F403
2
2
  from .menu import * # noqa: F401,F403
3
3
  from .taxon_list import * # noqa: F401,F403
4
+ from .taxon import * # noqa: F401,F403
@@ -0,0 +1,31 @@
1
+ from .source import ListPageSource
2
+ from ..formatters import TaxonFormatter
3
+ from ..formatters.constants import WWW_BASE_URL
4
+ from ..query import QueryResponse
5
+
6
+
7
+ class TaxonSource(ListPageSource):
8
+ def __init__(self, taxon_formatter: TaxonFormatter, with_ancestors: bool = True):
9
+ self._taxon_formatter = taxon_formatter
10
+ self._url = f"{WWW_BASE_URL}/taxon/{self.query_response.taxon.id}"
11
+ self.with_ancestors = with_ancestors
12
+ pages = [self.formatter.format(with_ancestors=with_ancestors)]
13
+ super().__init__(pages, per_page=1)
14
+
15
+ def is_paginating(self):
16
+ return False
17
+
18
+ @property
19
+ def formatter(self) -> TaxonFormatter:
20
+ return self._taxon_formatter
21
+
22
+ @property
23
+ def query_response(self) -> QueryResponse:
24
+ return self.formatter.query_response
25
+
26
+ def toggle_ancestors(self):
27
+ self.with_ancestors = not self.with_ancestors
28
+ self.entries[0] = self.format_page()
29
+
30
+ def format_page(self):
31
+ return self.formatter.format(with_ancestors=self.with_ancestors)
@@ -27,14 +27,16 @@ REMAINING_ARGS = list(ARGPARSE_ARGS)[1:]
27
27
  MACROS = {
28
28
  "rg": {"opt": ["quality_grade=research"]},
29
29
  "nid": {"opt": ["quality_grade=needs_id"]},
30
- "oldest": {"order": "asc", "sort_by": "observed"},
31
- "newest": {"order": "desc", "sort_by": "observed"},
30
+ "oldest": {"asc": None, "sort by": "observed"},
31
+ "newest": {"desc": None, "sort by": "observed"},
32
32
  "my": {"by": "me"},
33
33
  "home": {"from": "home"},
34
- "faves": {"sort_by": "votes", "opt": ["popular"]},
34
+ "faves": {"sort by": "votes", "opt": ["popular"]},
35
35
  "spp": {"opt": ["hrank=species"]},
36
36
  "species": {"opt": ["hrank=species"]},
37
37
  "unseen": {"not by": "me", "from": "home"},
38
+ "most": {"per": "species", "sort by": "obs"},
39
+ "least": {"per": "species", "sort by": "obs", "asc": None},
38
40
  }
39
41
  # Groups of taxa:
40
42
  # - can't function in place of a single taxon, and are typically only used in
@@ -208,6 +208,14 @@ class NaturalParser(UnixlikeParser):
208
208
  expanded_tokens.extend(["--from", params["from"]])
209
209
  if "of" in params:
210
210
  expanded_tokens.extend(["--of", params["of"]])
211
+ if "sort by" in params:
212
+ expanded_tokens.extend(["--sort-by", params["sort by"]])
213
+ if "asc" in params:
214
+ expanded_tokens.extend(["--asc"])
215
+ if "desc" in params:
216
+ expanded_tokens.extend(["--desc"])
217
+ if "per" in params:
218
+ expanded_tokens.extend(["--per", params["per"]])
211
219
  if opts:
212
220
  expanded_tokens.extend(["--opt", *opts])
213
221
 
@@ -523,10 +523,14 @@ class QueryResponse:
523
523
  with_or_and, lrank, hrank
524
524
  )
525
525
  else:
526
- higher_or_lower = "higher" if lrank else "lower"
527
- message += " {} rank {} or {}".format(
528
- with_or_and, hrank or lrank, higher_or_lower
529
- )
526
+ # For some commands "species and higher" filter is added only to
527
+ # make it match results on the web. Including this in the description
528
+ # would just be confusing.
529
+ if lrank != "species":
530
+ higher_or_lower = "higher" if lrank else "lower"
531
+ message += " {} rank {} or {}".format(
532
+ with_or_and, hrank or lrank, higher_or_lower
533
+ )
530
534
  order_by = kwargs.get("order_by")
531
535
  order = kwargs.get("order")
532
536
  if order:
@@ -7,7 +7,7 @@ extend-ignore = "E203"
7
7
 
8
8
  [tool.poetry]
9
9
  name = "dronefly-core"
10
- version = "0.3.9.dev1"
10
+ version = "0.4.0"
11
11
  description = "Core dronefly components"
12
12
  authors = ["Ben Armstrong <synrg@debian.org>"]
13
13
  license = "AGPL-3.0-or-later"
@@ -18,7 +18,7 @@ packages = [
18
18
 
19
19
  [tool.poetry.dependencies]
20
20
  python = ">=3.11,<3.13"
21
- pyinaturalist = "=0.20.0.dev1"
21
+ pyinaturalist = "^0.20.0"
22
22
  dateparser = "^1.1.1"
23
23
  filelock = "^3.13.3"
24
24
  inflect = "^5.3.0"