File: using-moderngl-in-ci.rst

package info (click to toggle)
python-moderngl 5.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,700 kB
  • sloc: python: 15,758; cpp: 14,665; makefile: 14
file content (132 lines) | stat: -rw-r--r-- 3,621 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

Using ModernGL in CI
====================

Windows CI Configuration
------------------------

ModernGL can't be run directly on Windows CI without the use of `Mesa`_. To get ModernGL running
you should first install Mesa from the `MSYS2 project`_ and adding it to the ``PATH``.

Steps
_____

1. Usually `MSYS2 project`_ should be installed by default by your CI provider in ``C:\msys64``. You 
   can refer `the documentation <https://www.msys2.org/docs/ci/>`_ on how to get it installed and make 
   sure to update it.

2. Then login through bash and enter ``pacman -S --noconfirm mingw-w64-x86_64-mesa``.
    
   .. code-block:: shell
      
       C:\msys64\usr\bin\bash -lc "pacman -S --noconfirm mingw-w64-x86_64-mesa"
   
   This will install Mesa binary, which moderngl would be using.
    
3. Then add ``C:\msys64\mingw64\bin`` to ``PATH``.
    
  .. code-block:: powershell
   
    $env:PATH = "C:\msys64\mingw64\bin;$env:PATH"

  .. warning::
    
        Make sure to delete ``C:\msys64\mingw64\bin\python.exe`` if it exists because the python provided
        by them would then be added to Global and some unexpected things may happen.
     
4. Then set an environment variable ``GLCONTEXT_WIN_LIBGL=C:\msys64\mingw64\bin\opengl32.dll``. This will
   make glcontext use ``C:\msys64\mingw64\bin\opengl32.dll`` for opengl drivers.

5. Then you can run moderngl as you want to.

.. _Mesa: https://mesa3d.org/
.. _MSYS2 project: https://www.msys2.org/

Example Configuration
_____________________

A example configuration for Github Actions:

.. code-block:: yaml

    name: Hello World
    on: [push, pull_request]

    jobs:
      build:
        runs-on: windows-latest
        steps:
          - uses: actions/checkout@v2
          - name: Set up Python
            uses: actions/setup-python@v2
            with:
              python-version: 3.9
          - uses: msys2/setup-msys2@v2
            with:
              msystem: MINGW64
              release: false
              install: mingw-w64-x86_64-mesa
          - name: Test using ModernGL
            shell: pwsh
            run: |
              Remove-Item C:\msys64\mingw64\bin\python.exe -Force
              $env:GLCONTEXT_WIN_LIBGL = "C:\msys64\mingw64\bin\opengl32.dll"
              python -m pip install -r requirements.txt
              python -m pytest
              
Linux
-----

For running ModernGL on Linux CI, you would need to configure ``xvfb`` so that it starts a Window in the background.
After that, you should be able to use ModernGL directly.

Steps
_____

1. Install ``xvfb`` from Package Manager.

   .. code-block:: bash
        
        sudo apt-get -y install xvfb

2. The run the below command, to start Xvfb from background.

   .. code-block:: bash
    
        sudo /usr/bin/Xvfb :0 -screen 0 1280x1024x24 &

3. You can run ModernGL now.

Example Configuration
_____________________

A example configuration for Github Actions:

.. code-block:: yaml

    name: Hello World
    on: [push, pull_request]

    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          - name: Set up Python
            uses: actions/setup-python@v2
            with:
              python-version: 3.9
          - name: Prepare
            run: |
                sudo apt-get -y install xvfb
                sudo /usr/bin/Xvfb :0 -screen 0 1280x1024x24 &            
          - name: Test using ModernGL
            run: |
              python -m pip install -r requirements.txt
              python -m pytest

macOS
-----

You won't need any special configuration to run on macOS.