diff --git a/Makefile b/Makefile index 9b0c384..488ace8 100644 --- a/Makefile +++ b/Makefile @@ -69,12 +69,19 @@ tag-release: check-origin-remote git tag -a $(VERSION) -m "Release $(VERSION)" git push origin $(VERSION) -release: dist tag-release ## package and upload for public release - gpg --detach-sign -a dist/layabout-*.tar.gz - twine upload dist/* +sign-artifacts: + # This doesn't have help text because it's intended to be a release helper. + # Apparently gpg isn't good with batching detached signatures... + # https://lists.gnupg.org/pipermail/gnupg-users/2002-August/014602.html + for artifact in dist/*; do \ + gpg2 --detach-sign -a $$artifact; \ + done dist: clean ## build source and wheel packages python3 setup.py sdist bdist_wheel +release: dist sign-artifacts tag-release ## package and upload for public release + twine upload dist/* + install: clean ## install the package into the active Python's site-packages python3 setup.py install diff --git a/README.rst b/README.rst index 1175f2c..4f6705b 100644 --- a/README.rst +++ b/README.rst @@ -54,7 +54,7 @@ Layabout for e in events) if __name__ == '__main__': - # Automatically load app token from $SLACK_API_TOKEN and run! + # Automatically load app token from $LAYABOUT_TOKEN and run! app.run(until=someone_leaves) print("Looks like someone left a channel!") diff --git a/docs/index.rst b/docs/index.rst index b26e030..dedd019 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -58,7 +58,7 @@ Release v\ |release|. (:ref:`Changelog `) for e in events) if __name__ == '__main__': - # Automatically load app token from $SLACK_API_TOKEN and run! + # Automatically load app token from $LAYABOUT_TOKEN and run! app.run(until=someone_leaves) print("Looks like someone left a channel!") diff --git a/examples/simple/example.py b/examples/simple/example.py index 03dcacf..4f2c06f 100644 --- a/examples/simple/example.py +++ b/examples/simple/example.py @@ -11,7 +11,7 @@ def print_all(slack, event): # We don't need to pass anything to run. By default the API token will -# be fetched from the LAYABOUT_API_TOKEN environment variable. +# be fetched from the LAYABOUT_TOKEN environment variable. if __name__ == "__main__": print('Printing all events. Press Ctrl-C to quit.\n') app.run() diff --git a/layabout.py b/layabout.py index e954704..65fb287 100644 --- a/layabout.py +++ b/layabout.py @@ -137,36 +137,10 @@ def echo(slack, event): app.run() """ def __init__(self) -> None: - self._env_var = EnvVar('SLACK_API_TOKEN') + self._env_var = EnvVar('LAYABOUT_TOKEN') self._slack: Optional[_SlackClientWrapper] = None self._handlers: _Handlers = defaultdict(list) - @staticmethod - def _format_parameter_error_message(name: str, sig: Signature, - num_params: int) -> str: - """ - Format an error message for missing positional arguments. - - Args: - name: The function name. - sig: The function's signature. - num_params: The number of function parameters. - - Returns: - str: A formatted error message. - """ - if num_params == 0: - plural = 's' - missing = 2 - arguments = "'slack' and 'event'" - else: - plural = '' - missing = 1 - arguments = "'event'" - - return (f"{name}{sig} missing {missing} required positional " - f"argument{plural}: {arguments}") - def handle(self, type: str, *, kwargs: dict = None) -> Callable: """ Register an event handler with the :obj:`Layabout` instance. @@ -192,7 +166,7 @@ def decorator(fn: Callable) -> Callable: sig = signature(fn) num_params = len(sig.parameters) if num_params < 2: - raise TypeError(self._format_parameter_error_message( + raise TypeError(_format_parameter_error_message( fn.__name__, sig, num_params)) # Register a tuple of the callable and its kwargs, if any. @@ -230,7 +204,7 @@ def run(self, *, connector: A means of connecting to the Slack API. This can be an API :obj:`Token`, an :obj:`EnvVar` from which a token can be retrieved, or an established :obj:`SlackClient` instance. If - absent an attempt will be made to use the ``SLACK_API_TOKEN`` + absent an attempt will be made to use the ``LAYABOUT_TOKEN`` environment variable. interval: The number of seconds to wait between fetching events from the Slack API. @@ -282,6 +256,32 @@ def run(self, *, time.sleep(interval) +def _format_parameter_error_message(name: str, sig: Signature, + num_params: int) -> str: + """ + Format an error message for missing positional arguments. + + Args: + name: The function name. + sig: The function's signature. + num_params: The number of function parameters. + + Returns: + str: A formatted error message. + """ + if num_params == 0: + plural = 's' + missing = 2 + arguments = "'slack' and 'event'" + else: + plural = '' + missing = 1 + arguments = "'event'" + + return (f"{name}{sig} missing {missing} required positional " + f"argument{plural}: {arguments}") + + @singledispatch def _create_slack(connector: Any) -> NoReturn: """ Default connector. Raises an error with unsupported connectors. """ diff --git a/setup.py b/setup.py index 4516eab..9f7a682 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ def get_version(string): install_requires=install_reqs, license='ISCL', py_modules=['layabout'], - keywords='Slack RTM API', + keywords='Slack RTM API Bot Framework', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Console', diff --git a/tests/test_layabout.py b/tests/test_layabout.py index b4f9219..c677bbc 100644 --- a/tests/test_layabout.py +++ b/tests/test_layabout.py @@ -216,7 +216,7 @@ def test_layabout_can_connect_to_slack_with_env_var(monkeypatch): Test that layabout can discover and use a Slack API token from an environment variable when not given one directly. """ - env_var = EnvVar('_TEST_SLACK_API_TOKEN') + env_var = EnvVar('_TEST_LAYABOUT_TOKEN') environ = {env_var: TOKEN} layabout = Layabout() SlackClient, slack = mock_slack(connections=(True,)) @@ -266,7 +266,7 @@ def test_layabout_raises_missing_slack_token_without_token(monkeypatch): # until will exit early here just to be safe. layabout.run(until=lambda e: False) - assert str(exc.value) == 'Could not acquire token from SLACK_API_TOKEN' + assert str(exc.value) == 'Could not acquire token from LAYABOUT_TOKEN' def test_layabout_raises_missing_slack_token_with_empty_token():