Skip to content

Latest commit

 

History

History
161 lines (120 loc) · 4.5 KB

File metadata and controls

161 lines (120 loc) · 4.5 KB

development

pre-work

create a virtual environment

While not strictly needed, it is a good idea to create a virtual environment to run and develop slack-app. See the Python documentation for more details on Creating a virtual environments.

It is possible to use pyenv and pyenv-virtualenv to easily create&manage different Python versions and virtual environments.

pyenv/pyenv-virtualenv

See the pyenv documentation and the pyenv-virtualenv documentation for more details about the installation.

# update pyenv
cd $(pyenv root) && git pull && cd -
# pyenv-virtualenv
cd $(pyenv root)/plugins/pyenv-virtualenv && git pull && cd -

# install liblzma
sudo apt update && \
    sudo apt install liblzma-dev

# find the latest 3.13.x version available in pyenv
export PY_VERSION=$(pyenv install -l | grep "^\s*3.13" | tail -n 1 | awk '{print $1}') && \
    echo $PY_VERSION

# install the latest 3.13.x release
pyenv install $PY_VERSION

# create a virtual environment
pyenv virtualenv $PY_VERSION slack-app-venv

activate the virtual environment

See the Python documentation for more details on Activating a virtual environment.

If using pyenv and pyenv-virtualenv run

pyenv activate slack-app-venv

install the requirements

pip install -r requirements-dev.txt

pre-commit, black, pylint and flake8 are included in requirements-dev.txt.

install the pre-commit hooks

  • make sure pre-commit is installed
    pre-commit --version
  • install pre-commit to set up the git hook scripts
    pre-commit install

See also the pre-commit tips section in miscellanea.md.

start slack-app in debug mode

Export the environment variables

source ~/.secrets/ENV_VARS

Run app.py in debug mode

export SLACK_BOT_DEBUG=true && \
    export PYTHONPATH=.; \
    export SLACK_BOT_TOKEN; export SLACK_APP_TOKEN; python slackapp/app.py

To switch off debug mode unset the env variable

unset SLACK_BOT_DEBUG && \
    export PYTHONPATH=.; \
    export SLACK_BOT_TOKEN; export SLACK_APP_TOKEN; python slackapp/app.py

tests

run the tests

GH Actions is configured to run pytest on push to the main branch and on PRs opened against the main branch.

It is possible to run tests with docker, or manually like in this example

(slack-app-venv) (...):~/github/slack-app$ pytest
========================= test session starts =========================
platform linux -- Python 3.13.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /home/user/github/slack-app
collected 1 item

tests/test_dummy.py .                                           [100%]

========================== 1 passed in 0.01s ==========================
(slack-app-venv) (...):~/github/slack-app$

Note that outside a virtual environment it will be needed to add PYTHONPATH explicitly

export PYTHONPATH=. ; pytest

run the tests with docker

docker build --target test -t slack-app-test .
docker run --rm slack-app-test

Run the test container interactively

docker run -it --rm slack-app-test bash

start the container for development

docker build --target dev -t slack-app-dev .
docker run \
    --env-file ~/.secrets/ENV_VARS \
    -it \
    --rm \
    slack-app-dev

If you wish to export the log files

docker build --target deploy -t slack-app .
mkdir -p ./logs
docker run \
    --env-file ~/.secrets/ENV_VARS \
    -it \
    --rm \
    --mount type=bind,source="$(pwd)"/logs,target=/var/log/slack-app \
    slack-app