generated from infinitelambda/template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support dynamically import module from local path if import_mod… (
#23) Co-authored-by: Dat Nguyen <dat@infinitelambda>
- Loading branch information
Showing
5 changed files
with
124 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!-- markdownlint-disable no-inline-html --> | ||
# Using custom module script | ||
|
||
In case you're NOT ready for publishing the adapters (`diqu-{new-adapter}`), or would like to keep yours privately, it's also supported here. | ||
|
||
This is a basic guideline to let you do that: | ||
|
||
## Understand the module paths | ||
|
||
Check out the our supported [modules](./../common.md#modules), and here is our skeleton: | ||
|
||
```bash | ||
diqu/ | ||
├── diqu/ | ||
├── alerts/ # Alert module | ||
├── packages/ # Package module | ||
├── sources/ # Source module | ||
``` | ||
|
||
Let's say that we want to create an alert custom script, named `your_alert_module.py`. | ||
Now, we must follow the above directory structure and put the script under `(your_repo)/diqu/alerts/` as below: | ||
|
||
```bash | ||
your_repo/ | ||
├── diqu/ | ||
├── alerts/ | ||
├── your_alert_module.py # custom script here | ||
├── your_other_dir/ | ||
``` | ||
|
||
> Follow the same fashion for the `Package` or `Source` module 👍 | ||
## Create your module script | ||
|
||
Check out the [Build a new adapter](./community_adapter.md#3-build-a-new-adapter) for more details on how to structure your code. | ||
|
||
For example: `(your_repo)/diqu/alerts/your_alert_module.py` | ||
|
||
```python | ||
from diqu.utils.log import logger | ||
from diqu.utils.meta import ResultCode | ||
|
||
|
||
def alert(data) -> ResultCode: | ||
# your implementation here | ||
# log any necessary messages e.g. logger.info("✅ Done > My Module") | ||
return ResultCode.SUCCEEDED # return the ResultCode value | ||
``` | ||
|
||
## 3. Run `diqu` with the custom module script | ||
|
||
Run `diqu alert -h` to inspect the usage for using custom: | ||
|
||
- Alert via `--to` option ([docs](./../config/alerts/)) | ||
- Package via `--package` option ([docs](./../config/packages/)) | ||
- Source via `--profile-name` and `--profiles-dir` ([docs](./../config/sources/)) | ||
|
||
For example: `(your_repo)/diqu/alerts/your_alert_module.py` | ||
|
||
```bash | ||
diqu alert --to your_alert_module | ||
``` | ||
|
||
**_Happy Customizing 🚀_** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters