Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build system and development instructions #800

Merged
merged 6 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 64 additions & 38 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# Cozy development

This document is intended for software engineers and translators who would like to help out with the development of Cozy or simply be able to run bleeding edge versions of the code locally.
This document is intended for software engineers and translators who would like to help out with the development of Cozy, or simply be able to run bleeding edge versions of the code locally.

## Ubuntu

_The below instructions have been tested on Ubuntu 20.04_
## Building with GNOME Builder (recommended)

## Requirements
Cozy can be built and run with [GNOME Builder](https://apps.gnome.org/Builder/).

```bash
1. Open GNOME Builder
2. Click the **Clone Repository** button
3. Enter `https://github.com/geigi/cozy.git` in the **Repository URL** field
4. Click the **Clone Project** button
5. Click the ▶️**Run** button to start building the application


## Building manually

_The below instructions have been tested on Ubuntu 20.04 and Fedora 39_


### Requirements (Ubuntu)

```console
sudo apt update
sudo apt install \
appstreamcli \
Expand All @@ -21,86 +34,99 @@ sudo apt install \
gstreamer1.0-plugins-ugly \
libgirepository1.0-dev \
libgstreamer1.0-0 \
libgtk-3-dev \
libgtk-4-dev \
libadwaita-1-dev
pip \
python-gi-cairo \
python3-gst-1.0 \
python3-venv

sudo add-apt-repository ppa:apandada1/libhandy-1
sudo apt update
sudo apt install libhandy-1-0 libhandy-1-dev
```
rdbende marked this conversation as resolved.
Show resolved Hide resolved

In case of issues with the `libhandy` installation, please refer to our [GitHub build script](.github/workflows/build.yml) on an alternative source of the library packages.

### UI development
### Requirements (Fedora)

```console
sudo dnf install\
appstream\
cmake\
gettext\
gstreamer1-libav\
gstreamer1-plugins-ugly\
gstreamer1-plugins-bad\
gstreamer1-plugins-good\
gstreamer1-devel\
gtk4-devel\
libadwaita-devel\
pipenv\
python3-cairo-devel\
python3-gstreamer1\
```

[Glade](https://glade.gnome.org/) is the GUI tool we have been using for generating and managing application [windows and widgets](data/ui/).

## Source code
### Source code

```bash
```console
git clone https://github.com/geigi/cozy.git
cd cozy
```

## Python packages

It is generally a good idea to set up a virtual environment to avoid referencing packages and the Python binary installed globally.
### Python packages

> At its core, the main purpose of Python virtual environments is to create an isolated environment for Python projects. This means that each project can have its own dependencies, regardless of what dependencies every other project has.
>
> realpython.com
> [!TIP]
> It is generally a good idea to set up a virtual environment for Python projects. It creates an isolated environment where packages can be installed without creating conflicts with other packages installed system-wide.

```bash
# only if you wish to use a virtual environment
```console
python3 -m venv venv
source ./venv/bin/activate

python -m pip install --upgrade pip
pip install -r requirements.txt

pip install \
meson \
ninja
pip install meson ninja

pip install \
pytest \
pytest-mock
pip install pytest pytest-mock
```

## Build and install
To enter the virtual environment, you will need to run `source ./venv/bin/activate` every time you reopen your terminal.


### Build and install

Let's assume you wish to build the application under the `build/` directory and install the binaries under `app/`:

```bash
meson --prefix=$(pwd)/app ./build
```console
meson setup --prefix=$(pwd)/app ./build

ninja -C build install
```


### Install translation files

```bash
```console
ninja -C build com.github.geigi.cozy-update-po
ninja -C build extra-update-po
```

## Run application

```bash
### Run application

```console
XDG_DATA_DIRS=app/share:/usr/share \
PYTHONPATH=app/lib/python3.8/site-packages \
PYTHONPATH=app/lib/python3.11/site-packages \
app/bin/com.github.geigi.cozy
```

Your Python path may be different so you might need to amend the `PYTHONPATH` environment variable above in case of errors.

Please note, every time you make code changes, you need to execute `ninja -C build install` before you run the application.
> [!NOTE]
> Every time you make changes to the code, you need to execute `ninja -C build install` before you run the application.


## Test
## Running the test suite

```bash
python -m pytest
```
```

4 changes: 2 additions & 2 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ endif
desktop_file = i18n.merge_file(
input: meson.project_name() + '.desktop',
output: meson.project_name() + '.desktop',
po_dir: join_paths(meson.source_root(), 'po', 'extra'),
po_dir: join_paths(meson.current_source_dir(), 'po', 'extra'),
type: 'desktop',
install: true,
install_dir: join_paths(get_option('datadir'), 'applications')
Expand All @@ -33,7 +33,7 @@ endif
appstream_file = i18n.merge_file(
input: meson.project_name() + '.appdata.xml',
output: meson.project_name() + '.appdata.xml',
po_dir: join_paths(meson.source_root(), 'po', 'extra'),
po_dir: join_paths(meson.current_source_dir(), 'po', 'extra'),
install: true,
install_dir: join_paths(get_option('datadir'), 'metainfo')
)
Expand Down
41 changes: 21 additions & 20 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
project('com.github.geigi.cozy', version: '1.3.0')
project('com.github.geigi.cozy', version: '1.3.0', meson_version: '>= 0.59.0')

python = import('python3')
python = import('python')
i18n = import('i18n')
gnome = import('gnome')

message('Looking for dependencies')
python_bin = python.find_python()
python_bin = python.find_installation('python3')
if not python_bin.found()
error('No valid python3 binary found')
else
message('Found python3 binary')
endif

dependency('glib-2.0')
dependency('libadwaita-1', version: '>= 1.0.0')
dependency('libadwaita-1', version: '>= 1.4.0')

# from https://github.com/AsavarTzeth/pulseeffects/blob/master/meson.build
# Support Debian non-standard python paths
# Fallback to Meson python3 module if command fails
# Fallback to Meson python module if command fails
message('Getting python install path')
py3_purelib = ''
r = run_command(python_bin.path(), '-c', 'from distutils.sysconfig import get_python_lib; print(get_python_lib(prefix=""))')
r = run_command(
python_bin.full_path(),
'-c',
'from distutils.sysconfig import get_python_lib; print(get_python_lib(prefix=""))',
check: false,
)

if r.returncode() != 0
py3_purelib = python.sysconfig_path('purelib')
py3_purelib = python_bin.get_path('purelib')
if not py3_purelib.endswith('site-packages')
error('Cannot find python install path')
endif
Expand All @@ -37,7 +43,7 @@ python3_required_modules = ['distro', 'peewee', 'mutagen', 'gi']
foreach p : python3_required_modules
# Source: https://docs.python.org/3/library/importlib.html#checking-if-a-module-can-be-imported
script = 'import importlib.util; import sys; exit(1) if importlib.util.find_spec(\''+ p +'\') is None else exit(0)'
if run_command(python_bin, '-c', script).returncode() != 0
if run_command(python_bin, '-c', script, check: false).returncode() != 0
error('Required Python3 module \'' + p + '\' not found')
endif
endforeach
Expand All @@ -50,10 +56,10 @@ conf.set('PACKAGE_URL', 'https://github.com/geigi/cozy')
conf.set('DATA_DIR', DATA_DIR)
conf.set('LOCALE_DIR', join_paths(get_option('prefix'), get_option('datadir'), 'locale'))
conf.set('PYTHON_DIR', python_dir)
conf.set('PYTHON_EXEC_DIR', join_paths(get_option('prefix'), python.sysconfig_path('stdlib')))
conf.set('PYTHON_EXEC_DIR', join_paths(get_option('prefix'), python_bin.get_path('stdlib')))
conf.set('libexecdir', LIBEXEC_DIR)
conf.set('VERSION', meson.project_version())
conf.set('PYTHON', python_bin.path())
conf.set('PYTHON', python_bin.full_path())
conf.set('INSTALLED', 'true')

subdir('data')
Expand Down Expand Up @@ -88,13 +94,8 @@ configure_file(
install_dir: python_dir + '/cozy/report'
)

if meson.version().version_compare('>=0.57.0')
gnome.post_install(
glib_compile_schemas: true,
gtk_update_icon_cache: true,
)
else
meson.add_install_script('meson/post_install_legacy.py')
endif

meson.add_install_script('meson/post_install_desktop_database.py')
gnome.post_install(
glib_compile_schemas: true,
gtk_update_icon_cache: true,
update_desktop_database: true,
)
11 changes: 0 additions & 11 deletions meson/post_install_desktop_database.py

This file was deleted.

16 changes: 0 additions & 16 deletions meson/post_install_legacy.py

This file was deleted.

2 changes: 1 addition & 1 deletion po/extra/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
i18n.gettext('extra',
args: [
'--directory=' + meson.source_root(),
'--directory=' + meson.current_source_dir(),
'--from-code=UTF-8'
],
preset: 'glib',
Expand Down
2 changes: 1 addition & 1 deletion po/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
i18n.gettext(meson.project_name(),
args: [
'--directory=' + meson.source_root(),
'--directory=' + meson.current_source_dir(),
'--from-code=UTF-8'
],
preset: 'glib'
Expand Down