Jump to content

User:Danmichaelo

From Wikitech

Checklist setting up a new python project

See also User:Pathoschild/Getting started with Flask
  1. Create a new project at Special:NovaServiceGroup using "Add service group".
  2. Wait a few minutes seconds, log out and in again, type become <projectname>
  3. vim .description and add a short description that will show up on tools.wmflabs.org. You can use html syntax to add links.
  4. Setup a virtual environment for python: virtualenv ENV
  5. Activate it: source ENV/bin/activate
  6. Install latest mwclient: pip install git+git://github.com/mwclient/mwclient.git
  7. vim .profile and add the following:
# Detect if we have an interactive shell
case "$-" in
    *i*) export INTERACTIVE=yes ;;
    *)   unset INTERACTIVE ;;
esac

# Say hello
test -n "$INTERACTIVE" && {
    echo "Hello ${SUDO_USER}!"
}

# Load user's environment
test -f /home/${SUDO_USER}/.profile && {
    echo "✔ Loading your .profile"
    . /home/${SUDO_USER}/.profile
}
test -f /home/${SUDO_USER}/.vimrc && {
    echo "✔ Aliasing vim to use your .vimrc"
    # alias vim="vim -u ~${SUDO_USER}/.vimrc --cmd 'set rtp^=~${SUDO_USER}/.vim'"
    alias vim="HOME=/home/$SUDO_USER vim"
}

# Activate virtualenv
test -d ENV && {
    test -n "$INTERACTIVE" && echo "✔ Activating virtualenv"
    . ENV/bin/activate
}

# Check gitconfig
test -n "$INTERACTIVE" && {
    alias git="HOME=/home/$SUDO_USER git"

    if [ ! -r /home/$SUDO_USER/.gitconfig ]
    then
        echo Please set git user and e-mail *in your own \$HOME* before running git
        echo in this project. In addition, make sure this tool user can read your
        echo ~/.gitconfig.
        echo
        echo "The following should work (remember: as your own user!)"
        echo git config --global user.name "My Username"
        echo git config --global user.email "my@email"
        echo chmod 644 \~/.gitconfig
        echo chmod +x \~
        echo
    fi
}

# Show running jobs
test -n "$INTERACTIVE" && qstat
  1. vim .inputrc and add the following:
# Up arrow
"\e[A": history-search-backward
# Down arrow
"\e[B": history-search-forward
  1. Setup git repo:
    1. git init
    2. git remote add origin <repo>
    3. Ctrl-D to become yourself again (if you need your own private key, etc..)
    4. cd to the project folder and git pull origin master
    5. Check that files are group-writable
  1. Configure uwsgi: vim uwsgi.ini and add the following: (replacing TOOLNAME with the name of the tool)
[uwsgi]
plugin = python3
socket = /data/project/TOOLNAME/TOOLNAME.sock
chdir = /data/project/TOOLNAME/www/python/src
venv = /data/project/TOOLNAME/www/python/venv
module = app
callable = app
manage-script-name = true
mount = /TOOLNAME=app:app
single-interpreter = true
  1. Start webserver: webservice --backend=gridengine uwsgi-plain start