roboherd 0.1.4__py3-none-any.whl → 0.1.6__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 roboherd might be problematic. Click here for more details.

@@ -1,7 +1,7 @@
1
1
  from fast_depends import Depends
2
- from typing import Annotated, Callable, Awaitable
2
+ from typing import Annotated
3
3
 
4
- from almabtrieb import Almabtrieb
4
+ from .common import PublishObject, PublishActivity # noqa
5
5
 
6
6
 
7
7
  def get_raw(data: dict) -> dict:
@@ -41,16 +41,3 @@ Activity = Annotated[dict, Depends(get_activity)]
41
41
 
42
42
  EmbeddedObject = Annotated[dict, Depends(get_embedded_object)]
43
43
  """The embedded object in the activity as parsed by muck_out"""
44
-
45
- Publisher = Callable[[dict], Awaitable[None]]
46
-
47
-
48
- def construct_publish_object(connection: Almabtrieb, actor_id: str) -> Publisher:
49
- async def publish(data: dict):
50
- await connection.trigger("publish_object", {"actor": actor_id, "data": data})
51
-
52
- return publish
53
-
54
-
55
- PublishObject = Annotated[Publisher, Depends(construct_publish_object)]
56
- """Allows one to publish an object as the actor. Assumes cattle_grid has the extension `simple_object_storage` or equivalent"""
@@ -1,8 +1,8 @@
1
1
  """Test documentation"""
2
2
 
3
- from typing import Annotated
3
+ from typing import Annotated, Awaitable, Callable
4
4
  from fast_depends import Depends
5
- from .common import Profile
5
+ from .common import Profile, PublishObject
6
6
 
7
7
  try:
8
8
  from bovine.activitystreams import factories_for_actor_object
@@ -39,3 +39,29 @@ ActivityFactory = Annotated[BovineActivityFactory, Depends(get_activity_factory)
39
39
 
40
40
  ObjectFactory = Annotated[BovineObjectFactory, Depends(get_object_factory)] # type: ignore
41
41
  """The object factory of type [bovine.activitystreams.object_factory.ObjectFactory][]"""
42
+
43
+
44
+ try:
45
+ import markdown
46
+
47
+ def get_markdown_poster( # type: ignore
48
+ object_factory: ObjectFactory, publish_object: PublishObject
49
+ ):
50
+ async def publish_markdown(message: str):
51
+ content = markdown.markdown(message)
52
+ note = object_factory.note(content=content).as_public().build() # type: ignore
53
+ await publish_object(note)
54
+
55
+ return publish_markdown
56
+
57
+ except ImportError:
58
+
59
+ def get_markdown_poster() -> None:
60
+ raise ImportError("bovine not installed")
61
+
62
+
63
+ MarkdownPublisher = Callable[[str], Awaitable[None]]
64
+ """Type of the markdown publisher"""
65
+
66
+ MarkdownPoster = Annotated[MarkdownPublisher, Depends(get_markdown_poster)] # type: ignore
67
+ """A function that takes a markdown string and posts it as the content of a note"""
@@ -1,14 +1,43 @@
1
1
  from fast_depends import Depends
2
- from typing import Annotated
2
+ from typing import Annotated, Callable, Awaitable
3
+
4
+ from almabtrieb import Almabtrieb
5
+
3
6
 
4
7
  from roboherd.cow import RoboCow
5
8
 
6
9
 
7
10
  def get_profile(cow: RoboCow) -> dict:
8
- if cow.profile is None:
11
+ if cow.internals.profile is None:
9
12
  raise ValueError("Cow has no profile")
10
- return cow.profile
13
+ return cow.internals.profile
11
14
 
12
15
 
13
16
  Profile = Annotated[dict, Depends(get_profile)]
14
17
  """The profile of the cow"""
18
+
19
+
20
+ Publisher = Callable[[dict], Awaitable[None]]
21
+ """Type returned by the publishing functions"""
22
+
23
+
24
+ def construct_publish_object(connection: Almabtrieb, actor_id: str) -> Publisher:
25
+ async def publish(data: dict):
26
+ await connection.trigger("publish_object", {"actor": actor_id, "data": data})
27
+
28
+ return publish
29
+
30
+
31
+ def construct_publish_activity(connection: Almabtrieb, actor_id: str) -> Publisher:
32
+ async def publish(data: dict):
33
+ await connection.trigger("publish_activity", {"actor": actor_id, "data": data})
34
+
35
+ return publish
36
+
37
+
38
+ PublishObject = Annotated[Publisher, Depends(construct_publish_object)]
39
+ """Allows one to publish an object as the actor. Assumes cattle_grid has the extension `simple_object_storage` or equivalent"""
40
+
41
+
42
+ PublishActivity = Annotated[Publisher, Depends(construct_publish_activity)]
43
+ """Allows one to publish an activity as the actor. Assumes cattle_grid has the extension `simple_object_storage` or equivalent"""
roboherd/cow/__init__.py CHANGED
@@ -25,17 +25,8 @@ class CronEntry:
25
25
 
26
26
 
27
27
  @dataclass
28
- class RoboCow:
29
- information: Information = field(
30
- metadata=dict(description="Information about the cow")
31
- )
32
-
33
- auto_follow: bool = field(
34
- default=True,
35
- metadata=dict(
36
- description="""Whether to automatically accept follow requests"""
37
- ),
38
- )
28
+ class RoboCowInternals:
29
+ """Internal data for the cow"""
39
30
 
40
31
  profile: dict | None = field(
41
32
  default=None,
@@ -69,6 +60,27 @@ class RoboCow:
69
60
 
70
61
  startup_routine: Callable | None = None
71
62
 
63
+ base_url: str | None = field(default=None)
64
+
65
+
66
+ @dataclass
67
+ class RoboCow:
68
+ information: Information = field(
69
+ metadata=dict(description="Information about the cow")
70
+ )
71
+
72
+ auto_follow: bool = field(
73
+ default=True,
74
+ metadata=dict(
75
+ description="""Whether to automatically accept follow requests"""
76
+ ),
77
+ )
78
+
79
+ internals: RoboCowInternals = field(
80
+ default_factory=RoboCowInternals,
81
+ metadata=dict(description="Internal data for the cow"),
82
+ )
83
+
72
84
  def action(self, action: str = "*", activity_type: str = "*"):
73
85
  """Adds a handler for an event. Use "*" as a wildcard.
74
86
 
@@ -90,15 +102,15 @@ class RoboCow:
90
102
 
91
103
  def inner(func):
92
104
  config.func = func
93
- self.handlers.add_handler(config, func)
94
- self.handler_configuration.append(config)
105
+ self.internals.handlers.add_handler(config, func)
106
+ self.internals.handler_configuration.append(config)
95
107
  return func
96
108
 
97
109
  return inner
98
110
 
99
111
  def cron(self, crontab):
100
112
  def inner(func):
101
- self.cron_entries.append(CronEntry(crontab, func))
113
+ self.internals.cron_entries.append(CronEntry(crontab, func))
102
114
 
103
115
  return func
104
116
 
@@ -119,7 +131,7 @@ class RoboCow:
119
131
  action="incoming",
120
132
  activity_type="*",
121
133
  )
122
- self.handlers.add_handler(config, func)
134
+ self.internals.handlers.add_handler(config, func)
123
135
  return func
124
136
 
125
137
  def incoming_create(self, func):
@@ -137,79 +149,57 @@ class RoboCow:
137
149
  config = HandlerConfiguration(
138
150
  action="incoming", activity_type="Create", func=func
139
151
  )
140
- self.handler_configuration.append(config)
141
- self.handlers.add_handler(config, func)
152
+ self.internals.handler_configuration.append(config)
153
+ self.internals.handlers.add_handler(config, func)
142
154
  return func
143
155
 
144
156
  def startup(self, func):
145
157
  """Adds a startup routine to be run when the cow is started."""
146
158
 
147
- self.startup_routine = func
159
+ self.internals.startup_routine = func
148
160
 
149
161
  def needs_update(self):
150
162
  """Checks if the cow needs to be updated"""
151
- if self.profile is None:
163
+ if self.internals.profile is None:
152
164
  return True
153
165
 
154
- if self.information.name != self.profile.get("name"):
166
+ if self.information.name != self.internals.profile.get("name"):
155
167
  return True
156
168
 
157
- if self.information.description != self.profile.get("summary"):
169
+ if self.information.description != self.internals.profile.get("summary"):
158
170
  return True
159
171
 
160
172
  return False
161
173
 
162
- def update_data(self):
163
- """
164
- Returns the update_actor message to send to cattle_grid
165
-
166
- ```pycon
167
- >>> info = Information(handle="moocow", name="name", description="description")
168
- >>> cow = RoboCow(information=info, actor_id="http://host.example/actor/1")
169
- >>> cow.update_data()
170
- {'actor': 'http://host.example/actor/1',
171
- 'profile': {'name': 'name',
172
- 'summary': 'description'},
173
- 'automaticallyUpdateFollowers': True}
174
-
175
- ```
176
- """
177
- return {
178
- "actor": self.actor_id,
179
- "profile": {
180
- "name": self.information.name,
181
- "summary": self.information.description,
182
- },
183
- "automaticallyUpdateFollowers": self.auto_follow,
184
- }
185
-
186
174
  async def run_startup(self, connection: Almabtrieb):
187
175
  """Runs when the cow is birthed"""
188
176
 
189
- if self.profile is None:
190
- if not self.actor_id:
177
+ if self.internals.profile is None:
178
+ if not self.internals.actor_id:
191
179
  raise ValueError("Actor ID is not set")
192
- result = await connection.fetch(self.actor_id, self.actor_id)
180
+ result = await connection.fetch(
181
+ self.internals.actor_id, self.internals.actor_id
182
+ )
193
183
  if not result.data:
194
184
  raise ValueError("Could not retrieve profile")
195
- self.profile = result.data
185
+ self.internals.profile = result.data
196
186
 
197
- if self.cron_entries:
187
+ if self.internals.cron_entries:
198
188
  frequency = ", ".join(
199
- get_description(entry.crontab) for entry in self.cron_entries
189
+ get_description(entry.crontab) for entry in self.internals.cron_entries
200
190
  )
201
191
  self.information.frequency = frequency
202
192
 
203
- update = determine_profile_update(self.information, self.profile)
193
+ update = determine_profile_update(self.information, self.internals.profile)
204
194
 
205
195
  if update:
206
196
  logger.info("Updating profile for %s", self.information.handle)
207
197
 
208
198
  await connection.trigger("update_actor", update)
209
199
 
210
- if self.startup_routine:
211
- await inject(self.startup_routine)(
212
- cow=self,
213
- connection=connection,
214
- actor_id=self.actor_id,
215
- )
200
+ if self.internals.startup_routine:
201
+ await inject(self.internals.startup_routine)(
202
+ cow=self, # type:ignore
203
+ connection=connection, # type:ignore
204
+ actor_id=self.internals.actor_id, # type:ignore
205
+ ) # type:ignore
roboherd/cow/const.py ADDED
@@ -0,0 +1,6 @@
1
+ default_icon = {
2
+ "mediaType": "image/png",
3
+ "type": "Image",
4
+ "url": "https://dev.bovine.social/assets/bull-horns.png",
5
+ }
6
+ """The default icon to be used"""
roboherd/cow/profile.py CHANGED
@@ -24,6 +24,9 @@ def profile_part_needs_update(information: Information, profile: dict) -> bool:
24
24
  if information.type != profile.get("type"):
25
25
  return True
26
26
 
27
+ if information.icon != profile.get("icon"):
28
+ return True
29
+
27
30
  return False
28
31
 
29
32
 
@@ -110,6 +113,7 @@ def determine_profile_update(information: Information, profile: dict) -> dict |
110
113
  "type": information.type,
111
114
  "name": information.name,
112
115
  "summary": information.description,
116
+ "icon": information.icon,
113
117
  }
114
118
 
115
119
  actions = determine_actions(information, profile)
roboherd/cow/test_init.py CHANGED
@@ -27,7 +27,8 @@ def test_needs_update(name, summary, profile, expected):
27
27
  name=name,
28
28
  description=summary,
29
29
  )
30
- cow = RoboCow(information=info, profile=profile)
30
+ cow = RoboCow(information=info)
31
+ cow.internals.profile = profile
31
32
 
32
33
  assert cow.needs_update() == expected
33
34
 
@@ -40,13 +41,13 @@ def test_cron():
40
41
  async def test_func():
41
42
  pass
42
43
 
43
- assert len(cow.cron_entries) == 1
44
+ assert len(cow.internals.cron_entries) == 1
44
45
 
45
46
 
46
47
  async def test_startup():
47
48
  info = Information(handle="testcow")
48
49
  cow = RoboCow(information=info)
49
- cow.profile = {"id": "http://host.test/actor/cow"}
50
+ cow.internals.profile = {"id": "http://host.test/actor/cow"}
50
51
  mock = AsyncMock()
51
52
 
52
53
  cow.startup(mock)
@@ -1,7 +1,7 @@
1
1
  import pytest
2
2
 
3
3
  from .types import Information, MetaInformation
4
-
4
+ from .const import default_icon
5
5
  from .profile import determine_profile_update
6
6
 
7
7
 
@@ -14,6 +14,7 @@ from .profile import determine_profile_update
14
14
  ],
15
15
  )
16
16
  def test_determine_profile_update_no_update(info_params, profile):
17
+ profile["icon"] = default_icon
17
18
  info = Information(**info_params)
18
19
 
19
20
  assert determine_profile_update(info, profile) is None
@@ -27,13 +28,22 @@ def test_determine_profile_update():
27
28
 
28
29
  assert result == {
29
30
  "actor": "http://host.test/actor/1",
30
- "profile": {"type": "Service", "name": "name", "summary": "description"},
31
+ "profile": {
32
+ "type": "Service",
33
+ "name": "name",
34
+ "summary": "description",
35
+ "icon": default_icon,
36
+ },
31
37
  }
32
38
 
33
39
 
34
40
  def test_determine_profile_update_author():
35
41
  info = Information(meta_information=MetaInformation(author="acct:author@host.test"))
36
- profile = {"id": "http://host.test/actor/1", "type": "Service"}
42
+ profile = {
43
+ "id": "http://host.test/actor/1",
44
+ "type": "Service",
45
+ "icon": default_icon,
46
+ }
37
47
 
38
48
  result = determine_profile_update(info, profile)
39
49
 
@@ -47,3 +57,25 @@ def test_determine_profile_update_author():
47
57
  }
48
58
  ],
49
59
  }
60
+
61
+
62
+ def test_profile_update_for_new_preferredUsername():
63
+ info = Information(handle="handle")
64
+ profile = {
65
+ "id": "http://host.test/actor/1",
66
+ "type": "Service",
67
+ "icon": default_icon,
68
+ }
69
+
70
+ result = determine_profile_update(info, profile)
71
+
72
+ assert result == {
73
+ "actor": "http://host.test/actor/1",
74
+ "actions": [
75
+ {
76
+ "action": "add_identifier",
77
+ "identifier": "acct:handle@host.test",
78
+ "primary": True,
79
+ }
80
+ ],
81
+ }
roboherd/cow/types.py CHANGED
@@ -1,5 +1,7 @@
1
1
  from pydantic import BaseModel, Field
2
2
 
3
+ from .const import default_icon
4
+
3
5
 
4
6
  class MetaInformation(BaseModel):
5
7
  """Meta Information about the bot. This includes
@@ -48,6 +50,11 @@ class Information(BaseModel):
48
50
  description="The description of the cow, used as summary of the actor",
49
51
  )
50
52
 
53
+ icon: dict = Field(
54
+ default=default_icon,
55
+ description="The profile image",
56
+ )
57
+
51
58
  frequency: str | None = Field(
52
59
  default=None,
53
60
  examples=["daily"],
@@ -21,7 +21,9 @@ See <a href="https://codeberg.org/helge/roboherd">codeberg.org</a>.""",
21
21
 
22
22
 
23
23
  @moocow.incoming_create
24
- async def on_incoming_create(obj: EmbeddedObject, publisher: PublishObject):
24
+ async def on_incoming_create(
25
+ obj: EmbeddedObject, publisher: PublishObject, actor_id: str
26
+ ):
25
27
  recipient = obj.get("attributedTo")
26
28
 
27
29
  logger.info("Replying to %s", recipient)
@@ -29,7 +31,7 @@ async def on_incoming_create(obj: EmbeddedObject, publisher: PublishObject):
29
31
  obj = {
30
32
  "@context": "https://www.w3.org/ns/activitystreams",
31
33
  "type": "Note",
32
- "attributedTo": moocow.actor_id,
34
+ "attributedTo": actor_id,
33
35
  "to": [recipient],
34
36
  "cc": ["https://www.w3.org/ns/activitystreams#Public"],
35
37
  "content": "moo",
@@ -18,4 +18,10 @@ bot = RoboCow(
18
18
 
19
19
  @bot.startup
20
20
  async def startup(publish_object: PublishObject, object_factory: ObjectFactory):
21
- await publish_object(object_factory.note(content="Booo! 🐦").as_public().build()) # type: ignore
21
+ note = object_factory.note(content="Booo! 🐦").as_public().build() # type: ignore
22
+ await publish_object(note)
23
+
24
+
25
+ # @bot.startup
26
+ # async def startup(poster: MarkdownPoster):
27
+ # await poster("__Booo!__ 🐦")
roboherd/herd/__init__.py CHANGED
@@ -41,12 +41,12 @@ class RoboHerd:
41
41
  cow = cow_config.load()
42
42
  result = await connection.create_actor(
43
43
  name=f"{self.manager.prefix}{cow_config.name}",
44
- base_url=self.base_url,
44
+ base_url=cow.internals.base_url or self.base_url,
45
45
  preferred_username=cow.information.handle,
46
46
  profile={"type": "Service"},
47
47
  automatically_accept_followers=True,
48
48
  )
49
- cow.actor_id = result.get("id")
49
+ cow.internals.actor_id = result.get("id")
50
50
 
51
51
  self.cows.append(cow)
52
52
 
@@ -81,7 +81,7 @@ class RoboHerd:
81
81
 
82
82
  result = []
83
83
  for cow in self.cows:
84
- for cron_entry in cow.cron_entries:
84
+ for cron_entry in cow.internals.cron_entries:
85
85
  result.append((cow, cron_entry))
86
86
 
87
87
  return result
@@ -89,6 +89,6 @@ class RoboHerd:
89
89
  def incoming_handlers(self) -> List[RoboCow]:
90
90
  result = []
91
91
  for cow in self.cows:
92
- if cow.handlers.has_handlers:
92
+ if cow.internals.handlers.has_handlers:
93
93
  result.append(cow)
94
94
  return result
@@ -30,7 +30,7 @@ class HerdManager:
30
30
  cow_config = self.herd_config.for_name(cow_name)
31
31
  if cow_config:
32
32
  cow = cow_config.load()
33
- cow.actor_id = info.id
33
+ cow.internals.actor_id = info.id
34
34
  existing_cows.append(cow)
35
35
 
36
36
  return existing_cows
@@ -1,7 +1,7 @@
1
1
  from dataclasses import dataclass, field
2
2
 
3
3
  from roboherd.cow import RoboCow
4
- from roboherd.util import load_cow
4
+ from .load import load_cow
5
5
 
6
6
 
7
7
  @dataclass
@@ -9,19 +9,26 @@ class CowConfig:
9
9
  name: str = field(metadata={"description": "Name of the cow, must be unique"})
10
10
  module: str
11
11
  attribute: str
12
+ config: dict
12
13
 
13
14
  @staticmethod
14
15
  def from_name_and_dict(name, cow: dict) -> "CowConfig":
15
16
  module, attribute = cow["bot"].split(":")
16
17
 
17
- return CowConfig(
18
- name=name,
19
- module=module,
20
- attribute=attribute,
21
- )
18
+ return CowConfig(name=name, module=module, attribute=attribute, config=cow)
22
19
 
23
20
  def load(self) -> RoboCow:
24
- return load_cow(self.module, self.attribute)
21
+ cow = load_cow(self.module, self.attribute)
22
+
23
+ if "name" in self.config:
24
+ cow.information.name = self.config["name"]
25
+ if "handle" in self.config:
26
+ cow.information.handle = self.config["handle"]
27
+
28
+ if "base_url" in self.config:
29
+ cow.internals.base_url = self.config["base_url"]
30
+
31
+ return cow
25
32
 
26
33
  def __hash__(self):
27
34
  return hash(self.name)
@@ -0,0 +1,15 @@
1
+ import copy
2
+ import importlib
3
+ from importlib import import_module
4
+
5
+ from roboherd.cow import RoboCow
6
+
7
+
8
+ def load_cow(module_name: str, attribute: str) -> RoboCow:
9
+ """Loads a cow from module name and attribute"""
10
+ module = import_module(module_name)
11
+ importlib.reload(module)
12
+
13
+ cow = getattr(module, attribute)
14
+
15
+ return copy.deepcopy(cow)
@@ -38,6 +38,22 @@ def test_from_name_and_dict():
38
38
  assert cow.attribute == "attribute"
39
39
 
40
40
 
41
+ def test_from_name_and_dict_with_new_name():
42
+ name = "cow"
43
+ value = {
44
+ "bot": "roboherd.examples.moocow:moocow",
45
+ "handle": "new_handle",
46
+ "name": "new name",
47
+ }
48
+
49
+ config = CowConfig.from_name_and_dict(name, value)
50
+
51
+ cow = config.load()
52
+
53
+ assert cow.information.name == "new name"
54
+ assert cow.information.handle == "new_handle"
55
+
56
+
41
57
  def test_load_config(test_config):
42
58
  herd = HerdConfig.from_settings(test_config)
43
59
 
@@ -0,0 +1,19 @@
1
+ from roboherd.cow import RoboCow
2
+
3
+ from .load import load_cow
4
+
5
+
6
+ def test_load_cow():
7
+ cow = load_cow("roboherd.examples.moocow", "moocow")
8
+ assert isinstance(cow, RoboCow)
9
+
10
+
11
+ def test_load_cow_can_overwrite_variables():
12
+ one = load_cow("roboherd.examples.moocow", "moocow")
13
+
14
+ one.information.name = "A cow eating watermelons"
15
+
16
+ two = load_cow("roboherd.examples.moocow", "moocow")
17
+
18
+ assert two.information.name == "The mooing cow 🐮"
19
+ assert one.information.name == "A cow eating watermelons"
@@ -26,7 +26,7 @@ class HerdProcessor:
26
26
  async def process_incoming(self, connection):
27
27
  actor_id_to_cow_map = {}
28
28
  for cow in self.incoming_handlers:
29
- actor_id_to_cow_map[cow.actor_id] = cow
29
+ actor_id_to_cow_map[cow.internals.actor_id] = cow
30
30
 
31
31
  async for msg in connection.incoming():
32
32
  actor_id = msg["actor"]
@@ -34,6 +34,6 @@ class HerdProcessor:
34
34
  cow = actor_id_to_cow_map.get(actor_id)
35
35
  logger.info(cow)
36
36
  if cow:
37
- await cow.handlers.handle(
37
+ await cow.internals.handlers.handle(
38
38
  msg, "incoming", connection, actor_id, cow=cow
39
39
  )
@@ -38,7 +38,7 @@ class HerdScheduler:
38
38
  inject(entry.func),
39
39
  trigger=trigger,
40
40
  kwargs={
41
- "actor_id": cow.actor_id,
41
+ "actor_id": cow.internals.actor_id,
42
42
  "connection": self.connection,
43
43
  "cow": cow,
44
44
  },
roboherd/util.py CHANGED
@@ -1,12 +1,9 @@
1
1
  import click
2
2
  import logging
3
- import copy
4
- import importlib
5
- from importlib import import_module
6
- from urllib.parse import parse_qs, urlparse
3
+
4
+ from urllib.parse import urlparse
7
5
  from almabtrieb import Almabtrieb
8
6
 
9
- from roboherd.cow import RoboCow
10
7
 
11
8
  logger = logging.getLogger(__name__)
12
9
 
@@ -46,52 +43,6 @@ def parse_connection_string(connection_string: str) -> dict:
46
43
  }
47
44
 
48
45
 
49
- def load_cow(module_name: str, attribute: str) -> RoboCow:
50
- """Loads a cow from module name and attribute"""
51
- module = import_module(module_name)
52
- importlib.reload(module)
53
-
54
- cow = getattr(module, attribute)
55
-
56
- return copy.deepcopy(cow)
57
-
58
-
59
- def import_cow(name: str) -> RoboCow:
60
- """Imports a cow from a string of the form
61
- `module.name:attribute`. Here attribute should
62
- be of type [roboherd.cow.RoboCow][roboherd.cow.RoboCow].
63
-
64
- ```pycon
65
- >>> cow = import_cow("roboherd.examples.moocow:moocow")
66
- >>> cow.information.handle
67
- 'moocow'
68
-
69
- ```
70
- """
71
- try:
72
- query = None
73
- module_name, attribute = name.split(":")
74
- if "?" in attribute:
75
- attribute, query = attribute.split("?")
76
-
77
- cow = load_cow(module_name, attribute)
78
-
79
- if query:
80
- parsed_query = parse_qs(query)
81
- handle = parsed_query.get("handle", [None])[0]
82
- if handle:
83
- cow.information.handle = handle
84
-
85
- return cow
86
-
87
- except Exception as e:
88
- logger.error("Failed to import cow with name: %s", name)
89
- logger.error("names should have the form module:attribute")
90
- logger.exception(e)
91
-
92
- raise ImportError("Failed to load module")
93
-
94
-
95
46
  def create_connection(ctx):
96
47
  connection_string = ctx.obj["connection_string"]
97
48
  base_url = ctx.obj["base_url"]
@@ -1,7 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: roboherd
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: A Fediverse bot framework
5
+ Project-URL: Documentation, https://bovine.codeberg.page/roboherd/
6
+ Project-URL: Repository, https://codeberg.org/bovine/roboherd
5
7
  Requires-Python: >=3.11
6
8
  Requires-Dist: aiohttp>=3.11.12
7
9
  Requires-Dist: almabtrieb[mqtt]>=0.1.0a1
@@ -14,6 +16,7 @@ Requires-Dist: tomli-w>=1.1.0
14
16
  Requires-Dist: watchfiles>=1.0.4
15
17
  Provides-Extra: bovine
16
18
  Requires-Dist: bovine>=0.5.15; extra == 'bovine'
19
+ Requires-Dist: markdown>=3.7; extra == 'bovine'
17
20
  Description-Content-Type: text/markdown
18
21
 
19
22
  # Roboherd
@@ -0,0 +1,44 @@
1
+ roboherd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ roboherd/__main__.py,sha256=cY4f-39QCDhStJ4gDuuSz46RDFE_AKnu08sTCpQEEV4,2933
3
+ roboherd/register.py,sha256=Gqa5aT2supVJMj7z21btMYRma3_WW0oK5gjZftr048s,976
4
+ roboherd/test_validators.py,sha256=UiFgJkutmXBLjGpdLP2IBYCEf75quwnRHX7Z51G8Xqo,222
5
+ roboherd/util.py,sha256=nrFRtyfvMQ8oXoGDYxmCAXcIN14dWBAPGv0cI_B_TP0,1710
6
+ roboherd/validators.py,sha256=2mc43ZGwFazp4f3B9J4RxZCU4Y_ErSNotib8MnYVtmY,140
7
+ roboherd/annotations/__init__.py,sha256=BrP5UWiVnh8FwmHc6wEY3G69BStidGUpF8uP4Ea5-dg,1140
8
+ roboherd/annotations/bovine.py,sha256=cFLUSFzTulikNjZb1lLq5v4tGjL1i7_dR3H6wimegCg,2322
9
+ roboherd/annotations/common.py,sha256=n5rm8WTgsg116RczKdzm_VoPg1mBk_IMf2V7l8UgWKQ,1351
10
+ roboherd/cow/__init__.py,sha256=MlMvjFbodwZf6vpKlPfIpSn5SHu9IugacSH5ylbySTY,5826
11
+ roboherd/cow/const.py,sha256=fj5nUJUIlcpr1AU2Ur55ToR7iVmYv4UnfdxiQwguv-k,166
12
+ roboherd/cow/handlers.py,sha256=k5Tc1M--wqmZ2EZvzIfID4dp8XE0rN18puMTKkNVjjE,1491
13
+ roboherd/cow/profile.py,sha256=ldeYq50lh97dl50QjOZiGopEbXtCoEsE5QJoXB5XUYU,3330
14
+ roboherd/cow/test_handlers.py,sha256=SwrZZcU_BD2BpJUFg18mFEsyUqu7N81-MkjIaGv7whQ,1673
15
+ roboherd/cow/test_init.py,sha256=bnK8IIbbeS1Y7vJaFg5HzCL6UoZeCl6mo_SAQqJAgQY,1409
16
+ roboherd/cow/test_profile.py,sha256=f7HE0iVgbpuNv6znEqi-4l1o_8UZ9ufQpjSVP7Xf1wc,2160
17
+ roboherd/cow/test_util.py,sha256=8FLRtVdSMmIo6NSpCpB9mS0PwOCpGgUeDAA1q6Gv0P4,430
18
+ roboherd/cow/types.py,sha256=TGXTcPuND7xMly3xFXZyIR7UE3XWyF_MLRuBHWKoFEE,1925
19
+ roboherd/cow/util.py,sha256=ASQn7AnSl5lskECqCyqOKn5BYC8yOces4FK3uNV8010,534
20
+ roboherd/examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
+ roboherd/examples/dev_null.py,sha256=6SZ9wlcawSBqhdq6Zv4xPXH5eKH2g1VaRwv3hSCDucE,308
22
+ roboherd/examples/json_echo.py,sha256=EFqNwaSKs0hTQjKZVatjn6i3O7rQff2GTHnEfpL1ha0,1370
23
+ roboherd/examples/meta.py,sha256=tFhHe-DJn2J13Mm22f-gFm5I8_3uQwLU4mAkrK2xzEM,170
24
+ roboherd/examples/moocow.py,sha256=DMPuR8XBpRRHKXFZM-2_VLYLWx8Iz4OdcE0QTVtYSFs,1097
25
+ roboherd/examples/number.py,sha256=Sj9aYfdtzANUfWVJnoX73zEvDNVcdrr-STZDSwNRHlI,2003
26
+ roboherd/examples/rooster.py,sha256=5_rPGLQTLv1s0cyE6l7WXLum-QLpQZ2p63YBkfrxKFw,596
27
+ roboherd/examples/scarecrow.py,sha256=CgQuI7smKBJdeMiL8fY5SP1itH5GaFRAoX3I3QGF3rw,748
28
+ roboherd/herd/__init__.py,sha256=6jWgYnuJOpXtYS03mdjEgWd0zXv5kj9w9d7K6UsCPbc,3068
29
+ roboherd/herd/builder.py,sha256=MSVPRF0Jsxure9kdyCoYJHQ7nYilGAD0_uQaGQ-rQyE,619
30
+ roboherd/herd/processor.py,sha256=ncXsYfuTRTT_0-K453COF_oAiGBJN0u5eP8NoeZmWik,1042
31
+ roboherd/herd/scheduler.py,sha256=pbWxOo9pnjAoAJhbvaczmSghkp6Y8Zp2HgXZ5zoOnDA,1276
32
+ roboherd/herd/test_herd.py,sha256=sQkzGCWdFveLklhaOJUybtl7odO-QOSDdd-_gan1py8,845
33
+ roboherd/herd/test_scheduler.py,sha256=wLisqRMSl734P_rjbqMNH5WTQKepwihgr7ZC32nEj80,424
34
+ roboherd/herd/types.py,sha256=_EidQbglm0jpsKX1EsL6U2qm_J5wCPhwUi6Avac22Ow,210
35
+ roboherd/herd/manager/__init__.py,sha256=NqOJsp1CdAobjARJGmzvU1ceTW7j2bt0FdRbpM8iFUw,1464
36
+ roboherd/herd/manager/config.py,sha256=VDuxB7GMoZdgSM2i1iG1o-IjtyScsSnO--6PEM8tx9U,1591
37
+ roboherd/herd/manager/load.py,sha256=BoeBID2UGP--sIKwITABQkQv2lMc9Y8pyp7_nleu2bw,351
38
+ roboherd/herd/manager/test_config.py,sha256=CnoqQ_exrpQdBWVoGxSns3HpccqgmhH9mNJIPTCKKAs,1665
39
+ roboherd/herd/manager/test_load.py,sha256=zyu5LIChMfTnxu_tYK63-bSOHYn1K1zUlbDY5DkE3GY,514
40
+ roboherd/herd/manager/test_manager.py,sha256=9pSMaH7zmN-zagYCIBpQcV3Q0sBT7XZSCvsmLVC0rOI,1047
41
+ roboherd-0.1.6.dist-info/METADATA,sha256=DvhOfgjAb92py9-vVqKR0bbsRhx5jau-_DVt_mLB31M,1007
42
+ roboherd-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
43
+ roboherd-0.1.6.dist-info/entry_points.txt,sha256=WebdVUmh8Ot-FupKJY6Du8LuFbmezt9yoy2UICqV3bE,52
44
+ roboherd-0.1.6.dist-info/RECORD,,
roboherd/test_util.py DELETED
@@ -1,24 +0,0 @@
1
- import pytest
2
-
3
- from roboherd.cow import RoboCow
4
-
5
- from .util import import_cow
6
-
7
-
8
- def test_import_cow():
9
- cow = import_cow("roboherd.examples.moocow:moocow")
10
-
11
- assert isinstance(cow, RoboCow)
12
- assert cow.information.handle == "moocow"
13
-
14
-
15
- def test_import_cow_failed():
16
- with pytest.raises(ImportError):
17
- import_cow("robocow:nocow")
18
-
19
-
20
- def test_import_cow_with_handle():
21
- cow = import_cow("roboherd.examples.moocow:moocow?handle=horse")
22
-
23
- assert isinstance(cow, RoboCow)
24
- assert cow.information.handle == "horse"
@@ -1,42 +0,0 @@
1
- roboherd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- roboherd/__main__.py,sha256=cY4f-39QCDhStJ4gDuuSz46RDFE_AKnu08sTCpQEEV4,2933
3
- roboherd/register.py,sha256=Gqa5aT2supVJMj7z21btMYRma3_WW0oK5gjZftr048s,976
4
- roboherd/test_util.py,sha256=Yor_YgXtvK3WnZu6jr7DvNtTLdR9YWHCA5QufHo_w2s,535
5
- roboherd/test_validators.py,sha256=UiFgJkutmXBLjGpdLP2IBYCEf75quwnRHX7Z51G8Xqo,222
6
- roboherd/util.py,sha256=xgOpGwgvj4QY-m687H7EcDPfIF-pFgdmCsYPmeK13to,3064
7
- roboherd/validators.py,sha256=2mc43ZGwFazp4f3B9J4RxZCU4Y_ErSNotib8MnYVtmY,140
8
- roboherd/annotations/__init__.py,sha256=z7Q-NwHtGm35AUcuc4SxmWGFLVQxCFhYNJlzOc2kdOY,1610
9
- roboherd/annotations/bovine.py,sha256=qXkliFVT63BfGn820Bopwd7O41ofP7VbNomxyit4zBg,1494
10
- roboherd/annotations/common.py,sha256=aeoWDEpWdX3llc-CiuifT4A8_Ote29PkELqOkF9Dy5o,314
11
- roboherd/cow/__init__.py,sha256=qS5ztkVa-vza6f-kZyn4fS5LVa4Fu5c083FyBcAEQC4,6051
12
- roboherd/cow/handlers.py,sha256=k5Tc1M--wqmZ2EZvzIfID4dp8XE0rN18puMTKkNVjjE,1491
13
- roboherd/cow/profile.py,sha256=NxnLdQYwOIjzZLu2iYEMMQyTOdUsGpLRe5nIN_jo-14,3223
14
- roboherd/cow/test_handlers.py,sha256=SwrZZcU_BD2BpJUFg18mFEsyUqu7N81-MkjIaGv7whQ,1673
15
- roboherd/cow/test_init.py,sha256=Te-4Z8lPpMlSv99OkzPLMtB607NSOfdRD3EB-6_3n1A,1370
16
- roboherd/cow/test_profile.py,sha256=edWKVL8VmOb8XtE1OQmwDLuw4mcDtxMKBfA9Kbd71qU,1423
17
- roboherd/cow/test_util.py,sha256=8FLRtVdSMmIo6NSpCpB9mS0PwOCpGgUeDAA1q6Gv0P4,430
18
- roboherd/cow/types.py,sha256=p2-7p936mm9E9slGnYbei-pui8FeMCNIuomLHcE7BuE,1790
19
- roboherd/cow/util.py,sha256=ASQn7AnSl5lskECqCyqOKn5BYC8yOces4FK3uNV8010,534
20
- roboherd/examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- roboherd/examples/dev_null.py,sha256=6SZ9wlcawSBqhdq6Zv4xPXH5eKH2g1VaRwv3hSCDucE,308
22
- roboherd/examples/json_echo.py,sha256=EFqNwaSKs0hTQjKZVatjn6i3O7rQff2GTHnEfpL1ha0,1370
23
- roboherd/examples/meta.py,sha256=tFhHe-DJn2J13Mm22f-gFm5I8_3uQwLU4mAkrK2xzEM,170
24
- roboherd/examples/moocow.py,sha256=OkceeaRqkjR31Nue8anHtL_DMqd7finLzs-gUaKsVBo,1083
25
- roboherd/examples/number.py,sha256=Sj9aYfdtzANUfWVJnoX73zEvDNVcdrr-STZDSwNRHlI,2003
26
- roboherd/examples/rooster.py,sha256=5_rPGLQTLv1s0cyE6l7WXLum-QLpQZ2p63YBkfrxKFw,596
27
- roboherd/examples/scarecrow.py,sha256=gLbQFx7Hu0W0H3_d9yi0mAO4drXxBshM8Iwoc-NdrjY,633
28
- roboherd/herd/__init__.py,sha256=nhGfHkuAErP7MDh44IbfsonMd0UKeK8GqaHkEUAsZtc,3012
29
- roboherd/herd/builder.py,sha256=MSVPRF0Jsxure9kdyCoYJHQ7nYilGAD0_uQaGQ-rQyE,619
30
- roboherd/herd/processor.py,sha256=NkROTAPs6ZoYW_0TSDnNkAfos4cTnaFgwtW3wOFSgQY,1022
31
- roboherd/herd/scheduler.py,sha256=fkR-74bFZ73DmlJje_dQSytxnFFLV5hCa067mXdwvXs,1266
32
- roboherd/herd/test_herd.py,sha256=sQkzGCWdFveLklhaOJUybtl7odO-QOSDdd-_gan1py8,845
33
- roboherd/herd/test_scheduler.py,sha256=wLisqRMSl734P_rjbqMNH5WTQKepwihgr7ZC32nEj80,424
34
- roboherd/herd/types.py,sha256=_EidQbglm0jpsKX1EsL6U2qm_J5wCPhwUi6Avac22Ow,210
35
- roboherd/herd/manager/__init__.py,sha256=yDVeSyJ3vIn9RMKR0FlobQA81oOQgdov5VVOIUAMwws,1454
36
- roboherd/herd/manager/config.py,sha256=qfcED9PfzKzDCWaYHefYj8AImcsOFs5daGpJwUrXlV4,1313
37
- roboherd/herd/manager/test_config.py,sha256=YQ-3huCZfHDqt2mdGjLs0ck5-DOkKdjKEzT3uhX0sLk,1293
38
- roboherd/herd/manager/test_manager.py,sha256=9pSMaH7zmN-zagYCIBpQcV3Q0sBT7XZSCvsmLVC0rOI,1047
39
- roboherd-0.1.4.dist-info/METADATA,sha256=55W2-6U-lsE1mibBgc9XaEx1Elo0BEQJTSxCxHWVvN0,830
40
- roboherd-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
41
- roboherd-0.1.4.dist-info/entry_points.txt,sha256=WebdVUmh8Ot-FupKJY6Du8LuFbmezt9yoy2UICqV3bE,52
42
- roboherd-0.1.4.dist-info/RECORD,,