dronefly-cli 0.3.0.dev0__py3-none-any.whl → 0.3.2.dev1__py3-none-any.whl

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.
File without changes
dronefly_cli/main.py CHANGED
@@ -1,23 +1,36 @@
1
1
  #!/usr/bin/env python
2
2
  import asyncio
3
+ import io
3
4
  import os
5
+ import re
4
6
  import sys
5
7
  import readline
6
8
  from inspect import getmembers, isroutine
7
9
 
8
- from dronefly.core import Commands, Format
9
- from dronefly.core.models import Config, User
10
- from dronefly.core.commands import ArgumentError, CommandError, Context
10
+ from dronefly.core import CLICommands, Format
11
+ from dronefly.core.models import Context, load_workspace, User
12
+ from dronefly.core.commands import ArgumentError, CommandError
11
13
  from dronefly.core.constants import INAT_USER_DEFAULT_PARAMS
12
14
  from rich.console import Console
13
15
  from rich.markdown import Markdown
14
16
 
15
-
16
17
  console = Console()
17
18
  histfile = os.path.expanduser("~/.dronefly_history")
18
19
  histfile_size = 1000
19
20
 
20
21
 
22
+ def get_styled_prompt_str(markup: str = "[bold gold1](=)[/bold gold1] ") -> str:
23
+ """Renders Rich markup into a raw ANSI prompt string safely."""
24
+ buffer = io.StringIO()
25
+ temp_console = Console(file=buffer, force_terminal=True)
26
+ temp_console.print(markup, end="")
27
+ raw_prompt = buffer.getvalue()
28
+
29
+ # Apply GNU readline non-printing wrappers (\001 and \002) if needed
30
+ # - See: Textualize/rich#2293
31
+ return re.sub(r"(\x1b\[[0-9;]*m)", r"\001\1\002", raw_prompt)
32
+
33
+
21
34
  async def help(ctx, *args):
22
35
  """Show help
23
36
  Usage:
@@ -34,7 +47,7 @@ async def help(ctx, *args):
34
47
  commands = [
35
48
  *(
36
49
  member
37
- for member in getmembers(Commands, predicate=isroutine)
50
+ for member in getmembers(CLICommands, predicate=isroutine)
38
51
  if member[0][0] != "_"
39
52
  ),
40
53
  ("help", help),
@@ -50,7 +63,7 @@ async def help(ctx, *args):
50
63
  if command_name == "help":
51
64
  command = help
52
65
  else:
53
- command = getattr(Commands, command_name, None)
66
+ command = getattr(CLICommands, command_name, None)
54
67
  if callable(command):
55
68
  return f"Command: {command_name.replace('_', ' ')}\nDescription: {command.__doc__}"
56
69
  return f"No help for: {' '.join(args)}"
@@ -94,10 +107,10 @@ async def do_command(commands, command_str: str, ctx: Context, *args):
94
107
  console.print(err)
95
108
 
96
109
 
97
- def get_context():
110
+ async def get_context():
98
111
  default_user_id = 1
99
- config = Config()
100
- user_config = config.user(default_user_id)
112
+ workspace = load_workspace()
113
+ user_config = await workspace.user(default_user_id)
101
114
  user_params = {"id": default_user_id}
102
115
  for param in ("inat_user_id", *INAT_USER_DEFAULT_PARAMS):
103
116
  param_value = None
@@ -110,7 +123,7 @@ def get_context():
110
123
  if param_value:
111
124
  user_params[param] = param_value
112
125
  user = User(**user_params)
113
- ctx = Context(author=user)
126
+ ctx = Context(author=user, workspace=workspace)
114
127
  return ctx
115
128
 
116
129
 
@@ -128,9 +141,19 @@ async def start_command_loop(commands, ctx, histfile, histfile_size):
128
141
  try:
129
142
  read_history(histfile)
130
143
 
144
+ prompt = "[bold gold1](=)[/bold gold1] "
145
+ use_readline_wrappers = getattr(readline, "backend", "readline") == "readline"
146
+ prompt_str = get_styled_prompt_str(prompt) if use_readline_wrappers else None
147
+
131
148
  while True:
132
- console.print("[bold gold1](=)[/bold gold1]", end="")
133
- _line = console.input(" ").rstrip()
149
+ try:
150
+ if prompt_str:
151
+ _line = input(prompt_str).rstrip()
152
+ else:
153
+ console.print(prompt, end="")
154
+ _line = input().rstrip()
155
+ except EOFError:
156
+ raise EOFError
134
157
  if not _line:
135
158
  if not ctx.page_formatter:
136
159
  continue
@@ -148,10 +171,10 @@ async def start_command_loop(commands, ctx, histfile, histfile_size):
148
171
 
149
172
 
150
173
  async def start():
151
- ctx = get_context()
174
+ ctx = await get_context()
152
175
 
153
176
  loop = asyncio.get_running_loop()
154
- commands = Commands(loop=loop, format=Format.rich)
177
+ commands = CLICommands(loop=loop, format=Format.rich)
155
178
  if len(sys.argv) == 1:
156
179
  ctx.per_page = 20
157
180
  await start_command_loop(commands, ctx, histfile, histfile_size)
@@ -1,18 +1,17 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.5
2
2
  Name: dronefly-cli
3
- Version: 0.3.0.dev0
3
+ Version: 0.3.2.dev1
4
4
  Summary: Dronefly command-line interface
5
- License: AGPL-3.0-or-later
6
- 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+)
5
+ Author-email: Ben Armstrong <synrg@debian.org>
6
+ License-Expression: AGPL-3.0-or-later
7
+ License-File: LICENSE
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: dronefly-core (==0.5.0.dev0)
14
- Requires-Dist: pyreadline3 (>=3.4.1,<4.0.0)
15
- Requires-Dist: rich (>=13.2,<14.0)
11
+ Requires-Python: <3.13,>=3.11
12
+ Requires-Dist: dronefly-core==0.5.4.dev2
13
+ Requires-Dist: pyreadline3<4,>=3.4.1
14
+ Requires-Dist: rich<15,>=13.2
16
15
  Description-Content-Type: text/markdown
17
16
 
18
17
  # Dronefly command-line client
@@ -21,17 +20,21 @@ The dronefly-cli command-line client will provide a standalone text user
21
20
  interface that can perform a usable subset of Dronefly Discord bot's
22
21
  capabilities, built solely with Dronefly core.
23
22
 
24
- # Installation with poetry
23
+ # Installation
25
24
 
26
- There are no releases of dronefly-cli yet. For now, this will get you started:
25
+ The fastest and most reliable way to get up and running with `dronefly-cli` is
26
+ with `uvx`:
27
+
28
+ 1. First install `uv`: https://docs.astral.sh/uv
29
+ 2. Run it with `uvx`:
27
30
 
28
31
  ```sh
29
- $ pip install git+https://github.com/dronefly-garden/dronefly-cli
30
- $ dronefly
32
+ $ uvx --from dronefly-cli dronefly
31
33
  ```
32
34
 
33
- If all went well, you should arrive at a Dronefly `(=)` prompt where you can test
34
- it with the `taxon` command to look up taxa by name. For example:
35
+ If all went well, it will fetch any dependencies, initialize the environment,
36
+ and run the `dronefly` cli. You should arrive at a Dronefly `(=)` prompt where
37
+ you can test it with the `taxon` command to look up taxa by name. For example:
35
38
 
36
39
  $\tt\textcolor{gold}{(=)}$ taxon picoides pubescens \
37
40
  [*Dryobates pubescens* (Downy Woodpecker)](https://www.inaturalist.org/taxa/792988-Dryobates-pubescens) (~~Picoides pubescens~~) \
@@ -68,4 +71,3 @@ bot's core components.
68
71
  Dronefly Discord bot brings [iNaturalist](https://www.inaturalist.org) taxa,
69
72
  observations, and other data from the site into conversations on the
70
73
  [Discord](https://discord.com) chat platform.
71
-
@@ -0,0 +1,7 @@
1
+ dronefly_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ dronefly_cli/main.py,sha256=deQR0_QhsIjCX8Grjh4gLCQ75pj41i544gisNp3dx9o,6505
3
+ dronefly_cli-0.3.2.dev1.dist-info/METADATA,sha256=P-TtznntbNN0JRHeJrQdJ2sBf5IWY16YG8B1_EE4eGw,2805
4
+ dronefly_cli-0.3.2.dev1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
5
+ dronefly_cli-0.3.2.dev1.dist-info/entry_points.txt,sha256=Yl08ShPUhWWabsQffC0__9wE-mPC4cb9TfaQ3WRga2E,52
6
+ dronefly_cli-0.3.2.dev1.dist-info/licenses/LICENSE,sha256=kVXZNqaDhVhOsr1UKj6KzvhCDS8RoKtGWelE5gzv0Nc,55570
7
+ dronefly_cli-0.3.2.dev1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.1
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ dronefly = dronefly_cli.main:main
@@ -1,6 +0,0 @@
1
- dronefly_cli/main.py,sha256=Crx5CfYU9ukArsvwd0HOMxSxJ29d6sW5Y8qhzitFrNA,5537
2
- dronefly_cli-0.3.0.dev0.dist-info/LICENSE,sha256=kVXZNqaDhVhOsr1UKj6KzvhCDS8RoKtGWelE5gzv0Nc,55570
3
- dronefly_cli-0.3.0.dev0.dist-info/METADATA,sha256=3MwlaXf-Wh5S9CXkpeYrJAagJGegpq9gkGytq98opow,2771
4
- dronefly_cli-0.3.0.dev0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
5
- dronefly_cli-0.3.0.dev0.dist-info/entry_points.txt,sha256=jpxRbGThxnlnFIhMpg-wI52emyjfDi_CgeQpIPUn-aM,51
6
- dronefly_cli-0.3.0.dev0.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- [console_scripts]
2
- dronefly=dronefly_cli.main:main
3
-