____ _ __
/ __ )(_)___ _/ /__ ____ __________
/ __ / / __ `/ / _ \/ __ `/ ___/ __ \______
/ /_/ / / /_/ / / __/ /_/ / / / / / /_____/
/_______/\__, /_/\___/\__,____ /_/ /_/
/ ___//____/____ ______/ __/___ _ ________ ______ _____ _____
\__ \/ __ \/ __ `/ ___/ /_/ __ `/_____/ ___/ _ \/ ___/ | / / _ \/ ___/
___/ / /_/ / /_/ / / / __/ /_/ /_____(__ ) __/ / | |/ / __/ /
/____/ .___/\__,_/_/ /_/ \__,_/ /____/\___/_/ |___/\___/_/
/_/
Python tasks used to support Biglearn and conduct calculations.
The requirements.txt file expects to be able to download the sparfa-algs
egg by cloning the biglearn-sparfa-algs repo from GitHub via SSH.
You'll either need to configure git to be able to access GitHub using an SSH key
or add the following to your ~/.gitconfig
to access GitHub via HTTPS instead:
[url "https://github.com/"]
insteadOf = [email protected]:
Install the required dependencies:
- Debian/Ubuntu:
sudo apt-get install libpq-dev
- OS X: Get Homebrew if you don't already have it
and then run
brew install postgresql
NOTE: Unfortunately you need to install the postgresql package, because Homebrew does not currently provide a standalone libpq package.
The following external services are required:
- PostgreSQL 9.6
- Redis 4.0
- RabbitMQ 3.6
We recommend you install them using Docker and Docker Compose. This should work on any OS that docker can be installed on:
-
Install Docker and Docker Compose by following the instructions on the Docker website
-
Run Docker Compose:
docker-compose up
You will now have three containers running PostgreSQL, Redis and RabbitMQ.
docker ps
will show the running containers. You can connect to the PostgreSQL database by runningpsql postgresql://postgres@localhost:5445/postgres
.When you want to shut the containers down you can interrupt the
docker-compose
command. If you would rather run them in the background, you can rundocker-compose up -d
. -
If not running Docker Compose in daemon mode, open a new terminal window.
You will need a way to install a specific version of python,
since biglearn-sparfa-server requires python >= 3.6 and < 3.7.
We recommend pyenv
and pyenv-virtualenv
, and they are required to use our Makefile.
Make sure to follow all the installation instructions, including
adding the required lines to your profile and restarting the shell.
-
Install pyenv
-
Install pyenv-virtualenv
-
Run
make install
to install python, create a virtualenv and install all dependencies using the exact versions inrequirements.txt
.
As long as it has been properly installed, pyenv-virtualenv will automatically activate the new virtualenv for you.
If you need to update package versions, first run make reinstall
to reset
your virtualenv to having only non-dev packages, then update the packages as needed.
When satisfied, run make requirements
to create a new requirements.txt
based on the package versions currently installed in the virtualenv.
Alternatively, run make update
to update all packages listed in setup.py
to the
latest versions allowed, then run make requirements
to create a new requirements.txt
.
Or simply run make update requirements
to do both steps at once.
-
Run
make dotenv
to copy .python.env.example into .python.env -
Fill in the API tokens for biglearn-api and biglearn-scheduler in .python.env. Also make sure the URLs are correct for the Biglearn servers you desire to use.
-
Run
make create-user setup-db
to create the database user and the database and run all migrations. -
If you need more database management commands, see
make help
.
-
To install the dev dependencies, run
make install-dev
. -
To run tests, run
make test
.
-
sparfa load
andsparfa calc
can run individual loaders and calculations. Run each of these commands to obtain a list of available loaders and calculations. -
sparfa celery
can be used to send commands to the celery CLI, using the app's environment. For example:sparfa celery worker
andsparfa celery beat
Make sure you have external services running before you run this command.
honcho start
starts the celery worker and beat processes.
This will run all periodic tasks, including loaders and calculations.
Make sure you have the external services running before you run this command.
Alembic is used to manage migrations in biglearn-sparfa-server.
-
alembic upgrade head
will run all migrations. -
alembic downgrade -1
will rollback the last migration. -
alembic upgrade +1
will apply the next migration. -
alembic history
will show the migration version history.
Migrations are stored in the migrations/versions
directory.
Each migration file begins with a hash and includes the
revision message that was posted at the command line.
The sparfa_server/models.py
file contains all the models that represent
the tables in the biglearn-sparfa-server database.
The models can be changed and migration files can be autogenerated.
However, not everything can be autodetected.
Visit the
alembic
documentation to see what can be autogenerated.
If a change has been made to the models.py
file, run the following to create a migration file:
alembic revision --autogenerate -m "added X column to Y table"
If a migration file needs to be created manually, instead run:
alembic revision -m "created X table"
In either case, review the generated file in order to add the proper migration code or make any necessary changes.