-
Notifications
You must be signed in to change notification settings - Fork 45
Setting up a development environment
- Install Docker. We use Docker because it lets us develop cross-platform.
- On Mac or Windows, increase Docker's memory to 4GB. (You don't need this step on Linux.) Mac instructions Windows instructions
- Install Git. That's XCode on Mac, GitHub Desktop for Windows, and
dnf install git
/apt install git
on Fedora/Ubuntu Linux. -
git clone https://github.com/CJWorkbench/cjworkbench.git
to clone this repo
You'll need a command line. First, get the development server up and running
git pull
-
bin/dev start
to run database migrations, start compiling JavaScript/CSS files, and run Django. - Browse to http://localhost:8000 and register a user.
- Django will fake-email you a confirmation code. Check the
local_mail/
subdirectory for the email and follow the link within. Then log in. - Press Ctrl+C in the console to kill everything
-
bin/dev python
-- open a Python console with Workbench's dependencies installed. This is useful for testing Pandas-related code (e.g.,import pandas
works). -
bin/dev python ./manage.py shell
-- open a Python console with Django loaded. This is useful for testing Workbench models (e.g.,import server.models
works). -
bin/dev sql
-- open a PostgreSQL shell to the development database. -
bin/dev npm install PACKAGE
-- you may runnpm
commands that modifypackage.json
andpackage-lock.json
; modules are installed to a Docker volume, not./node_modules
. -
bin/dev pipenv install PACKAGE
-- you may runpipenv
commands that modifyPipfile
andPipfile.lock
; packages are installed to a Docker volume. -
bin/dev clean
-- delete all Python packages, Node modules, the database, and files on disk that the database references.
-
bin/dev npm test
(~15s) runs JavaScript tests inassets/js/
.bin/dev npm test -- --watch
watches them for changes. -
bin/dev unittest
(~90s) runs Django tests inserver/tests/
.bin/dev unittest -k server.tests.modules.test_loadurl
(~30s first run, ~6s subsequent runs) specifies just one module to test. -
bin/integration-test
(~15min) builds images exactly as we do in production and runs automated integration tests on them. It fails as soon as a single test fails, to save you time. Write tests inintegrationtests/*.py
; if there's an error,bin/integration-test
will fill your screen with helpful advice.
If you test features that send email (such as confirmation email for new accounts) the email will appear in the local_mail
folder in your cjworkbench
directory.
To develop with the integrated tools in PyCharm (run, test, debug, etc.) setup a Python interpreter using the docker-compose.yml
file, as described in this documentation.
You will need to tell run the python interpreter inside the frontend
container, and launch it with the pipenv-run-python
script to make sure it uses the correct virtual environment. This is what your PyCharm Python interpreter settings should look like:
On Mac, you can get to this dialog through PyCharm -> Preferences -> Project: cjworkbench -> Project Interpreter
then pick Show All
at the bottom of the Project Interpreter
drop-down.
If you want to test logging in with Facebook and Google, you'll need to either manually set up social applications in the Django admin interface, or get or create a file called socialaccounts_secrets.json
in the project root. The file contains a list of objects defining a social account, like so:
{
'name':'Display Name',
'provider':'social_acccount_provider', // a full list is here: https://django-allauth.readthedocs.io/en/latest/providers.html
'client_id':'12345', // Your chosen provider's app id/client id -- everyone calls this something different
'secret':'12345' // Same as above but for client_secret
}
Once you've created this file, kill and restart bin/dev start
.
To download from Google Drive:
- Browse to https://console.developers.google.com
- Create a new organization, if wanted
- Create a new project within that organization:
Workbench Dev
- Enable the
Google Drive
API - Enable the
Google Picker
API - Add credentials for
Google Drive API
for aWeb server
accessingUser data
: NameGoogleConnect
, authorized originhttp://localhost:8000
, authorized redirect URIhttp://localhost:8000/oauth
, product nameWorkbench Dev
. - Download
client_id.json
orclient_secret_XXXXX.json
(they're the same) - Move that file into your Workbench project directory, as
client_secret.json
. (It's in.gitignore
: Google terms dictate it stay private.) - Restart
bin/dev start
- Create a new workflow and add a
Google Drive
module. - Sign in.
- Pick a file.
- Click
Update
To let users authenticate with Twitter:
- Browse to https://apps.twitter.com
- Click
Create New App
. Call itWorkbench Dev [random numbers]
, descriptionAuthenticator for CJWorkbench Twitter module, in dev mode only
, websitehttp://example.org
, callback URLhttp://localhost:8000/oauth
. Read and agree to the developer agreement. ClickCreate your Twitter application
. - Browse to
Permissions
. Switch toRead only
and clickUpdate Settings
. - Browse to
Keys and Access Tokens
. Copy/paste these into a new file calledtwitter_secret.json
in the root of the project (we.gitignore
it, because Twitter asks us to keep it private) with contents{"key":"....","secret":".....","redirect_url":"http://localhost:8000/oauth"}
. - Restart
bin/dev start
- Create a new workflow and add a
Twitter
module. - Sign in.
- Pick a search.
- Click
Update