Development installation

Everyone’s development environment is different. This is an attempt to make it as easy as possible to setup.

Please read through Direct installation first. Even if we’re gonna omit most of it, it will be easier to understand.

System setup

You’ll need git. Obviously.

apt install git

Code setup

Clone your fork:

git clone https://github.com/<your username>/lemon.py.git
# or, if you have SSH keys setup
git clone git@github.com:<your username>/lemon.py.git

Then you have to setup link back to our main repository, which is usually called upstream:

git remote add upstream https://github.com/Pumpkin-py/lemon.py.git

Database setup

Instead of high-performance PostgreSQL we are going to be using SQLite3, which has giant advantage: it requires zero setup.

Create a file called .env in the root directory of your cloned repo and copy the content of the default.env file into it. The .env file will hold sensitive bot information, so don’t let anyone see its content, ever. Open it and paste the connection string into the DB_STRING variable: sqlite:///lemon.db.

If you ever need to wipe the database, just delete the lemon.db file. The bot will create a new one when it starts again.

Development workflow with git

Note

Always start from main, but never commit to main.

When you make new feature, create new branch from main:

git checkout main
git checkout -b <branch name>

Now you can make edits to the code and commit the changes. When the feature is ready, push the commits and open a Pull request against the main branch.

Your changes will be reviewed and, if you’ve done your work correctly, accepted.

To update your local repository and your fork, run the following:

# ensure you are in 'main'
git checkout main
# download upstream changes
git fetch upstream
# apply changes to upstream main
git merge upstream/main
# update your GitHub repository
git push

The feature branch you used to open PR will no longer be useful. Delete it (and its remote version) by running

git branch -D <branch name>
git push -d origin <branch name>

Development inside of virtual environment

We strongly recommend you to use venv. While it’s possible to install Python packages directly on system/user level, they may conflict with other system programs.

Install the bot requirements:

apt install \
        python3 python3-dev python3-pip python3-venv python3-setuptools \
        gcc libffi-dev \
        libjpeg-dev libtiff-dev libwebp-dev libopenjp2-7-dev
python3 -m pip install wheel

Create the virtual environment and load it. Then you can install all bot dependencies.

python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt

Especially when working on the bot (debugging, development) it is easier if you speed up environment variable import. Open the venv file (.venv/bin/activate) and insert to the end of it:

set -o allexport
source ~/lemon/.env
set +o allexport

This way the variables will be set whenever you enter the virtual environment with the source .venv/bin/activate command. You can leave by running deactivate.

Running the bot

Assuming you are in virtual environment and have everything set up, run

python3 lemon.py

It will print startup information and a welcome message, something like this:

Imported database models in modules.base.base.database.
Imported database models in modules.base.admin.database.
Loaded module base.acl
Loaded module base.admin
Loaded module base.base
Loaded module base.logging
Loaded module base.errors
Loaded module base.language
2021-08-01 16:00:00 INFO: The pie is ready.