dronefly-cli 0.3.0.dev0__tar.gz → 0.3.2.dev1__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.
@@ -0,0 +1,115 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+ MANIFEST
27
+
28
+ # PyInstaller
29
+ # Usually these files are written by a python script from a template
30
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ .hypothesis/
48
+ .pytest_cache/
49
+
50
+ # Translations
51
+ *.mo
52
+ *.pot
53
+
54
+ # Django stuff:
55
+ *.log
56
+ local_settings.py
57
+ db.sqlite3
58
+
59
+ # Flask stuff:
60
+ instance/
61
+ .webassets-cache
62
+
63
+ # Scrapy stuff:
64
+ .scrapy
65
+
66
+ # Sphinx documentation
67
+ docs/_build/
68
+
69
+ # PyBuilder
70
+ target/
71
+
72
+ # Jupyter Notebook
73
+ .ipynb_checkpoints
74
+
75
+ # pyenv
76
+ .python-version
77
+
78
+ # celery beat schedule file
79
+ celerybeat-schedule
80
+
81
+ # SageMath parsed files
82
+ *.sage.py
83
+
84
+ # Environments
85
+ .env
86
+ .venv
87
+ env/
88
+ venv/
89
+ ENV/
90
+ env.bak/
91
+ venv.bak/
92
+
93
+ # Spyder project settings
94
+ .spyderproject
95
+ .spyproject
96
+
97
+ # Rope project settings
98
+ .ropeproject
99
+
100
+ # mkdocs documentation
101
+ /site
102
+
103
+ # mypy
104
+ .mypy_cache/
105
+
106
+ # api keys
107
+ *.key
108
+
109
+ qgriff.ini
110
+
111
+ # Red Bot V3 stuff
112
+ red_setup_logs
113
+
114
+ # Visual Studio Code stuff
115
+ .vscode/
@@ -0,0 +1,24 @@
1
+ default_language_version:
2
+ python: python3.11
3
+ repos:
4
+ - repo: https://github.com/pre-commit/pre-commit-hooks
5
+ rev: v6.0.0
6
+ hooks:
7
+ - id: check-merge-conflict
8
+ - id: debug-statements
9
+ - repo: https://github.com/PyCQA/flake8
10
+ rev: 7.3.0
11
+ hooks:
12
+ - id: flake8
13
+ additional_dependencies:
14
+ - flake8-pyproject>=1.2.4,<2
15
+ - repo: https://github.com/psf/black
16
+ rev: 26.5.1
17
+ hooks:
18
+ - id: black
19
+ - repo: https://github.com/PyCQA/bandit
20
+ rev: 1.9.4
21
+ hooks:
22
+ - id: bandit
23
+ args: ["-c", "pyproject.toml"]
24
+ additional_dependencies: [ "bandit[toml]" ]
@@ -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
-
@@ -4,17 +4,21 @@ The dronefly-cli command-line client will provide a standalone text user
4
4
  interface that can perform a usable subset of Dronefly Discord bot's
5
5
  capabilities, built solely with Dronefly core.
6
6
 
7
- # Installation with poetry
7
+ # Installation
8
8
 
9
- There are no releases of dronefly-cli yet. For now, this will get you started:
9
+ The fastest and most reliable way to get up and running with `dronefly-cli` is
10
+ with `uvx`:
11
+
12
+ 1. First install `uv`: https://docs.astral.sh/uv
13
+ 2. Run it with `uvx`:
10
14
 
11
15
  ```sh
12
- $ pip install git+https://github.com/dronefly-garden/dronefly-cli
13
- $ dronefly
16
+ $ uvx --from dronefly-cli dronefly
14
17
  ```
15
18
 
16
- If all went well, you should arrive at a Dronefly `(=)` prompt where you can test
17
- it with the `taxon` command to look up taxa by name. For example:
19
+ If all went well, it will fetch any dependencies, initialize the environment,
20
+ and run the `dronefly` cli. You should arrive at a Dronefly `(=)` prompt where
21
+ you can test it with the `taxon` command to look up taxa by name. For example:
18
22
 
19
23
  $\tt\textcolor{gold}{(=)}$ taxon picoides pubescens \
20
24
  [*Dryobates pubescens* (Downy Woodpecker)](https://www.inaturalist.org/taxa/792988-Dryobates-pubescens) (~~Picoides pubescens~~) \
File without changes
@@ -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)
@@ -0,0 +1,66 @@
1
+ [project]
2
+ name = "dronefly-cli"
3
+ version = "0.3.2.dev1"
4
+ description = "Dronefly command-line interface"
5
+ authors = [{ name = "Ben Armstrong", email = "synrg@debian.org" }]
6
+ requires-python = ">=3.11,<3.13"
7
+ readme = "README.md"
8
+ license = "AGPL-3.0-or-later"
9
+ classifiers = [
10
+ "Programming Language :: Python :: 3",
11
+ "Programming Language :: Python :: 3.11",
12
+ "Programming Language :: Python :: 3.12",
13
+ ]
14
+ dependencies = [
15
+ "pyreadline3>=3.4.1,<4",
16
+ "dronefly-core==0.5.4.dev2",
17
+ "rich>=13.2,<15",
18
+ ]
19
+
20
+ [project.scripts]
21
+ dronefly = "dronefly_cli.main:main"
22
+
23
+ [tool.flake8]
24
+ max-line-length = 100
25
+
26
+ [dependency-groups]
27
+ dev = [
28
+ "black>=26.1.0,<27",
29
+ "pytest>=9.0,<10.dev0",
30
+ "pytest-asyncio>=1.4.0,<1.5",
31
+ "pylint>=4.1.3,<5",
32
+ "pre-commit>=4.6.1",
33
+ ]
34
+
35
+ [tool.black]
36
+ target-version = ['py311']
37
+
38
+ [tool.bandit]
39
+ exclude_dirs = ["tests"]
40
+
41
+ [build-system]
42
+ requires = ["hatchling"]
43
+ build-backend = "hatchling.build"
44
+
45
+ [tool.hatch.metadata]
46
+ allow-direct-references = true
47
+
48
+ [tool.hatch.build.targets.wheel]
49
+ packages = ["dronefly_cli"]
50
+
51
+ [tool.uv]
52
+ prerelease = "allow"
53
+
54
+ [tool.uv.sources]
55
+ dronefly-core = { path = "../dronefly-core", editable = true }
56
+ dronefly-cli = { workspace = true }
57
+
58
+ [tool.setuptools]
59
+ packages = ["dronefly_cli"]
60
+
61
+ [tool.setuptools.package-dir]
62
+ "" = "."
63
+
64
+ [uv.tool.build-backend]
65
+ module-name = "dronefly_cli"
66
+ module-root = ""