rename project

This commit is contained in:
HgO 2022-06-13 20:55:01 +02:00
parent 3d8fbf142b
commit ad324c63c3
26 changed files with 102 additions and 102 deletions

View file

@ -5,35 +5,34 @@ name: Lint
on: on:
push: push:
branches: [ master ] branches: [master]
pull_request: pull_request:
branches: [ master ] branches: [master]
jobs: jobs:
lint: lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set up Python 3.9 - name: Set up Python 3.9
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:
python-version: 3.9 python-version: 3.9
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install -U isort==5.6.4 flake8==3.8.4 flake8-comprehensions==3.3.1 black==20.8b1 pip install -U isort==5.6.4 flake8==3.8.4 flake8-comprehensions==3.3.1 black==20.8b1
- name: Check import statement sorting - name: Check import statement sorting
run: | run: |
isort -c --df my_project_name/ my-project-name tests isort -c --df matrix_alertbot/ matrix-alertbot tests
- name: Python syntax errors, undefined names, etc. - name: Python syntax errors, undefined names, etc.
run: | run: |
flake8 . --count --show-source --statistics flake8 . --count --show-source --statistics
- name: PEP8 formatting - name: PEP8 formatting
run: | run: |
black --check --diff my_project_name/ my-project-name tests black --check --diff matrix_alertbot/ matrix-alertbot tests

1
.gitignore vendored
View file

@ -5,6 +5,7 @@
env/ env/
env3/ env3/
.env/ .env/
.venv/
# Bot local files # Bot local files
*.db *.db

View file

@ -46,11 +46,11 @@ See [SETUP.md](SETUP.md) for how to setup and run the template project.
*A reference of each file included in the template repository, its purpose and *A reference of each file included in the template repository, its purpose and
what it does.* what it does.*
The majority of the code is kept inside of the `my_project_name` folder, which The majority of the code is kept inside of the `matrix_alertbot` folder, which
is in itself a [python package](https://docs.python.org/3/tutorial/modules.html), is in itself a [python package](https://docs.python.org/3/tutorial/modules.html),
the `__init__.py` file inside declaring it as such. the `__init__.py` file inside declaring it as such.
To run the bot, the `my-project-name` script in the root of the codebase is To run the bot, the `matrix-alertbot` script in the root of the codebase is
available. It will import the `main` function from the `main.py` file in the available. It will import the `main` function from the `main.py` file in the
package and run it. To properly install this script into your python environment, package and run it. To properly install this script into your python environment,
run `pip install -e .` in the project's root directory. run `pip install -e .` in the project's root directory.
@ -65,7 +65,7 @@ their needs. Be sure never to check the edited `config.yaml` into source control
since it'll likely contain sensitive details such as passwords! since it'll likely contain sensitive details such as passwords!
Below is a detailed description of each of the source code files contained within Below is a detailed description of each of the source code files contained within
the `my_project_name` directory: the `matrix_alertbot` directory:
### `main.py` ### `main.py`

View file

@ -132,19 +132,19 @@ source env/bin/activate
Then simply run the bot with: Then simply run the bot with:
``` ```
my-project-name matrix-alertbot
``` ```
You'll notice that "my-project-name" is scattered throughout the codebase. When You'll notice that "matrix-alertbot" is scattered throughout the codebase. When
it comes time to modifying the code for your own purposes, you are expected to it comes time to modifying the code for your own purposes, you are expected to
replace every instance of "my-project-name" and its variances with your own replace every instance of "matrix-alertbot" and its variances with your own
project's name. project's name.
By default, the bot will run with the config file at `./config.yaml`. However, an By default, the bot will run with the config file at `./config.yaml`. However, an
alternative relative or absolute filepath can be specified after the command: alternative relative or absolute filepath can be specified after the command:
``` ```
my-project-name other-config.yaml matrix-alertbot other-config.yaml
``` ```
## Testing the bot works ## Testing the bot works

View file

@ -58,9 +58,9 @@ RUN apk add --no-cache \
# Install python runtime modules. We do this before copying the source code # Install python runtime modules. We do this before copying the source code
# such that these dependencies can be cached # such that these dependencies can be cached
# This speeds up subsequent image builds when the source code is changed # This speeds up subsequent image builds when the source code is changed
RUN mkdir -p /src/my_project_name RUN mkdir -p /src/matrix_alertbot
COPY my_project_name/__init__.py /src/my_project_name/ COPY matrix_alertbot/__init__.py /src/matrix_alertbot/
COPY README.md my-project-name /src/ COPY README.md matrix-alertbot /src/
# Build the dependencies # Build the dependencies
COPY setup.py /src/setup.py COPY setup.py /src/setup.py
@ -68,7 +68,7 @@ RUN pip install --prefix="/python-libs" --no-warn-script-location "/src/.[postgr
# Now copy the source code # Now copy the source code
COPY *.py *.md /src/ COPY *.py *.md /src/
COPY my_project_name/*.py /src/my_project_name/ COPY matrix_alertbot/*.py /src/matrix_alertbot/
# And build the final module # And build the final module
RUN pip install --prefix="/python-libs" --no-warn-script-location "/src/.[postgres]" RUN pip install --prefix="/python-libs" --no-warn-script-location "/src/.[postgres]"
@ -98,4 +98,4 @@ RUN apk add --no-cache \
VOLUME ["/data"] VOLUME ["/data"]
# Start the bot # Start the bot
ENTRYPOINT ["my-project-name", "/data/config.yaml"] ENTRYPOINT ["matrix-alertbot", "/data/config.yaml"]

View file

@ -53,14 +53,14 @@ RUN apk add --no-cache \
# Install python runtime modules. We do this before copying the source code # Install python runtime modules. We do this before copying the source code
# such that these dependencies can be cached # such that these dependencies can be cached
RUN mkdir -p /src/my_project_name RUN mkdir -p /src/matrix_alertbot
COPY my_project_name/__init__.py /src/my_project_name/ COPY matrix_alertbot/__init__.py /src/matrix_alertbot/
COPY README.md my-project-name /src/ COPY README.md matrix-alertbot /src/
COPY setup.py /src/setup.py COPY setup.py /src/setup.py
RUN pip install -e "/src/.[postgres]" RUN pip install -e "/src/.[postgres]"
# Now copy the source code # Now copy the source code
COPY my_project_name/*.py /src/my_project_name/ COPY matrix_alertbot/*.py /src/matrix_alertbot/
COPY *.py /src/ COPY *.py /src/
# Specify a volume that holds the config file, SQLite3 database, # Specify a volume that holds the config file, SQLite3 database,
@ -68,4 +68,4 @@ COPY *.py /src/
VOLUME ["/data"] VOLUME ["/data"]
# Start the app # Start the app
ENTRYPOINT ["my-project-name", "/data/config.yaml"] ENTRYPOINT ["matrix-alertbot", "/data/config.yaml"]

View file

@ -1,6 +1,6 @@
# Docker # Docker
The docker image will run my-project-name with a SQLite database and The docker image will run matrix-alertbot with a SQLite database and
end-to-end encryption dependencies included. For larger deployments, a end-to-end encryption dependencies included. For larger deployments, a
connection to a Postgres database backend is recommended. connection to a Postgres database backend is recommended.
@ -44,7 +44,7 @@ differences:
If using postgres, point to your postgres instance instead: If using postgres, point to your postgres instance instead:
``` ```
database: "postgres://username:password@postgres/my-project-name?sslmode=disable" database: "postgres://username:password@postgres/matrix-alertbot?sslmode=disable"
``` ```
**Note:** a postgres container is defined in `docker-compose.yaml` for your convenience. **Note:** a postgres container is defined in `docker-compose.yaml` for your convenience.
@ -67,7 +67,7 @@ First, create a volume for the data directory created in the above section:
docker volume create \ docker volume create \
--opt type=none \ --opt type=none \
--opt o=bind \ --opt o=bind \
--opt device="/path/to/data/dir" data_volume --opt device="/path/to/data/dir" matrix-alertbot
``` ```
Optional: If you want to use the postgres container defined in Optional: If you want to use the postgres container defined in
@ -80,20 +80,20 @@ docker-compose up -d postgres
Start the bot with: Start the bot with:
``` ```
docker-compose up my-project-name docker-compose up matrix-alertbot
``` ```
This will run the bot and log the output to the terminal. You can instead run This will run the bot and log the output to the terminal. You can instead run
the container detached with the `-d` flag: the container detached with the `-d` flag:
``` ```
docker-compose up -d my-project-name docker-compose up -d matrix-alertbot
``` ```
(Logs can later be accessed with the `docker logs` command). (Logs can later be accessed with the `docker logs` command).
This will use the `latest` tag from This will use the `latest` tag from
[Docker Hub](https://hub.docker.com/somebody/my-project-name). [Docker Hub](https://hub.docker.com/neutrinet/matrix-alertbot).
If you would rather run from the checked out code, you can use: If you would rather run from the checked out code, you can use:
@ -116,7 +116,7 @@ remove the option altogether to allow all addresses.
To update the container, navigate to the bot's `docker` directory and run: To update the container, navigate to the bot's `docker` directory and run:
``` ```
docker-compose pull my-project-name docker-compose pull matrix-alertbot
``` ```
Then restart the bot. Then restart the bot.
@ -124,26 +124,26 @@ Then restart the bot.
## Systemd ## Systemd
A systemd service file is provided for your convenience at A systemd service file is provided for your convenience at
[my-project-name.service](my-project-name.service). The service uses [matrix-alertbot.service](matrix-alertbot.service). The service uses
`docker-compose` to start and stop the bot. `docker-compose` to start and stop the bot.
Copy the file to `/etc/systemd/system/my-project-name.service` and edit to Copy the file to `/etc/systemd/system/matrix-alertbot.service` and edit to
match your setup. You can then start the bot with: match your setup. You can then start the bot with:
``` ```
systemctl start my-project-name systemctl start matrix-alertbot
``` ```
and stop it with: and stop it with:
``` ```
systemctl stop my-project-name systemctl stop matrix-alertbot
``` ```
To run the bot on system startup: To run the bot on system startup:
``` ```
systemctl enable my-project-name systemctl enable matrix-alertbot
``` ```
## Building the image ## Building the image
@ -152,5 +152,5 @@ To build a production image from source, use the following `docker build` comman
from the repo's root: from the repo's root:
``` ```
docker build -t somebody/my-project-name:latest -f docker/Dockerfile . docker build -t neutrinet/matrix-alertbot:latest -f docker/Dockerfile .
``` ```

View file

@ -2,17 +2,17 @@ version: '3.1' # specify docker-compose version
volumes: volumes:
# Set up with `docker volume create ...`. See docker/README.md for more info. # Set up with `docker volume create ...`. See docker/README.md for more info.
data_volume: matrix-alertbot:
external: true external: true
pg_data_volume: pg_data_volume:
services: services:
# Runs from the latest release # Runs from the latest release
my-project-name: matrix-alertbot:
image: somebody/my-project-name image: neutrinet/matrix-alertbot
restart: always restart: always
volumes: volumes:
- data_volume:/data - matrix-alertbot:/data
# Used for allowing connections to homeservers hosted on the host machine # Used for allowing connections to homeservers hosted on the host machine
# (while docker host mode is still broken on Linux). # (while docker host mode is still broken on Linux).
# #
@ -29,7 +29,7 @@ services:
# args: # args:
# PYTHON_VERSION: 3.8 # PYTHON_VERSION: 3.8
volumes: volumes:
- data_volume:/data - matrix-alertbot:/data
# Used for allowing connections to homeservers hosted on the host machine # Used for allowing connections to homeservers hosted on the host machine
# (while docker host networking mode is still broken on Linux). # (while docker host networking mode is still broken on Linux).
# #
@ -46,7 +46,7 @@ services:
# args: # args:
# PYTHON_VERSION: 3.8 # PYTHON_VERSION: 3.8
volumes: volumes:
- data_volume:/data - matrix-alertbot:/data
# Used for allowing connections to homeservers hosted on the host machine # Used for allowing connections to homeservers hosted on the host machine
# (while docker host networking mode is still broken on Linux). # (while docker host networking mode is still broken on Linux).
# #

View file

@ -0,0 +1,16 @@
[Unit]
Description=A matrix bot that does amazing things!
[Service]
Type=simple
User=matrix-alertbot
Group=matrix-alertbot
WorkingDirectory=/path/to/matrix-alertbot/docker
ExecStart=/usr/bin/docker-compose up matrix-alertbot
ExecStop=/usr/bin/docker-compose stop matrix-alertbot
RemainAfterExit=yes
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target

View file

@ -1,16 +0,0 @@
[Unit]
Description=A matrix bot that does amazing things!
[Service]
Type=simple
User=my-project-name
Group=my-project-name
WorkingDirectory=/path/to/my-project-name/docker
ExecStart=/usr/bin/docker-compose up my-project-name
ExecStop=/usr/bin/docker-compose stop my-project-name
RemainAfterExit=yes
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target

View file

@ -2,9 +2,9 @@
import asyncio import asyncio
try: try:
from my_project_name import main from matrix_alertbot import main
# Run the main function of the bot # Run the main function of the bot
asyncio.get_event_loop().run_until_complete(main.main()) asyncio.get_event_loop().run_until_complete(main.main())
except ImportError as e: except ImportError as e:
print("Unable to import my_project_name.main:", e) print("Unable to import matrix_alertbot.main:", e)

View file

@ -2,7 +2,7 @@ import sys
# Check that we're not running on an unsupported Python version. # Check that we're not running on an unsupported Python version.
if sys.version_info < (3, 5): if sys.version_info < (3, 5):
print("my_project_name requires Python 3.5 or above.") print("matrix_alertbot requires Python 3.5 or above.")
sys.exit(1) sys.exit(1)
__version__ = "0.0.1" __version__ = "0.0.1"

View file

@ -1,8 +1,8 @@
from nio import AsyncClient, MatrixRoom, RoomMessageText from nio import AsyncClient, MatrixRoom, RoomMessageText
from my_project_name.chat_functions import react_to_event, send_text_to_room from matrix_alertbot.chat_functions import react_to_event, send_text_to_room
from my_project_name.config import Config from matrix_alertbot.config import Config
from my_project_name.storage import Storage from matrix_alertbot.storage import Storage
class Command: class Command:

View file

@ -11,11 +11,11 @@ from nio import (
UnknownEvent, UnknownEvent,
) )
from my_project_name.bot_commands import Command from matrix_alertbot.bot_commands import Command
from my_project_name.chat_functions import make_pill, react_to_event, send_text_to_room from matrix_alertbot.chat_functions import make_pill, react_to_event, send_text_to_room
from my_project_name.config import Config from matrix_alertbot.config import Config
from my_project_name.message_responses import Message from matrix_alertbot.message_responses import Message
from my_project_name.storage import Storage from matrix_alertbot.storage import Storage
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View file

@ -6,7 +6,7 @@ from typing import Any, List, Optional
import yaml import yaml
from my_project_name.errors import ConfigError from matrix_alertbot.errors import ConfigError
logger = logging.getLogger() logger = logging.getLogger()
logging.getLogger("peewee").setLevel( logging.getLogger("peewee").setLevel(

View file

@ -16,9 +16,9 @@ from nio import (
UnknownEvent, UnknownEvent,
) )
from my_project_name.callbacks import Callbacks from matrix_alertbot.callbacks import Callbacks
from my_project_name.config import Config from matrix_alertbot.config import Config
from my_project_name.storage import Storage from matrix_alertbot.storage import Storage
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View file

@ -2,9 +2,9 @@ import logging
from nio import AsyncClient, MatrixRoom, RoomMessageText from nio import AsyncClient, MatrixRoom, RoomMessageText
from my_project_name.chat_functions import send_text_to_room from matrix_alertbot.chat_functions import send_text_to_room
from my_project_name.config import Config from matrix_alertbot.config import Config
from my_project_name.storage import Storage from matrix_alertbot.storage import Storage
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View file

@ -19,7 +19,7 @@ matrix:
# If this device ID already exists, messages will be dropped silently in encrypted rooms # If this device ID already exists, messages will be dropped silently in encrypted rooms
device_id: ABCDEFGHIJ device_id: ABCDEFGHIJ
# What to name the logged in device # What to name the logged in device
device_name: my-project-name device_name: matrix-alertbot
storage: storage:
# The database connection string # The database connection string

View file

@ -11,7 +11,7 @@ if [ $# -ge 1 ]
then then
files=$* files=$*
else else
files="my_project_name my-project-name tests" files="matrix_alertbot matrix-alertbot tests"
fi fi
echo "Linting these locations: $files" echo "Linting these locations: $files"

View file

@ -12,7 +12,7 @@ ignore=W503,W504,E203,E731,E501
line_length = 88 line_length = 88
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,TESTS,LOCALFOLDER sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,TESTS,LOCALFOLDER
default_section=THIRDPARTY default_section=THIRDPARTY
known_first_party=my_project_name known_first_party=matrix_alertbot
known_tests=tests known_tests=tests
multi_line_output=3 multi_line_output=3
include_trailing_comma=true include_trailing_comma=true

View file

@ -20,12 +20,12 @@ def read_file(path_segments):
return f.read() return f.read()
version = exec_file(("my_project_name", "__init__.py"))["__version__"] version = exec_file(("matrix_alertbot", "__init__.py"))["__version__"]
long_description = read_file(("README.md",)) long_description = read_file(("README.md",))
setup( setup(
name="my-project-name", name="matrix-alertbot",
version=version, version=version,
url="https://github.com/anoadragon453/nio-template", url="https://github.com/anoadragon453/nio-template",
description="A matrix bot to do amazing things!", description="A matrix bot to do amazing things!",
@ -54,6 +54,6 @@ setup(
], ],
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
# Allow the user to run the bot with `my-project-name ...` # Allow the user to run the bot with `matrix-alertbot ...`
scripts=["my-project-name"], scripts=["matrix-alertbot"],
) )

View file

@ -3,8 +3,8 @@ from unittest.mock import Mock
import nio import nio
from my_project_name.callbacks import Callbacks from matrix_alertbot.callbacks import Callbacks
from my_project_name.storage import Storage from matrix_alertbot.storage import Storage
from tests.utils import make_awaitable, run_coroutine from tests.utils import make_awaitable, run_coroutine

View file

@ -1,8 +1,8 @@
import unittest import unittest
from unittest.mock import Mock from unittest.mock import Mock
from my_project_name.config import Config from matrix_alertbot.config import Config
from my_project_name.errors import ConfigError from matrix_alertbot.errors import ConfigError
class ConfigTestCase(unittest.TestCase): class ConfigTestCase(unittest.TestCase):