Contributing Code - HomeMadePy/messages GitHub Wiki

Thank you for your interest. All contributions are welcome!

Contributing Code

Please join the Messages Slack Team to discuss adding to the project so duplicate work is not created by other contributors.

Getting Started

  • Fork the repository
  • Create a virtualenv and install poetry
  • Install messages in development mode
  • Install test dependencies
  • Run unit tests and ensure all pass
    • Post a bug report if any fail
  • Create a branch for your contributions
$ git clone https://github.com/trp07/messages.git
$ cd messages/
$ pip install poetry
$ poetry install
$ pytest -v
$ git branch "yourBranchName"
$ git checkout "yourBranchName"

Code Style/Formatting

  • Use black for code formatting

Testing Guidelines

  • Use pytest for unit test
  • Use pytest-mock for mocking
  • All added features must be tested
  • Ensure all tests pass before committing code
  • Feel free to reach out for help with testing
$ cd messages/
$ pytest -v
  • Bug fixes must include added tests

Adding a Message class

  • Create a new module for the type of message or add it to an existing module if that message type is related (See slack.py)
  • Each message should import the Message base class from _interface.py so that it inherits some required features and to enforce some method inclusion
  • Design the dunder init method to be somewhat consistent with the other message classes
    • All credentials will be added to an auth param in the form of a string or tuple of multiple items
    • At the end of the init method add the guard clause to check the config file (see example below)
  • Add the required send and send_async methods
  • Add any additional methods required for that message type
  • Add pertinent information to the CONFIG global var in the _config.py module so that your new message type can be added to the config file
  • Add an entry in the init.py module for your new message class
  • Add a new command in the cli.py module to invoke your message at the CLI
"""Your new message class."""

from ._config import check_config_file
from ._eventloop import MESSAGELOOP
from ._exceptions import MessageSendError
from ._interface import Message
from ._utils import credential_property
from ._utils import validate_property
from ._utils import timestamp


class YourNewMsg(Message):
    auth = credential_property('auth')

    def __init__(
        self,
        from_=None,
        to=None,
        auth=None,
        verbose=False, 
        profile=None..., # and so forth for other params
     ):

        self.from_ = from_
        self.to = to
        self.auth = auth
        self.verbose = verbose
        self.profile = profile

        if self.profile:
            check_config_file(self)

       # anything else needed to complete your __init__ method


    def __str__(self):
        # create a str method for self.verbose output


    def send(self):
        # add a send method


    def send_async(self):
        # add a send_async method
        """Send message asynchronously."""
        MESSAGELOOP.add_message(self)