Development Environment
Prior to committing any changes to Refinery, our pre-commit hooks should be installed. Generally, pre-commit hooks are simple scripts that run automatically when calling git commit
. We use Pre-Commit to manage our pre-commit hooks. In our case we run Flake8 and JSHint to check for simple formatting issue regarding our Python JavaScript files.
Pre-commit hooks need to be installed only once after a fresh git clone
has been retrieved:
$ workon refinery-deployment
$ pre-commit install
When you change .pre-commit-config.yaml
then you have to manually update pre-commit. Unfortunately there's no update command that just works. You have to manually uninstall, clean, and install the hook again.
$ workon refinery-deployment
$ pre-commit uninstall
$ pre-commit clean
$ pre-commit install
Note: Do not run pre-commit autoupdate
! This will edit .pre-commit-config.yaml
and overwrite all version with the very latest commit hash of git, which I think (Fritz) is dangerous because the last commit might not be a stable release.
The hooks themselves are configured in .pre-commit-config.yaml
. For more information visit http://pre-commit.com/.
PyCharm enthusiasts need to create a custom bash profile to ensure that they activate Refinery's deployment environment in order to access pre-commit. Follow these steps:
-
Create a new file
.pycharmrc-refinery
in your favorite location, e.g./my/favorite/location/
-
Open that file and add the following line
source ~/.bashrc workon refinery-deployment
We are assuming that you've set up virtualenvwrapper and all the depending stuff in your
.bashrc
. If that's not the case then please source the correct bash profile; e.g.source /where/ever/.myFancyBashProfile
. -
Open PyCharm and got to your project settings. The at Tools -> Terminal -> Shell path and set it to:
/bin/bash --rcfile /my/favorite/location/.pycharmrc-refinery
-
Next time you want to commit some nasty stuff that PEP8 doesn't like your commit will fail and an error message will enlighten you. 🖖
Enable Django support for the project (set refinery-platform/refinery
directory as Django project root).
Configure a remote interpreter (Vagrant and/or SSH). Make sure to select the Python interpreter from the Refinery virtualenv on the remote host (e.g.: /home/vagrant/.virtualenvs/refinery-platform/bin/python
- not the system default).
Create run/debug configuration for Django server:
- set Host to
0.0.0.0
, Port to8000
- add to Environment variables:
DJANGO_SETTINGS_MODULE=config.settings.<CONFIG>
andPYTHONUNBUFFERED=1
-
<CONFIG>
is a deployment mode supported by our Fabric script (fab vm conf:<CONFIG>
) and by default one ofdev
,prod
,gdev
, ordjdt
. - The value of
<CONFIG>
used for theDJANGO_SETTINGS_MODULE
has to match the value of<CONFIG>
used when launching the VM.
-
- choose a corresponding remote interpreter
NOTE: Adding
CELERY_ALWAYS_EAGER = True
to your settings file will run Celery tasks on the main thread, making debugging much easier.
Create run/debug configuration for Python:
- set Script to the path to of
manage.py
on the host - set Script parameters to run the Celery worker, for example:
celeryd -c 4 -Q celery --events
- set Environment variables and remote interpreter as above
Additional settings for SSH connection:
- add to Environment variables (to load packages installed into virtual environment):
PYTHONPATH=/path/to/remote/virtualenv/refinery-platform/lib/python2.7/site-packages
- add to Path mappings (project directory for
manage.py
):/path/to/local/refinery-platform/refinery
/path/to/remote/refinery-platform/refinery
Optionally, forward ports if remote host is behind a firewall, e.g.: ssh -L18000:localhost:8000 remote-host-name
. Then connect to http://localhost:18000/
in web browser.
Troubleshooting:
- Remote debugger may exit prematurely with code -1 the first time after configuration is created or changed - simply restart it and it should run successfully the second time.
- Ignore
New process is launching (breakpoints won't work in the new process)
message from the debugger - breakpoints do work if "Attach to subprocess automatically while debugging" is enabled. - The default configuration after (re-)provisioning is
prod
To enable the Django debug toolbar run fab vm conf:djdt
on the host. Finally, if you want to debug the API append &debug
to your endpoint of choice, e.g. http://192.168.50.50:8000/api/v1/data_sets/?format=json&debug. This wraps the JSON output as HTML, which in turn will load the toolbar.
Note: The &debug
query parameter only works when the toolbar is enabled.
Administration
- Operations
- Setting Up Galaxy
- Galaxy CloudMan
- Annotating & Importing Refinery Tools
- Batch Import ISA-Tabs
- Backup & Restore
- Google reCAPTCHA v2
Development