VirtualEnv Installation

Note

Installing Mozillians might be daunting. Ask for help using IRC in #commtools on irc.mozilla.org. Ping giorgos, nemo-yiannis or tasos, they will be happy to help.

Dependencies

Prerequisites: You’ll need python2.7, python2.7-dev, virtualenv, pip, a C compiler (for building some of the Python packages, like the DB interface), mysqlclient and mysql-dev (or the equivalent on your system), a MySQL server, gettext, git, and lessc. Also, since we use elasticsearch, you will need a JAVA runtime environment.

There are almost certainly other requirements that we’re so used to having installed we’ve forgotten we have them, so don’t be shy about asking on IRC for help if you run into unexpected errors.

You will want a *nix box, ideally the latest versions of Debian or Ubuntu since that’s what most of the core developers are using and it’s most likely to work.

If you’re on Ubuntu or Debian, you might start with:

$ sudo apt-get install build-essential git-core \
python2.7 python2.7-dev python-virtualenv python-pip \
gettext libjpeg-turbo8-dev \
mysql-client mysql-server libmysqlclient-dev default-jre \
libxslt2.1 libxslt1-dev libjpeg-dev zlib1g-dev libpng12-dev

Then install node and lessc (you only need node for lessc).

nodejs is not packaged for every distribution so we will not get into details as that would require different instructions for every distribution. You might want to take a look at nodejs github wiki. Just bare in mind that lessc must be installed after nodejs, since you have to use npm, the package manager of nodejs.

Note

Make sure your node version node -v is greater than v0.6.12 or there will be issues installing less.

When you want to start contributing…

  1. Fork the main Mozillians repository (https://github.com/mozilla/mozillians) on GitHub.

  2. Clone your fork to your local machine:

    $ git clone git@github.com:YOUR_USERNAME/mozillians.git mozillians
    (lots of output - be patient...)
    $ cd mozillians
    
  3. Create your python virtual environment:

    $ virtualenv venv
    
  4. Activate your python virtual environment:

    $ source venv/bin/activate
    (venv) $
    

    Note

    When you activate your python virtual environment, ‘venv’ (virtual environment’s root directory name) will be prepended to your PS1.

  5. Install development requirements:

    (venv)$ python ./scripts/pipstrap.py
    (venv)$ pip install --require-hashes --no-deps -r requirements/dev.txt
    (lots more output - be patient again...)
    (venv) $
    

    Note

    Since you are using a virtual environment, all the python packages you will install while the environment is active will be available only within this environment. Your system’s python libraries will remain intact.

    Note

    Mac OS X users may see a problem when pip installs PIL. To correct that, install freetype, then do:

    sudo ln -s /opt/local/include/freetype2 /opt/local/include/freetype
    

    Once complete, re-run the pip install step to finish the installation.

  6. Configure your local mozillians installation:

    (venv)$ cp mozillians/env-dist mozillians/.env
    

    The provided configuration uses a MySQL database named mozillians and accesses it locally using the user mozillians.

  7. Download ElasticSearch:

    (venv)$ wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-2.4.5.tar.gz
    (venv)$ tar zxf elasticsearch-2.4.5.tar.gz
    

    and run:

    (venv)$ ./elasticsearch-2.4.5/bin/elasticsearch -d
    
This will run the elasticsearch instance in the background.

MySQL setup

Setting up a MySQL user and database for development:

  1. Install the MySQL server. Many Linux distributions provide an installable package. If your OS does not, you can find downloadable install packages on the MySQL site.

  2. Start the mysql client program as the mysql root user:

    $ mysql -u root -p
    Enter password: ........
    mysql>
    
  3. Create a mozillians user:

    mysql> create user 'mozillians'@'localhost';
    
  4. Create a mozillians database:

    mysql> create database mozillians character set utf8;
    
  5. Give the mozillians user access to the mozillians database:

    mysql> GRANT ALL PRIVILEGES ON mozillians.* TO "mozillians"@"localhost";
    mysql> EXIT
    Bye
    $
    
  6. Install timezone info tables in mysql:

    (venv)$ mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -uroot -p mysql
    

Running Mozillians

  1. Update product details:

    (venv)$ ./manage.py update_product_details -f
    
  2. Apply migrations:

    (venv)$ ./manage.py migrate
    
  3. Create user:

    1. Run server:

      ./manage.py runserver 127.0.0.1:8000
      
    2. Load http://127.0.0.1:8000 and sign in with Persona, then create your profile.

    3. Stop the server with Ctrl^C.

    4. Vouch your account and convert it to superuser:

      ./scripts/su.sh
      
  4. Develop!

    Now you can start contributing to Mozillians.

  5. When you’re done:

    When you are done with your coding session, do not forget to kill the elasticsearch process and deactivate your virtual python environment by running:

    (venv)$ deactivate
    $
    
  6. Next time:

    Next time, before starting you will need to activate your environment by typing:

    $ . $VIRTUAL_ENV/bin/activate
    

    and start elasticsearch server again:

    (venv)$ ./elasticsearch-2.4.5/bin/elasticsearch -d
    

Have fun!