The torsions server is a wrapper around the TorsionAnalyzer commandline application and is its intermediary into the web. It consists of a django backend server with infrastructure to run asynchornous jobs on a redis cluster, as well as various management functionality for Torsion Library and TorsionAnalyzer data. More information can be found in the following publication:
Patrick Penner, Wolfgang Guba, Robert Schmidt, Agnes Meyder, Martin Stahl, and Matthias Rarey. (submitted). The Torsion Library: Semi-automated Improvement of Torsion Rules with SMARTScompare.
Get python dependencies with conda.
conda create --name torsions -c anaconda -c conda-forge python=3.8 django celery psycopg2 redis redis-py vine pylint pylint-django coverage
conda activate torsionsAt this point either set the environment variables $USER, $PASSWORD and
$DATABASE to the ones configured in the torsions/settings.py or replace them with appropriate values below.
torsions requires a postgres database and a separate database user. You can create both with this:
psql -d postgres -c "CREATE ROLE $USER WITH ENCRYPTED PASSWORD '$PASSWORD'; ALTER ROLE $USER WITH LOGIN CREATEDB;"
psql -d postgres -c "CREATE DATABASE $DATABASE;"Perform the torsions migrations and seed the database with:
python manage.py migrate
python manage.py seedEnsure the bin directory exists and contains the TorsionAnalyzer binary.
The default configured backend and result system for celery is redis. Redis
must be installed and available at the url configured in the
torsions/settings.py.
Redis is run with the following:
redis-serverCelery workers can be run with:
celery -A torsions worker --loglevel=INFO...or in a more debug and IDE friendly way:
python /path/to/conda/envs/torsions/bin/celery -A torsions worker --loglevel=INFO| Criteria | Threshold |
|---|---|
| pylint | >9.0 |
| coverage (overall) | >90% |
| coverage (single file) | >80% |
Run pylint with the django plugin using:
find torsion* -type f -name "*.py" | xargs pylint --load-plugins pylint_django --django-settings-module=torsions.settingsRun coverage generation:
coverage run manage.py test
coverage htmlThis will generate an HTML coverage report int htmlcov
The preferred deployment server is gunicorn. It can be installed like this:
conda install -c anaconda gunicornTwo scripts, start.sh and stop.sh, are provided as utilities to start and
stop all necessary processes. The necessary processes are the following:
- redis
- celery worker
- gunicorn
Each process has its own directory where it will log to and save its PID file to. All processes are daemonized for an unprivileged user. The assumption is made that if a PID file exists the process is running as intended. This may not always be the case if the process encounters an unexpected error or is configured incorrectly. Configuration is kept as close to default as possible and modified values in default configuration files are marked with 'modified'.
A static torsion library is necessary for the torsion_analyzer. Paths to one
can be set in torsion_analyzer/settings.py. The STATIC_TORLIB_URL is
especially dependent on how static data is served in the deployment.