Initial commit

This commit is contained in:
Hemna 2021-10-22 09:29:40 -04:00
commit 375037d6a2
21 changed files with 731 additions and 0 deletions

23
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: detect-private-key
- id: check-merge-conflict
- id: check-case-conflict
- id: check-docstring-first
- id: check-builtin-literals
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.16.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/dizballanze/gray
rev: v0.10.1
hooks:
- id: gray

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2021 Walter A. Boring IV
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

65
Makefile Normal file
View File

@ -0,0 +1,65 @@
REQUIREMENTS_TXT ?= requirements.txt requirements-dev.txt
.DEFAULT_GOAL := help
.PHONY: help dev test
include Makefile.venv
Makefile.venv:
curl \
-o Makefile.fetched \
-L "https://github.com/sio/Makefile.venv/raw/v2020.08.14/Makefile.venv"
echo "5afbcf51a82f629cd65ff23185acde90ebe4dec889ef80bbdc12562fbd0b2611 *Makefile.fetched" \
| sha256sum --check - \
&& mv Makefile.fetched Makefile.venv
help: # Help for the Makefile
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
dev: venv ## Create the virtualenv with all the requirements installed
docs: build
cp README.rst docs/readme.rst
cp Changelog docs/changelog.rst
tox -edocs
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
clean-build: ## remove build artifacts
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
coverage: ## check code coverage quickly with the default Python
coverage run --source aprsd_telegram_plugin setup.py test
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html
test: dev ## Run all the tox tests
tox -p all
build: test ## Make the build artifact prior to doing an upload
$(VENV)/python3 setup.py sdist bdist_wheel
$(VENV)/twine check dist/*
upload: build ## Upload a new version of the plugin
$(VENV)/twine upload dist/*
check: dev ## Code format check with tox and pep8
tox -epep8
fix: dev ## fixes code formatting with gray
tox -efmt

99
README.rst Normal file
View File

@ -0,0 +1,99 @@
aprsd-telegram-plugin
=====================
|PyPI| |Status| |Python Version| |License|
|Read the Docs| |Tests| |Codecov|
|pre-commit|
.. |PyPI| image:: https://img.shields.io/pypi/v/aprsd-telegram-plugin.svg
:target: https://pypi.org/project/aprsd-telegram-plugin/
:alt: PyPI
.. |Status| image:: https://img.shields.io/pypi/status/aprsd-telegram-plugin.svg
:target: https://pypi.org/project/aprsd-telegram-plugin/
:alt: Status
.. |Python Version| image:: https://img.shields.io/pypi/pyversions/aprsd-telegram-plugin
:target: https://pypi.org/project/aprsd-telegram-plugin
:alt: Python Version
.. |License| image:: https://img.shields.io/pypi/l/aprsd-telegram-plugin
:target: https://opensource.org/licenses/MIT
:alt: License
.. |Read the Docs| image:: https://img.shields.io/readthedocs/aprsd-telegram-plugin/latest.svg?label=Read%20the%20Docs
:target: https://aprsd-telegram-plugin.readthedocs.io/
:alt: Read the documentation at https://aprsd-telegram-plugin.readthedocs.io/
.. |Tests| image:: https://github.com/hemna/aprsd-telegram-plugin/workflows/Tests/badge.svg
:target: https://github.com/hemna/aprsd-telegram-plugin/actions?workflow=Tests
:alt: Tests
.. |Codecov| image:: https://codecov.io/gh/hemna/aprsd-telegram-plugin/branch/main/graph/badge.svg
:target: https://codecov.io/gh/hemna/aprsd-telegram-plugin
:alt: Codecov
.. |pre-commit| image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit
Features
--------
* TODO
Requirements
------------
* TODO
Installation
------------
You can install *aprsd-telegram-plugin* via pip_ from PyPI_:
.. code:: console
$ pip install aprsd-telegram-plugin
Usage
-----
Please see the `Command-line Reference <Usage_>`_ for details.
Contributing
------------
Contributions are very welcome.
To learn more, see the `Contributor Guide`_.
License
-------
Distributed under the terms of the `MIT license`_,
*aprsd-telegram-plugin* is free and open source software.
Issues
------
If you encounter any problems,
please `file an issue`_ along with a detailed description.
Credits
-------
This project was generated from `@hemna`_'s `APRSD Plugin Python Cookiecutter`_ template.
.. _@hemna: https://github.com/hemna
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _MIT license: https://opensource.org/licenses/MIT
.. _PyPI: https://pypi.org/
.. _APRSD Plugin Python Cookiecutter: https://github.com/hemna/cookiecutter-aprsd-plugin
.. _file an issue: https://github.com/hemna/aprsd-telegram-plugin/issues
.. _pip: https://pip.pypa.io/
.. github-only
.. _Contributor Guide: CONTRIBUTING.rst
.. _Usage: https://aprsd-telegram-plugin.readthedocs.io/en/latest/usage.html

View File

View File

@ -0,0 +1,54 @@
import logging
from aprsd import messaging, plugin, trace
LOG = logging.getLogger("APRSD")
class TelegramChatPlugin(plugin.APRSDRegexCommandPluginBase):
version = "1.0"
# Look for any command that starts with w or W
command_regex = "^[wW]"
# the command is for ?
command_name = "weather"
enabled = False
def setup(self):
# Do some checks here?
self.enabled = True
def create_threads(self):
"""This allows you to create and return a custom APRSDThread object.
Create a child of the aprsd.threads.APRSDThread object and return it
It will automatically get started.
You can see an example of one here:
https://github.com/craigerl/aprsd/blob/master/aprsd/threads.py#L141
"""
if self.enabled:
# You can create a background APRSDThread object here
# Just return it for example:
# https://github.com/hemna/aprsd-weewx-plugin/blob/master/aprsd_weewx_plugin/aprsd_weewx_plugin.py#L42-L50
#
return []
@trace.trace
def process(self, packet):
"""This is called when a received packet matches self.command_regex."""
LOG.info("TelegramChatPlugin Plugin")
packet.get("from")
packet.get("message_text", None)
if self.enabled:
# Now we can process
return "some reply message"
else:
LOG.warning("TelegramChatPlugin is disabled.")
return messaging.NULL_MESSAGE

20
docs/Makefile Normal file
View File

@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = python -msphinx
SPHINXPROJ = aprsd_telegram_plugin
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

1
docs/authors.rst Normal file
View File

@ -0,0 +1 @@
.. include:: ../AUTHORS.rst

22
docs/clean_docs.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
"""Removes temporary Sphinx build artifacts to ensure a clean build.
This is needed if the Python source being documented changes significantly. Old sphinx-apidoc
RST files can be left behind.
"""
import shutil
from pathlib import Path
def main() -> None:
docs_dir = Path(__file__).resolve().parent
for folder in ("_build", "apidoc"):
delete_dir = docs_dir / folder
if delete_dir.exists():
shutil.rmtree(delete_dir)
if __name__ == "__main__":
main()

168
docs/conf.py Executable file
View File

@ -0,0 +1,168 @@
#!/usr/bin/env python
#
# aprsd_telegram_plugin documentation build configuration file, created by
# sphinx-quickstart on Fri Jun 9 13:47:02 2017.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# If extensions (or modules to document with autodoc) are in another
# directory, add these directories to sys.path here. If the directory is
# relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath(".."))
import aprsd_telegram_plugin
# -- General configuration ---------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ".rst"
# The master toctree document.
master_doc = "index"
# General information about the project.
project = "aprsd-telegram-plugin"
copyright = "2021, Walter A. Boring IV"
author = "Walter A. Boring IV"
# The version info for the project you're documenting, acts as replacement
# for |version| and |release|, also used in various other places throughout
# the built documents.
#
# The short X.Y version.
version = aprsd_telegram_plugin.__version__
# The full version, including alpha/beta/rc tags.
release = aprsd_telegram_plugin.__version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output -------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "alabaster"
# Theme options are theme-specific and customize the look and feel of a
# theme further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
# -- Options for HTMLHelp output ---------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = "aprsd_telegram_plugindoc"
# -- Options for LaTeX output ------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass
# [howto, manual, or own class]).
latex_documents = [
(
master_doc, "aprsd_telegram_plugin.tex",
"aprsd-telegram-plugin Documentation",
"Walter A. Boring IV", "manual",
),
]
# -- Options for manual page output ------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(
master_doc, "aprsd_telegram_plugin",
"aprsd-telegram-plugin Documentation",
[author], 1,
),
]
# -- Options for Texinfo output ----------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(
master_doc, "aprsd_telegram_plugin",
"aprsd-telegram-plugin Documentation",
author,
"aprsd_telegram_plugin",
"One line description of project.",
"Miscellaneous",
),
]

1
docs/contributing.rst Normal file
View File

@ -0,0 +1 @@
.. include:: ../CONTRIBUTING.rst

1
docs/history.rst Normal file
View File

@ -0,0 +1 @@
.. include:: ../HISTORY.rst

18
docs/index.rst Normal file
View File

@ -0,0 +1,18 @@
Welcome to APRSD Nearest station plugin's documentation!
========================================================
.. toctree::
:maxdepth: 2
:caption: Contents:
readme
installation
contributing
authors
history
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

51
docs/installation.rst Normal file
View File

@ -0,0 +1,51 @@
.. highlight:: shell
============
Installation
============
Stable release
--------------
To install aprsd-telegram-plugin, run this command in your terminal:
.. code-block:: console
$ pip install aprsd-telegram-plugin
This is the preferred method to install, as it will always install the most recent stable release.
If you don't have `pip`_ installed, this `Python installation guide`_ can guide
you through the process.
.. _pip: https://pip.pypa.io
.. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/
From sources
------------
The sources can be downloaded from the `Github repo`_.
You can either clone the public repository:
.. code-block:: console
$ git clone git://github.com/hemna/aprsd-telegram-plugin
Or download the `tarball`_:
.. code-block:: console
$ curl -OJL https://github.com/hemna/aprsd-telegram-plugin/tarball/master
Once you have a copy of the source, you can install it with:
.. code-block:: console
$ python setup.py install
.. _Github repo: https://github.com/hemna/aprsd-telegram-plugin
.. _tarball: https://github.com/hemna/aprsd-telegram-plugin/tarball/master

12
requirements-dev.txt Normal file
View File

@ -0,0 +1,12 @@
pip
pip-tools
bump2version
wheel
watchdog
flake8
tox
coverage
Sphinx
twine
pytest==6.2.5
gray

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
pbr
aprsd>=2.2.0

40
setup.cfg Normal file
View File

@ -0,0 +1,40 @@
[metadata]
name = aprsd_telegram_plugin
long_description = file: README.rst
long_description_content_type = text/x-rst
author = Walter A. Boring IV
author_email = waboring@hemna.com
license = MIT
license_file = LICENSE
classifiers =
License :: OSI Approved :: MIT License
classifier =
Topic :: Communications :: Ham Radio
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
description_file =
README.rst
summary = Ham Radio APRS APRSD plugin for Telegram IM service
[global]
setup-hooks =
pbr.hooks.setup_hook
[files]
packages =
aprsd_telegram_plugin
[build_sphinx]
source-dir = doc/source
build-dir = doc/build
all_files = 1
[upload_sphinx]
upload-dir = doc/build/html
[mypy]
ignore_missing_imports = True
strict = True

27
setup.py Normal file
View File

@ -0,0 +1,27 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import setuptools
# In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing # noqa
except ImportError:
pass
setuptools.setup(setup_requires=["pbr"], pbr=True)

1
tests/__init__.py Normal file
View File

@ -0,0 +1 @@
"""Unit test package for aprsd_telegram_plugin."""

View File

@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Tests for `aprsd_telegram_plugin` package."""
import pytest
@pytest.fixture
def response():
"""Sample pytest fixture.
See more at: http://doc.pytest.org/en/latest/fixture.html
"""
# import requests
# return requests.get('https://github.com/audreyr/cookiecutter-pypackage')
def test_content(response):
"""Sample pytest test function with the pytest fixture as an argument."""
# from bs4 import BeautifulSoup
# assert 'GitHub' in BeautifulSoup(response.content).title.string

83
tox.ini Normal file
View File

@ -0,0 +1,83 @@
[tox]
# These are the default environments that will be run
# when ``tox`` is run without arguments.
envlist =
fmt
lint
py{37,38,39}
skip_missing_interpreters = true
[flake8]
# Use the more relaxed max line length permitted in PEP8.
max-line-length = 99
# This ignore is required by black.
extend-ignore = E203
extend-exclude =
venv
# This is the configuration for the tox-gh-actions plugin for GitHub Actions
# https://github.com/ymyzk/tox-gh-actions
# This section is not needed if not using GitHub Actions for CI.
[gh-actions]
python =
3.7: py37
3.8: py38, fmt, lint
3.9: py39
# Activate isolated build environment. tox will use a virtual environment
# to build a source distribution from the source tree. For build tools and
# arguments use the pyproject.toml file as specified in PEP-517 and PEP-518.
isolated_build = true
[testenv]
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements-dev.txt
commands =
# Use -bb to enable BytesWarnings as error to catch str/bytes misuse.
# Use -Werror to treat warnings as errors.
{envpython} -bb -Werror -m pytest {posargs}
[testenv:type-check]
skip_install = true
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements-dev.txt
commands =
mypy src tests
[testenv:lint]
skip_install = true
deps =
-r{toxinidir}/requirements-dev.txt
commands =
flake8 aprsd_telegram_plugin tests
[testenv:docs]
skip_install = true
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements-dev.txt
changedir = {toxinidir}/docs
commands =
{envpython} clean_docs.py
sphinx-apidoc --force --output-dir apidoc {toxinidir}/aprsd_telegram_plugin
sphinx-build -a -W . _build
[testenv:fmt]
skip_install = true
deps =
-r{toxinidir}/requirements-dev.txt
commands =
gray aprsd_telegram_plugin tests
[testenv:licenses]
skip_install = true
recreate = true
deps =
-r{toxinidir}/requirements.txt
pip-licenses
commands =
pip-licenses {posargs}