Gaphor on Windows

Development Environment

Choco

We recommend using Chocolately as a package manager in Windows.

To install it, open PowerShell as an administrator, then execute:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

To run local scripts in follow-on steps, also execute Set-ExecutionPolicy RemoteSigned. This allows for local PowerShell scripts to run without signing, but still requires signing for remote scripts.

Git

To setup a development environment in Windows first install Git by executing as an adminstrator:

choco install git

MSYS2

Both of the development environments in the next steps need MSYS2 installed.

Install MSYS2:

Keep PowerShell open as administrator and execute:

choco install msys2

GTK and Python with MSYS2 (alternative method)

MSYS2 provides a bash terminal, with Python and GTK compiled against GCC. This is an alternative method to using gvsbuild above. The advantage is that you get a full bash environment in Windows, the disadvantage is that Python is very heavily patched to be built this way and often breaks.

  1. Run C:\tools\msys64\mingw64.exe - the MINGW64 terminal window should pop up

$ pacman -Suy
$ pacman -S mingw-w64-x86_64-gcc \
    mingw-w64-x86_64-gtk3 \
    mingw-w64-x86_64-gtksourceview4 \
    mingw-w64-x86_64-pkgconf \
    mingw-w64-x86_64-cairo \
    mingw-w64-x86_64-gobject-introspection \
    mingw-w64-x86_64-python \
    mingw-w64-x86_64-python-pip \
    mingw-w64-x86_64-python-setuptools
$ echo 'export PATH="/c/Program Files/Git/bin:$PATH"' >> ~/.bash_profile

Restart the MINGW64 terminal.

Clone the repository.

Create and activate a virtual environment in which Gaphor can be installed:

$ cd gaphor
$ python3.9 -m venv .venv
$ source .venv/bin/activate

Install and configure Poetry:

$ pip install poetry wheel
$ poetry config virtualenvs.create false

Install Gaphor and give it a try:

$ poetry install
$ poetry run gaphor

Debugging using Visual Studio Code

Start a new PowerShell terminal, and set current directory to the project folder:

PS > cd (to the location you put gaphor)

Ensure that path environment variable is set:

PS > $env:Path = "C:\gtk-build\gtk\x64\release\bin;" + $env:Path

Start Visual Studio Code:

PS > code .

To start the debugger, execute the following steps:

  1. Open __main__.py file from gaphor folder

  2. Add a breakpoint on line main(sys.argv)

  3. In the menu, select Run → Start debugging

  4. Choose Select module from the list

  5. Enter gaphor as module name

Visual Studio Code will start the application in debug mode, and will stop at main.

Packaging for Windows

In order to create an exe installation package for Windows, we utilize PyInstaller which analyzes Gaphor to find all the dependencies and bundle them in to a single folder. We then use a custom bash script that creates a Windows installer using NSIS and a portable installer using 7-Zip.

  1. Follow the instructions for settings up a development environment above

  2. Run C:\tools\msys64\mingw64.exe - a terminal window should pop up

$ source .venv/bin/activate
$ mingw32-make dist
$ cd packaging
$ mingw32-make all
$ cd windows
$ mingw32-make all