Debian Codegraph @

docs/devguide/dev_environ.rst

raw
1 .. include:: ../icons.rst
2
3 .. _devenv:
4
5 ##################################
6 Creating a Development Environment
7 ##################################
8
9 This describes how to setup a development environment for working on a project
10 that uses PyGObject, or for working on PyGObject itself. Please follow the
11 instructions on ":ref:`gettingstarted`" first, as they are a pre-requirement.
12
13 .. _pipenv-setup:
14
15 *****************
16 Environment Setup
17 *****************
18
19 .. _install-dependencies:
20
21 Install Dependencies
22 ====================
23 In order to compile Python and pip install pygobject, dependencies are need for
24 your operating system.
25
26 =========================================== ======================================== ==============================================
27 |ubuntu-logo| :ref:`Ubuntu <ubuntu-dep>` |fedora-logo| :ref:`Fedora <fedora-dep>` |arch-logo| :ref:`Arch Linux <arch-dep>`
28 |windows-logo| :ref:`Windows <windows-dep>` |macosx-logo| :ref:`macOS <macosx-dep>` |opensuse-logo| :ref:`openSUSE <opensuse-dep>`
29 =========================================== ======================================== ==============================================
30
31 .. _ubuntu-dep:
32
33 |ubuntu-logo| Ubuntu / |debian-logo| Debian
34 -------------------------------------------
35
36 .. code:: console
37
38 sudo apt-get install -y python3-venv python3-wheel python3-dev
39 sudo apt-get install -y gobject-introspection libgirepository-2.0-dev \
40 gir1.2-girepository-3.0 build-essential libbz2-dev libreadline-dev \
41 libssl-dev zlib1g-dev libsqlite3-dev wget curl llvm libncurses-dev \
42 xz-utils tk-dev libcairo2-dev
43
44
45 .. _fedora-dep:
46
47 |fedora-logo| Fedora
48 --------------------
49
50 .. code:: console
51
52 sudo dnf install -y python3-wheel
53 sudo dnf install -y gcc zlib-devel bzip2 bzip2-devel readline-devel \
54 sqlite sqlite-devel openssl-devel tk-devel git python3-cairo-devel \
55 cairo-gobject-devel gobject-introspection-devel
56
57
58 .. _arch-dep:
59
60 |arch-logo| Arch Linux
61 ----------------------
62
63 .. code:: console
64
65 sudo pacman -S --noconfirm python-wheel
66 sudo pacman -S --noconfirm base-devel openssl zlib git gobject-introspection
67
68
69 .. _opensuse-dep:
70
71 |opensuse-logo| openSUSE
72 ------------------------
73
74 .. code:: console
75
76 sudo zypper install -y python3-wheel gobject-introspection-devel \
77 python3-cairo-devel openssl zlib git
78 sudo zypper install --type pattern devel_basis
79
80
81 .. _windows-dep:
82
83 |windows-logo| Windows
84 ----------------------
85
86 To develop on Windows you need to have `MSYS2 <https://msys2.org>`_ installed.
87
88 .. code:: console
89
90 pacman -S --needed --noconfirm base-devel mingw-w64-ucrt-x86_64-toolchain git \
91 mingw-w64-ucrt-x86_64-python mingw-w64-ucrt-x86_64-pycairo \
92 mingw-w64-ucrt-x86_64-gobject-introspection mingw-w64-ucrt-x86_64-libffi
93
94 .. _macosx-dep:
95
96 |macosx-logo| macOS
97 -------------------
98
99 With homebrew:
100
101 .. code:: console
102
103 brew update
104 brew install python3 gobject-introspection libffi
105 export PKG_CONFIG_PATH=$(brew --prefix libffi)/lib/pkgconfig # use /usr/local/ for older Homebrew installs
106
107
108 .. _install-pyenv:
109
110 Install `pyenv`_ (Optional)
111 ===========================
112
113 `pyenv`_ lets you easily switch between multiple versions of Python.
114
115 ============================================= =========================================
116 |linux-logo| :ref:`Linux <linux-pyenv>` |macosx-logo| :ref:`macOS <macosx-pyenv>`
117 ============================================= =========================================
118
119 .. _linux-pyenv:
120
121 |linux-logo| Linux
122 ------------------
123
124 .. code:: console
125
126 curl https://pyenv.run | bash
127 exec $SHELL
128 pyenv install 3.11
129 pyenv global 3.11
130
131
132 .. _macosx-pyenv:
133
134 |macosx-logo| macOS
135 -------------------
136
137 .. code:: console
138
139 brew install pyenv
140 pyenv install 3.11
141 pyenv global 3.11
142
143
144 .. _projects-pygobject-dependencies:
145
146
147 *****************
148 Work on PyGObject
149 *****************
150
151 .. _platform-ind-steps:
152
153 Platform Independent Steps
154 ==========================
155
156
157 First, check out the source code:
158
159 .. code:: console
160
161 git clone https://gitlab.gnome.org/GNOME/pygobject.git
162 cd pygobject
163
164 With a local copy of PyGObject, there's three ways to start developing:
165
166 1. PDM, a modern Python package and dependency manager
167 2. Pip, the default Python package installer
168 3. Meson, use the Meson build system directly
169
170
171 PDM
172 ---
173
174 Make sure you have `PDM <https://pdm-project.org>`_ 2.13 or newer installed.
175
176 Then set up the project by running:
177
178 .. code:: console
179
180 pdm install
181
182 You can run the unit tests with:
183
184 .. code:: console
185
186 pdm run pytest
187
188
189 Pip
190 ---
191
192 It's always a good idea to work from within a Python virtual environment.
193 PyGObject is built with `Meson <https://mesonbuild.com/>`_.
194 In order to support
195 `editable installs <https://meson-python.readthedocs.io/en/latest/how-to-guides/editable-installs.html>`_,
196 Meson-python, Meson, and Ninja should be installed in the virtual environment.
197
198 .. code:: console
199
200 python3 -m venv .venv
201 source .venv/bin/activate
202 python3 -m pip install meson-python meson ninja pycairo pytest pre-commit
203
204 .. note::
205
206 For Python 3.12 and newer, also install ``setuptools``, since distutils is no longer provided in the standard library.
207
208 Install PyGObject in your local environment with the ``--no-build-isolation`` to allow for dynamic rebuilds
209
210 .. code:: console
211
212 pip install --no-build-isolation --config-settings=setup-args="-Dtests=true" -e '.[dev]'
213
214 By default the C libraries are built in "release" mode (no debug symbols).
215 To compile the C libraries with debug symbols, run
216
217 .. code:: console
218
219 pip install --no-build-isolation --config-settings=setup-args="-Dbuildtype=debug" --config-settings=setup-args="-Dtests=true" -e '.[dev]'
220
221 Open a Python console:
222
223 .. code:: python
224
225 from gi.repository import GObject
226
227 Run the unittests:
228
229 .. code:: console
230
231 pytest
232
233
234 Meson
235 -----
236
237 It's also possible to run the tests from Meson. Tests are still run with Pytest, so it's important
238 that Pytest is installed.
239
240 .. code:: console
241
242 meson setup _build # Needed only once
243 meson test -C _build
244
245
246 Contributing Changes
247 ====================
248
249 First off, thank you for considering contributing to PyGObject.
250 We really appreciate it!
251
252 * Create your own fork of the repository
253 * Add tests for your changes
254 * Do the changes in your fork
255 * If you like the change and think the project could use it:
256
257 * Make sure you are following the
258 `GNOME Code of Conduct <https://conduct.gnome.org>`_
259 * Be sure you have the pre-commit hook installed with:
260
261 .. code:: console
262
263 pre-commit install
264
265 It will ensure that lint and code formatting tools are run automatically.
266 * Commit your changes
267 * Create a merge request
268
269 .. _pyenv: https://github.com/pyenv/pyenv