Skip to content

Commit 9db0c5c

Browse files
authored
docs: improve documentation on extensions (#555)
* docs: improve documentation on extensions Also it changes the variable and parameter names: From `dependencies` and `_dependencies` to `packages` and `_packages`. Also modifies docstrings related to the line above. * feat: implement optional additional kwargs for setup()
1 parent 42ab2c0 commit 9db0c5c

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

docs/ext.gettingstarted.rst

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,26 @@ This code shows a basic example for creating the base of a 3rd party:
4747

4848
.. code-block:: python
4949
50-
from interactions.ext import Base, build, Version
51-
50+
from interactions.ext import Base, build, Version, VersionAuthor
51+
52+
version = (
53+
Version(
54+
version="0.0.1",
55+
author=VersionAuthor(
56+
name="name",
57+
email="example@email.com",
58+
),
59+
),
60+
)
5261
data = {
53-
"name": "interactions.ext.name_here"
54-
"description": "We do cool things!"
55-
"version": Version(version="0.0.1")
56-
"link": "https://example.com"
62+
"name": "interactions-name_here",
63+
"description": "We do cool things!",
64+
"version": version
65+
"link": "https://example.com",
66+
"packages": ["interactions.ext.name_here"]
5767
}
58-
class MyThirdParty(Base):
59-
def __init__(self):
60-
super().__init__(**data)
6168
62-
library = MyThirdParty()
63-
build(library)
69+
build(Base(**data))
6470
6571
This configures the base of the library in a rather simple manner: you give the name
6672
and description of the 3rd party, as well as its own official version and link for

interactions/ext/base.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ class Base:
1515
:ivar str description: The description of the library.
1616
:ivar Optional[str] long_description: The long description of the library.
1717
:ivar str link: The repository link or the library.
18-
:ivar Optional[List[str]] _dependencies: The dependencies of the library needed.
18+
:ivar Optional[List[str]] _packages: The packages of the library.
1919
:ivar Optional[List[str]] _requirements: The modules in the library required.
2020
:ivar Dict[str, object] __objects: The objects running under the service.
2121
"""
2222

2323
__slots__ = (
24-
"_dependencies",
24+
"_packages",
2525
"_requirements",
26+
"_kwargs",
2627
"__objects",
2728
"version",
2829
"name",
@@ -38,8 +39,9 @@ def __init__(
3839
link: str,
3940
description: str,
4041
long_description: Optional[str] = None,
41-
dependencies: Optional[List[str]] = None,
42+
packages: Optional[List[str]] = None,
4243
requirements: Optional[List[str]] = None,
44+
**kwargs: Optional[dict],
4345
) -> None:
4446
"""
4547
:param name: The name of the library.
@@ -52,18 +54,21 @@ def __init__(
5254
:type description: str
5355
:param long_description?: The full description of the library, e.g. README. Defaults to ``None``.
5456
:type long_description: Optional[str]
55-
:param dependencies?: The dependencies/other modules needed for library function. Defaults to ``None``.
56-
:type dependencies: Optional[List[str]]
57+
:param packages?: The package(s) of the library. Defaults to ``None``.
58+
:type packages: Optional[List[str]]
5759
:param requirements?: The required modules needed for library function. Defaults to ``None``.
5860
:type requirements: Optional[List[str]]
61+
:param kwargs?: Any other keyword arguments. Defaults to ``None``.
62+
:type kwargs: Optional[dict]
5963
"""
6064
self.version = version
6165
self.name = name
6266
self.link = link
6367
self.description = description
6468
self.long_description = long_description
65-
self._dependencies = dependencies
69+
self._packages = packages
6670
self._requirements = requirements
71+
self._kwargs = kwargs
6772
self.__objects = {}
6873

6974
def _check_service(self, name: str) -> bool:
@@ -136,6 +141,7 @@ def build(base: Base) -> None:
136141
author=base.version.author,
137142
author_email=base.version.author.email,
138143
url=base.link,
139-
packages=[] if base._dependencies is None else base._dependencies,
144+
packages=[] if base._packages is None else base._packages,
140145
install_requires=[] if base._requirements is None else base._requirements,
146+
**base._kwargs,
141147
)

interactions/ext/base.pyi

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ from typing import Dict, List, Optional, Union
22

33
from .version import Version
44

5-
65
class Base:
7-
_dependencies: Optional[List[str]]
6+
_packages: Optional[List[str]]
87
_requirements: Optional[List[str]]
98
__objects: Dict[str, object]
109
version: Version
1110
name: str
1211
description: str
1312
link: str
14-
1513
def __init__(
1614
self,
1715
*,
@@ -20,12 +18,12 @@ class Base:
2018
link: str,
2119
description: str,
2220
long_description: Optional[str] = None,
23-
dependencies: Optional[List[str]] = None,
21+
packages: Optional[List[str]] = None,
2422
requirements: Optional[List[str]] = None,
25-
) -> None:
23+
) -> None: ...
2624
def _check_service(self, name: str) -> bool: ...
2725
def add_service(self, obj: object, name: str) -> Dict[str, object]: ...
2826
def remove_service(self, name: str) -> Union[Exception, bool]: ...
2927
@property
3028
def services(self) -> Dict[str, object]: ...
31-
def build(self) -> None: ...
29+
def build(base: "Base") -> None: ...

0 commit comments

Comments
 (0)