dart-tools 0.7.0__py3-none-any.whl → 0.7.2__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.

Potentially problematic release.


This version of dart-tools might be problematic. Click here for more details.

dart/dart.py CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env python3
1
+ #!/usr/bin/env uv run python3
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  """A CLI to interact with the Dart web app."""
@@ -19,7 +19,7 @@ from collections import defaultdict
19
19
  from datetime import timezone
20
20
  from functools import wraps
21
21
  from importlib.metadata import version
22
- from typing import Callable, NoReturn, TypeVar
22
+ from typing import Callable, NoReturn, TypeVar, Union
23
23
  from webbrowser import open_new_tab
24
24
 
25
25
  import dateparser
@@ -27,8 +27,6 @@ import httpx
27
27
  import platformdirs
28
28
  from pick import pick
29
29
 
30
- from dart.generated.types import Response
31
-
32
30
  from .exception import DartException
33
31
  from .generated import Client, api
34
32
  from .generated.models import (
@@ -54,7 +52,7 @@ from .generated.models import (
54
52
  WrappedTaskCreate,
55
53
  WrappedTaskUpdate,
56
54
  )
57
- from .generated.types import UNSET, Unset
55
+ from .generated.types import UNSET, Response, Unset
58
56
 
59
57
  _APP = "dart-tools"
60
58
  _PROG = "dart"
@@ -66,7 +64,7 @@ _HOST_MAP = {"prod": _PROD_HOST, "stag": _STAG_HOST, "dev": _DEV_HOST}
66
64
 
67
65
  # Service commands
68
66
  _LOGIN_CMD = "login"
69
- _SET_HOST_CMD = "sethost"
67
+ _SET_HOST_CMD = "host-set"
70
68
  _VERSION_CMD = "--version"
71
69
  # Task commands
72
70
  _CREATE_TASK_CMD = "task-create"
@@ -131,7 +129,7 @@ def _make_id() -> str:
131
129
  return "".join(random.choices(_ID_CHARS, k=12))
132
130
 
133
131
 
134
- def trim_slug_str(s: str, length: int, max_under: int | None = None) -> str:
132
+ def trim_slug_str(s: str, length: int, max_under: Union[int, None] = None) -> str:
135
133
  max_under = max_under if max_under is not None else length // 6
136
134
  if len(s) <= length:
137
135
  return s
@@ -141,7 +139,7 @@ def trim_slug_str(s: str, length: int, max_under: int | None = None) -> str:
141
139
  return s[:length]
142
140
 
143
141
 
144
- def slugify_str(s: str, lower: bool = False, trim_kwargs: dict | None = None) -> str:
142
+ def slugify_str(s: str, lower: bool = False, trim_kwargs: Union[dict, None] = None) -> str:
145
143
  lowered = s.lower() if lower else s
146
144
  formatted = _NON_ALPHANUM_RE.sub("-", lowered.replace("'", ""))
147
145
  formatted = _REPEATED_DASH_RE.sub("-", formatted).strip("-")
@@ -205,7 +203,7 @@ def _handle_request_errors(fn: Callable) -> Callable:
205
203
  except DartException as ex:
206
204
  _dart_exit(ex)
207
205
  except (httpx.TimeoutException, httpx.RequestError, httpx.ConnectError) as ex:
208
- _dart_exit(f"Failed to execute API call. Reason: {ex}.")
206
+ _dart_exit(f"Failed to execute API call: {ex}.")
209
207
 
210
208
  return wrapper
211
209
 
@@ -276,7 +274,7 @@ class Dart:
276
274
  def get_client_id(self) -> str:
277
275
  return self._config.client_id
278
276
 
279
- def get_auth_token(self) -> str | None:
277
+ def get_auth_token(self) -> Union[str, None]:
280
278
  result = self._config.get(_AUTH_TOKEN_KEY)
281
279
  if result is not None:
282
280
  return result
@@ -456,7 +454,7 @@ def _auth_failure_exit() -> NoReturn:
456
454
  _dart_exit(
457
455
  f"Not logged in, run\n\n {_PROG} {_LOGIN_CMD}\n\nto log in."
458
456
  if _is_cli
459
- else "Not logged in, either run dart.login(token) or save the token into the DART_TOKEN environment variable."
457
+ else "Not logged in, either run\n\n dart.login(token)\n\nor save the token into the DART_TOKEN environment variable."
460
458
  )
461
459
 
462
460
 
@@ -492,7 +490,7 @@ def is_logged_in(should_raise: bool = False) -> bool:
492
490
 
493
491
  if not result and should_raise:
494
492
  _auth_failure_exit()
495
- _log(f"You are {'' if result else 'not '}logged in")
493
+ _log(f"You are{'' if result else ' not'} logged in")
496
494
  return result
497
495
 
498
496
 
@@ -555,7 +553,7 @@ def begin_task() -> bool:
555
553
  return True
556
554
 
557
555
 
558
- def _normalize_priority(priority_int: int | None | Unset) -> str | None | Unset:
556
+ def _normalize_priority(priority_int: Union[int, None, Unset]) -> Union[str, None, Unset]:
559
557
  if priority_int in (None, UNSET):
560
558
  return priority_int
561
559
 
@@ -565,13 +563,13 @@ def _normalize_priority(priority_int: int | None | Unset) -> str | None | Unset:
565
563
  return _PRIORITY_MAP[priority_int]
566
564
 
567
565
 
568
- def _get_due_at_from_str_arg(due_at_str: str | None | Unset) -> str | None | Unset:
566
+ def _get_due_at_from_str_arg(due_at_str: Union[str, None, Unset]) -> Union[str, None, Unset]:
569
567
  if due_at_str in (None, UNSET):
570
568
  return due_at_str
571
569
 
572
570
  due_at = dateparser.parse(due_at_str)
573
571
  if not due_at:
574
- _dart_exit(f"Could not parse due date '{due_at_str}'.")
572
+ _dart_exit(f"Could not parse due date: {due_at_str}.")
575
573
  due_at = due_at.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc).isoformat()
576
574
 
577
575
  return due_at
@@ -580,13 +578,13 @@ def _get_due_at_from_str_arg(due_at_str: str | None | Unset) -> str | None | Uns
580
578
  def create_task(
581
579
  title: str,
582
580
  *,
583
- dartboard_title: str | Unset = UNSET,
584
- status_title: str | Unset = UNSET,
585
- assignee_emails: list[str] | Unset = UNSET,
586
- tag_titles: list[str] | Unset = UNSET,
587
- priority_int: int | None | Unset = UNSET,
588
- size_int: int | None | Unset = UNSET,
589
- due_at_str: str | None | Unset = UNSET,
581
+ dartboard_title: Union[str, Unset] = UNSET,
582
+ status_title: Union[str, Unset] = UNSET,
583
+ assignee_emails: Union[list[str], Unset] = UNSET,
584
+ tag_titles: Union[list[str], Unset] = UNSET,
585
+ priority_int: Union[int, None, Unset] = UNSET,
586
+ size_int: Union[int, None, Unset] = UNSET,
587
+ due_at_str: Union[str, None, Unset] = UNSET,
590
588
  should_begin: bool = False,
591
589
  ) -> Task:
592
590
  dart = Dart()
@@ -603,7 +601,7 @@ def create_task(
603
601
  )
604
602
  )
605
603
  task = dart.create_task(task_create).item
606
- _log(f"Created task (ID: {task.id}) {task.title} at {task.html_url}")
604
+ _log(f"Created task\n\n {task.title}\n {task.html_url}\n ID: {task.id}\n")
607
605
 
608
606
  if should_begin:
609
607
  user = dart.get_config().user
@@ -616,14 +614,14 @@ def create_task(
616
614
  def update_task(
617
615
  id: str,
618
616
  *,
619
- title: Unset | str = UNSET,
620
- dartboard_title: str | Unset = UNSET,
621
- status_title: str | Unset = UNSET,
622
- assignee_emails: list[str] | Unset = UNSET,
623
- tag_titles: list[str] | Unset = UNSET,
624
- priority_int: int | None | Unset = UNSET,
625
- size_int: int | None | Unset = UNSET,
626
- due_at_str: str | None | Unset = UNSET,
617
+ title: Union[Unset, str] = UNSET,
618
+ dartboard_title: Union[str, Unset] = UNSET,
619
+ status_title: Union[str, Unset] = UNSET,
620
+ assignee_emails: Union[list[str], Unset] = UNSET,
621
+ tag_titles: Union[list[str], Unset] = UNSET,
622
+ priority_int: Union[int, None, Unset] = UNSET,
623
+ size_int: Union[int, None, Unset] = UNSET,
624
+ due_at_str: Union[str, None, Unset] = UNSET,
627
625
  ) -> Task:
628
626
  dart = Dart()
629
627
  task_update = WrappedTaskUpdate(
@@ -641,7 +639,7 @@ def update_task(
641
639
  )
642
640
  task = dart.update_task(id, task_update).item
643
641
 
644
- _log(f"Updated task (ID: {task.id}) {task.title} at {task.html_url}")
642
+ _log(f"Updated task\n\n {task.title}\n {task.html_url}\n ID: {task.id}\n")
645
643
  _log("Done.")
646
644
  return task
647
645
 
@@ -650,7 +648,7 @@ def delete_task(id: str) -> Task:
650
648
  dart = Dart()
651
649
  task = dart.delete_task(id).item
652
650
 
653
- _log(f"Deleted task (ID: {task.id}) {task.title} at {task.html_url}")
651
+ _log(f"Deleted task\n\n {task.title}\n {task.html_url}\n ID: {task.id}\n")
654
652
  _log("Done.")
655
653
  return task
656
654
 
@@ -658,14 +656,14 @@ def delete_task(id: str) -> Task:
658
656
  def create_doc(
659
657
  title: str,
660
658
  *,
661
- folder: str | Unset = UNSET,
662
- text: str | Unset = UNSET,
659
+ folder: Union[str, Unset] = UNSET,
660
+ text: Union[str, Unset] = UNSET,
663
661
  ) -> Doc:
664
662
  dart = Dart()
665
663
  doc_create = WrappedDocCreate(item=DocCreate(title=title, folder=folder, text=text))
666
664
  doc = dart.create_doc(doc_create).item
667
665
 
668
- _log(f"Created doc (ID: {doc.id}) {doc.title} at {doc.html_url}")
666
+ _log(f"Created doc\n\n {doc.title}\n {doc.html_url}\n ID: {doc.id}\n")
669
667
  _log("Done.")
670
668
  return doc
671
669
 
@@ -674,14 +672,14 @@ def update_doc(
674
672
  id: str,
675
673
  *,
676
674
  title: str,
677
- folder: str | Unset = UNSET,
678
- text: str | Unset = UNSET,
675
+ folder: Union[str, Unset] = UNSET,
676
+ text: Union[str, Unset] = UNSET,
679
677
  ) -> Doc:
680
678
  dart = Dart()
681
679
  doc_update = WrappedDocUpdate(item=DocUpdate(id, title=title, folder=folder, text=text))
682
680
  doc = dart.update_doc(id, doc_update).item
683
681
 
684
- _log(f"Updated doc (ID: {doc.id}) {doc.title} at {doc.html_url}")
682
+ _log(f"Updated doc\n\n {doc.title}\n {doc.html_url}\n ID: {doc.id}\n")
685
683
  _log("Done.")
686
684
  return doc
687
685
 
@@ -690,7 +688,7 @@ def delete_doc(id: str) -> Doc:
690
688
  dart = Dart()
691
689
  doc = dart.delete_doc(id).item
692
690
 
693
- _log(f"Deleted doc (ID: {doc.id}) {doc.title} at {doc.html_url}")
691
+ _log(f"Deleted doc\n\n {doc.title}\n {doc.html_url}\n ID: {doc.id}\n")
694
692
  _log("Done.")
695
693
  return doc
696
694
 
@@ -699,7 +697,7 @@ def create_comment(id: str, text: str) -> Comment:
699
697
  dart = Dart()
700
698
  comment_create = WrappedCommentCreate(item=CommentCreate(task_id=id, text=text))
701
699
  comment = dart.create_comment(comment_create).item
702
- _log(f"Created comment (ID: {comment.id}) at {comment.html_url}")
700
+ _log(f"Created comment\n\n {comment.html_url}\n ID: {comment.id}\n")
703
701
  _log("Done.")
704
702
  return comment
705
703
 
@@ -793,7 +791,7 @@ def cli() -> None:
793
791
  metavar=f"{{{metavar}}}",
794
792
  )
795
793
 
796
- set_host_parser = subparsers.add_parser(_SET_HOST_CMD, aliases=["h"])
794
+ set_host_parser = subparsers.add_parser(_SET_HOST_CMD, aliases=["hs"])
797
795
  set_host_parser.add_argument("host", help="the new host: {prod|stag|dev|[URL]}")
798
796
  set_host_parser.set_defaults(func=set_host)
799
797
 
@@ -1,9 +1,16 @@
1
1
  """Contains methods for accessing the API"""
2
-
3
- from .comment import create_comment
4
2
  from .config import get_config
5
- from .dartboard import retrieve_dartboard
6
- from .doc import create_doc, delete_doc, list_docs, retrieve_doc, update_doc
3
+ from .comment import create_comment
7
4
  from .folder import retrieve_folder
8
- from .task import create_task, delete_task, list_tasks, retrieve_task, update_task
5
+ from .dartboard import retrieve_dartboard
6
+ from .task import create_task
7
+ from .task import delete_task
8
+ from .task import update_task
9
+ from .task import retrieve_task
10
+ from .task import list_tasks
9
11
  from .view import retrieve_view
12
+ from .doc import create_doc
13
+ from .doc import delete_doc
14
+ from .doc import update_doc
15
+ from .doc import list_docs
16
+ from .doc import retrieve_doc
@@ -1,5 +1,5 @@
1
1
  from http import HTTPStatus
2
- from typing import Any, Optional, Union, cast
2
+ from typing import Any, Optional, Union
3
3
 
4
4
  import httpx
5
5
 
@@ -20,14 +20,11 @@ def _get_kwargs() -> dict[str, Any]:
20
20
 
21
21
  def _parse_response(
22
22
  *, client: Union[AuthenticatedClient, Client], response: httpx.Response
23
- ) -> Optional[Union[Any, UserSpaceConfiguration]]:
23
+ ) -> Optional[UserSpaceConfiguration]:
24
24
  if response.status_code == 200:
25
25
  response_200 = UserSpaceConfiguration.from_dict(response.json())
26
26
 
27
27
  return response_200
28
- if response.status_code == 400:
29
- response_400 = cast(Any, None)
30
- return response_400
31
28
  if client.raise_on_unexpected_status:
32
29
  raise errors.UnexpectedStatus(response.status_code, response.content)
33
30
  else:
@@ -36,7 +33,7 @@ def _parse_response(
36
33
 
37
34
  def _build_response(
38
35
  *, client: Union[AuthenticatedClient, Client], response: httpx.Response
39
- ) -> Response[Union[Any, UserSpaceConfiguration]]:
36
+ ) -> Response[UserSpaceConfiguration]:
40
37
  return Response(
41
38
  status_code=HTTPStatus(response.status_code),
42
39
  content=response.content,
@@ -48,7 +45,7 @@ def _build_response(
48
45
  def sync_detailed(
49
46
  *,
50
47
  client: Union[AuthenticatedClient, Client],
51
- ) -> Response[Union[Any, UserSpaceConfiguration]]:
48
+ ) -> Response[UserSpaceConfiguration]:
52
49
  """Get user space configuration
53
50
 
54
51
  Get information about the user's space, including all of the possible values that can be provided to
@@ -59,7 +56,7 @@ def sync_detailed(
59
56
  httpx.TimeoutException: If the request takes longer than Client.timeout.
60
57
 
61
58
  Returns:
62
- Response[Union[Any, UserSpaceConfiguration]]
59
+ Response[UserSpaceConfiguration]
63
60
  """
64
61
 
65
62
  kwargs = _get_kwargs()
@@ -74,7 +71,7 @@ def sync_detailed(
74
71
  def sync(
75
72
  *,
76
73
  client: Union[AuthenticatedClient, Client],
77
- ) -> Optional[Union[Any, UserSpaceConfiguration]]:
74
+ ) -> Optional[UserSpaceConfiguration]:
78
75
  """Get user space configuration
79
76
 
80
77
  Get information about the user's space, including all of the possible values that can be provided to
@@ -85,7 +82,7 @@ def sync(
85
82
  httpx.TimeoutException: If the request takes longer than Client.timeout.
86
83
 
87
84
  Returns:
88
- Union[Any, UserSpaceConfiguration]
85
+ UserSpaceConfiguration
89
86
  """
90
87
 
91
88
  return sync_detailed(
@@ -96,7 +93,7 @@ def sync(
96
93
  async def asyncio_detailed(
97
94
  *,
98
95
  client: Union[AuthenticatedClient, Client],
99
- ) -> Response[Union[Any, UserSpaceConfiguration]]:
96
+ ) -> Response[UserSpaceConfiguration]:
100
97
  """Get user space configuration
101
98
 
102
99
  Get information about the user's space, including all of the possible values that can be provided to
@@ -107,7 +104,7 @@ async def asyncio_detailed(
107
104
  httpx.TimeoutException: If the request takes longer than Client.timeout.
108
105
 
109
106
  Returns:
110
- Response[Union[Any, UserSpaceConfiguration]]
107
+ Response[UserSpaceConfiguration]
111
108
  """
112
109
 
113
110
  kwargs = _get_kwargs()
@@ -120,7 +117,7 @@ async def asyncio_detailed(
120
117
  async def asyncio(
121
118
  *,
122
119
  client: Union[AuthenticatedClient, Client],
123
- ) -> Optional[Union[Any, UserSpaceConfiguration]]:
120
+ ) -> Optional[UserSpaceConfiguration]:
124
121
  """Get user space configuration
125
122
 
126
123
  Get information about the user's space, including all of the possible values that can be provided to
@@ -131,7 +128,7 @@ async def asyncio(
131
128
  httpx.TimeoutException: If the request takes longer than Client.timeout.
132
129
 
133
130
  Returns:
134
- Union[Any, UserSpaceConfiguration]
131
+ UserSpaceConfiguration
135
132
  """
136
133
 
137
134
  return (
@@ -30,6 +30,9 @@ def _parse_response(
30
30
  if response.status_code == 400:
31
31
  response_400 = cast(Any, None)
32
32
  return response_400
33
+ if response.status_code == 404:
34
+ response_404 = cast(Any, None)
35
+ return response_404
33
36
  if client.raise_on_unexpected_status:
34
37
  raise errors.UnexpectedStatus(response.status_code, response.content)
35
38
  else:
@@ -30,6 +30,9 @@ def _parse_response(
30
30
  if response.status_code == 400:
31
31
  response_400 = cast(Any, None)
32
32
  return response_400
33
+ if response.status_code == 404:
34
+ response_404 = cast(Any, None)
35
+ return response_404
33
36
  if client.raise_on_unexpected_status:
34
37
  raise errors.UnexpectedStatus(response.status_code, response.content)
35
38
  else:
@@ -101,7 +101,9 @@ def sync_detailed(
101
101
  text: Union[Unset, str] = UNSET,
102
102
  title: Union[Unset, str] = UNSET,
103
103
  ) -> Response[PaginatedConciseDocList]:
104
- """
104
+ """List all docs that the user has access to. This will return a list of docs, including the title,
105
+ folder, text and others.
106
+
105
107
  Args:
106
108
  folder (Union[Unset, str]):
107
109
  folder_id (Union[Unset, str]):
@@ -156,7 +158,9 @@ def sync(
156
158
  text: Union[Unset, str] = UNSET,
157
159
  title: Union[Unset, str] = UNSET,
158
160
  ) -> Optional[PaginatedConciseDocList]:
159
- """
161
+ """List all docs that the user has access to. This will return a list of docs, including the title,
162
+ folder, text and others.
163
+
160
164
  Args:
161
165
  folder (Union[Unset, str]):
162
166
  folder_id (Union[Unset, str]):
@@ -206,7 +210,9 @@ async def asyncio_detailed(
206
210
  text: Union[Unset, str] = UNSET,
207
211
  title: Union[Unset, str] = UNSET,
208
212
  ) -> Response[PaginatedConciseDocList]:
209
- """
213
+ """List all docs that the user has access to. This will return a list of docs, including the title,
214
+ folder, text and others.
215
+
210
216
  Args:
211
217
  folder (Union[Unset, str]):
212
218
  folder_id (Union[Unset, str]):
@@ -259,7 +265,9 @@ async def asyncio(
259
265
  text: Union[Unset, str] = UNSET,
260
266
  title: Union[Unset, str] = UNSET,
261
267
  ) -> Optional[PaginatedConciseDocList]:
262
- """
268
+ """List all docs that the user has access to. This will return a list of docs, including the title,
269
+ folder, text and others.
270
+
263
271
  Args:
264
272
  folder (Union[Unset, str]):
265
273
  folder_id (Union[Unset, str]):
@@ -30,6 +30,9 @@ def _parse_response(
30
30
  if response.status_code == 400:
31
31
  response_400 = cast(Any, None)
32
32
  return response_400
33
+ if response.status_code == 404:
34
+ response_404 = cast(Any, None)
35
+ return response_404
33
36
  if client.raise_on_unexpected_status:
34
37
  raise errors.UnexpectedStatus(response.status_code, response.content)
35
38
  else:
@@ -41,6 +41,9 @@ def _parse_response(
41
41
  if response.status_code == 400:
42
42
  response_400 = cast(Any, None)
43
43
  return response_400
44
+ if response.status_code == 404:
45
+ response_404 = cast(Any, None)
46
+ return response_404
44
47
  if client.raise_on_unexpected_status:
45
48
  raise errors.UnexpectedStatus(response.status_code, response.content)
46
49
  else:
@@ -30,6 +30,9 @@ def _parse_response(
30
30
  if response.status_code == 400:
31
31
  response_400 = cast(Any, None)
32
32
  return response_400
33
+ if response.status_code == 404:
34
+ response_404 = cast(Any, None)
35
+ return response_404
33
36
  if client.raise_on_unexpected_status:
34
37
  raise errors.UnexpectedStatus(response.status_code, response.content)
35
38
  else:
@@ -30,6 +30,9 @@ def _parse_response(
30
30
  if response.status_code == 400:
31
31
  response_400 = cast(Any, None)
32
32
  return response_400
33
+ if response.status_code == 404:
34
+ response_404 = cast(Any, None)
35
+ return response_404
33
36
  if client.raise_on_unexpected_status:
34
37
  raise errors.UnexpectedStatus(response.status_code, response.content)
35
38
  else: