Creating a Development Environment — PyGObject

# Creating a Development Environment

This describes how to setup a development environment for working on a project that uses PyGObject, or for working on PyGObject itself. Please follow the instructions on “Getting Started” first, as they are a pre-requirement.

## Pipenv Setup

### Install Dependencies

In order to compile Python and pip install pygobject, dependencies are need for your operating system.

Ubuntu | Fedora | Arch Linux
Windows | macOS | openSUSE

#### Ubuntu / Debian

    sudo apt-get install -y python3-venv python3-wheel python3-dev
    sudo apt-get install -y libgirepository1.0-dev build-essential \
      libbz2-dev libreadline-dev libssl-dev zlib1g-dev libsqlite3-dev wget \
      curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libcairo2-dev

#### Fedora

    sudo dnf install -y python3-venv python3-wheel
    sudo dnf install -y gcc zlib-devel bzip2 bzip2-devel readline-devel \
      sqlite sqlite-devel openssl-devel tk-devel git python3-cairo-devel \
      cairo-gobject-devel gobject-introspection-devel

#### Arch Linux

    sudo pacman -S --noconfirm python-virtualenv python-wheel
    sudo pacman -S --noconfirm base-devel openssl zlib git gobject-introspection

#### openSUSE

    sudo zypper install -y python3-venv python3-wheel gobject-introspection-devel \
      python3-cairo-devel openssl zlib git
    sudo zypper install --type pattern devel_basis

#### Windows

    pacman -S --needed --noconfirm base-devel mingw-w64-i686-toolchain git \
       mingw-w64-i686-python3 mingw-w64-i686-python3-cairo \
       mingw-w64-i686-gobject-introspection mingw-w64-i686-libffi

#### macOS

No extra dependencies needed.

### Install pyenv

pyenv lets you easily switch between multiple versions of Python.

Linux | macOS
Windows |

#### Linux

    git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
    echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc
    source ~/.bashrc
    pyenv install 3.6.4

#### Windows

TODO: currently no way to install pyenv in Windows. So we’ll use a normal virtualenv instead.

    virtualenv --python 3 myvenv
    source myvenv/bin/activate

#### macOS

    brew install pyenv
    pyenv install 3.6.4

### Install pipsi

pipsi is a wrapper around virtualenv and pip which installs scripts provided by python packages into separate virtualenvs to shield them from your system and each other. We’ll use this to install pipenv.

Linux | macOS
Windows |

#### Linux

    curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py | python3 - --src=git+https://github.com/mitsuhiko/pipsi.git\#egg=pipsi
    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc
    pipsi install pew
    pipsi install pipenv

#### Windows

    curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py | python3 - --src=git+https://github.com/mitsuhiko/pipsi.git\#egg=pipsi

Add C:/Users/.local/bin to your path via Control Panel->All Control Panel Items->System->Advanced System Setttings->Environment Variables

    pipsi install pew
    pipsi install pipenv

#### macOS

With homebrew:

    brew install pipenv

With pipsi:

    curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py | python3 - --src=git+https://github.com/mitsuhiko/pipsi.git\#egg=pipsi
    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc
    pipsi install pew
    pipsi install pipenv

## Projects with PyGObject Dependencies

If you are going to work on a project that has PyGObject as a dependency, then do the following additional steps:

    git clone <url/projectname.git>
    cd projectname
    pipenv --python 3
    pipenv install pycairo
    pipenv install pygobject
    pipenv shell

## Work on PyGObject

### Platform Independent Steps

If you are going to work on developing PyGObject itself, then do the following additional steps:

    git clone https://gitlab.gnome.org/GNOME/pygobject.git
    cd pygobject
    pipenv --python 3
    pipenv install pytest
    pipenv install flake8
    pipenv install pycairo
    pipenv shell