Skip to content

Getting Started

This page sets up a development instance on your machine. See Repository Layout for where things are.

Requirements

  • uv, which manages the virtual environment and the dependencies
  • git
  • the system libraries that the Python dependencies need to build, such as libgit2

Get the sources

git clone https://code.abilian.com/abilian/sourcelab.git
cd sourcelab

Dependencies

Create the virtual environment in .venv and install the locked dependencies:

uv sync

Each package declares its dependencies in a pyproject.toml, the root pyproject.toml declares the development tools, and uv.lock records all the exact versions. Prefix commands with uv run to run them in the environment.

uv sync --extra clamav --package sourcelab   # add an optional feature: clamav, postgresql
uv sync --all-packages                       # also install sourcelab-milters, which needs libmilter to build
uv add --package sourcelab <package>         # change the dependencies of a package

Front-end assets

The web interface needs no JavaScript library and no Node.js: its pages are rendered on the server, on the Abilian Design System, which uv run abilian-ds sync vendors into web/static/ads/ and web/templates/ads/. The app's own CSS is web/static/theme.css.

Run SourceLab

make run

This creates the database the first time, then starts the web server and the workers, at http://127.0.0.1:5000, in a single process. Ctrl-C stops it. The web server and the workers are Myxo services, run from the layout layouts/dev.toml (myxo serve layouts/dev.toml), and the process restarts when you save a Python file.

To get a few projects and users, run this once, in a second terminal, on a new database:

make seed

You can then log in as pingou, with the password testing123.

The database is /var/tmp/sourcelab_dev.sqlite. The repositories and uploads are in lcl/. Delete both to start over.

make run and make seed read the configuration file dev/run.cfg, which only sets HOOK_SECRET and HOOK_URL: the git hooks of a push ask the running server to run them, instead of each loading SourceLab, so a push takes half a second rather than several. With SOURCELAB_CONFIG set in your environment, they read your file instead: copy the two keys into it to keep fast pushes.

Other environments, with Docker Compose on PostgreSQL or in a Vagrant VM, are described in the README.

Change the configuration

To change some configuration keys, put them in a file, as described in Configuration. For example, config:

from datetime import timedelta
# Makes the admin session longer
ADMIN_SESSION_LIFETIME = timedelta(minutes=20000000)

# Use a postgresql database instead of sqlite
DB_URL = 'postgresql://user:pass@localhost/sourcelab'

APP_URL = '*'
DOC_APP_URL = '*'

# Avoid sending email when developing
EMAIL_SEND = False

and run the server with it, along with the other processes you need:

uv run bin/runserver.py -c config

A relative path given to a script in bin/ resolves against the current directory.

Create a pull-request for testing

When working on SourceLab, it is pretty often that one wanted to work on a feature or a bug related to pull-requests needs to create one.

Making a pull-request for development purposes isn't hard, if you remember that since you're running a local instance, the git repos created in your SourceLab instance are also local.

So here are in a few steps that one could perform to create a pull-request in a local SourceLab instance.

  • Create a project on your SourceLab instance, let's say it will be called test

  • Create a folder clones somewhere in your system outside of lcl/:

    mkdir clones
    
  • Clone the repo of the test project into this clones folder and move into it:

    cd clones
    git clone /path/to/sourcelab/lcl/repos/test.git
    cd test
    
  • Add and commit some files:

    echo "*~" > .gitignore
    git add .gitignore
    git commit -m "Add a .gitignore file"
    echo "BSD" > LICENSE
    git add LICENSE
    git commit -m "Add a LICENSE file"
    
  • Push these changes:

    git push -u origin master
    
  • Create a new branch and add a commit in it:

    git branch new_branch
    git checkout new_branch
    touch test
    git add test
    git commit -m "Add file: test"
    
  • Push this new branch:

    git push -u origin new_branch
    

Then go back to your SourceLab instance running in your web-browser, check the test project. You should see two branches: master and new_branch. From there you should be able to open a new pull-request, either from the front page or via the File Pull Request button in the Pull Requests page.

Coding standards

make lint checks the code: ruff's lint rules and formatting on the package and its tests, the import contracts between layers, then the type checkers. make format formats the code and applies ruff's automatic fixes.

make lint
make format

Every Python file starts with an SPDX license line, which packages/sourcelab/tests/test_license.py checks.

Send patch

The easiest way to work on SourceLab is to make your own branch in git and commit your changes to it as often as you want. Rebase it on main whenever you need. When you are done, send the patch by email or open a pull request.

The workflow would therefore be something like:

git branch <my_shiny_feature>
git checkout <my_shiny_feature>
<work>
git commit file1 file2
<more work>
git commit file3 file4
git checkout main
git pull
git checkout <my_shiny_feature>
git rebase main
git format-patch -2

This will create two patch files that you can send by email to submit in a ticket on SourceLab, by email or after forking the project on SourceLab by submitting a pull-request (in which case the last step above git format-patch -2 is not needed.

Note

Though not required, it’s a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. The text up to the first blank line in a commit message is treated as the commit title, and that title is used throughout Git. For example, git-format-patch turns a commit into email. It uses the title on the Subject line and the rest of the commit in the body. SourceLab uses lines that contain only 'Fixes #number' as references to issues. If for example a commit message of a SourceLab patch has a line 'Fixes #3547' and a pullrequest (PR) gets created in SourceLab, this PR will be linked to from https://pagure.io/pagure/issue/3547

Unit-tests

SourceLab has a large test suite. We check both that functions work the way we want and that they fail when and how we expect.

The tests are in packages/sourcelab/tests/, split between a_unit, b_integration and c_e2e. Each test gets a temporary directory and an SQLite database. The jobs that a test puts run right after its session commits, in the same thread.

Inside a tier, the tests mirror the source: the tests of sourcelab/web/ui/fork/ are in c_e2e/web/ui/fork/, those of sourcelab/services/issues.py in b_integration/services/test_issues.py, and those of the top-level sourcelab/utils.py in a_unit/test_utils.py. Each layer has its natural tier: the pure code (domain, utils, config) is unit-tested, the layers that need a database or git repositories (services, infra, hooks, workers, cli) are integration-tested, and web is tested end to end. Tepyd checks that layout and the shape of the suite: run tepyd report in packages/sourcelab/; its configuration is the [tool.tepyd] section of packages/sourcelab/pyproject.toml.

make test                                       # the whole suite
uv run pytest -n auto                           # the same, in parallel
uv run pytest packages/sourcelab/tests/b_integration/services/test_issues.py   # one file

To run the suite on each supported Python, in separate environments:

uvx nox -s tests                                # every Python
uvx nox -s tests-3.12                           # one Python
uvx nox -s tests-3.12 -- packages/sourcelab/tests/test_license.py  # with arguments for pytest

The suite also runs in containers, on Fedora and CentOS Stream. This builds their images from the working tree, committed or not, and runs it in each:

./dev/run-tests-container.py              # --fedora or --centos for one, --python 3.15 for another Python

You can limit it to a test file or a single test, as with pytest. It uses docker, on the current context, or $CONTAINER_ENGINE.