From 62dee101a8c1a3537e78f2cd33c5e49ad325630f Mon Sep 17 00:00:00 2001 From: rdbende Date: Sat, 25 Nov 2023 21:49:59 +0100 Subject: [PATCH 1/4] Update build system --- DEVELOPMENT.md | 17 +++-------- data/meson.build | 4 +-- meson.build | 41 +++++++++++++------------- meson/post_install_desktop_database.py | 11 ------- meson/post_install_legacy.py | 16 ---------- po/extra/meson.build | 2 +- po/meson.build | 2 +- 7 files changed, 29 insertions(+), 64 deletions(-) delete mode 100755 meson/post_install_desktop_database.py delete mode 100755 meson/post_install_legacy.py diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c922ca3b..789eea3e 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -21,23 +21,14 @@ 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 ``` -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 - -[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 ```bash @@ -75,7 +66,7 @@ pip 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 +meson setup --prefix=$(pwd)/app ./build ninja -C build install ``` @@ -103,4 +94,4 @@ Please note, every time you make code changes, you need to execute `ninja -C bui ```bash python -m pytest -``` \ No newline at end of file +``` diff --git a/data/meson.build b/data/meson.build index a32d61bc..ea1402f0 100644 --- a/data/meson.build +++ b/data/meson.build @@ -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') @@ -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') ) diff --git a/meson.build b/meson.build index 36700911..214ed644 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,11 @@ -project('com.github.geigi.cozy', version: '1.2.1') +project('com.github.geigi.cozy', version: '1.2.1', 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 @@ -13,16 +13,22 @@ else 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 @@ -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 @@ -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') @@ -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') \ No newline at end of file +gnome.post_install( + glib_compile_schemas: true, + gtk_update_icon_cache: true, + update_desktop_database: true, +) diff --git a/meson/post_install_desktop_database.py b/meson/post_install_desktop_database.py deleted file mode 100755 index ef348dc3..00000000 --- a/meson/post_install_desktop_database.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python3 - -from os import environ, path -from subprocess import call - -prefix = environ.get('MESON_INSTALL_PREFIX', '/usr/local') -datadir = path.join(prefix, 'share') -destdir = environ.get('DESTDIR', '') - -print('Updating desktop database...') -call(['update-desktop-database', '-q', path.join(datadir, 'applications')]) \ No newline at end of file diff --git a/meson/post_install_legacy.py b/meson/post_install_legacy.py deleted file mode 100755 index 7eb2bf3c..00000000 --- a/meson/post_install_legacy.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python3 - -from os import environ, path -from subprocess import call - -prefix = environ.get('MESON_INSTALL_PREFIX', '/usr/local') -datadir = path.join(prefix, 'share') -destdir = environ.get('DESTDIR', '') - -# Package managers set this so we don't need to run -if not destdir: - print('Updating icon cache...') - call(['gtk-update-icon-cache', '-qtf', path.join(datadir, 'icons', 'hicolor')]) - - print('Compiling GSettings schemas...') - call(['glib-compile-schemas', path.join(datadir, 'glib-2.0', 'schemas')]) diff --git a/po/extra/meson.build b/po/extra/meson.build index 404605dd..d9851ffc 100644 --- a/po/extra/meson.build +++ b/po/extra/meson.build @@ -1,6 +1,6 @@ i18n.gettext('extra', args: [ - '--directory=' + meson.source_root(), + '--directory=' + meson.current_source_dir(), '--from-code=UTF-8' ], preset: 'glib', diff --git a/po/meson.build b/po/meson.build index 9e4ea075..a860fcc5 100644 --- a/po/meson.build +++ b/po/meson.build @@ -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' From c0a1090450f2acd1121e18c9c27f00b3d10420e9 Mon Sep 17 00:00:00 2001 From: rdbende Date: Wed, 29 Nov 2023 17:41:36 +0100 Subject: [PATCH 2/4] Restructure it a bit, add GNOME Builder info and Fedora dependencies --- DEVELOPMENT.md | 91 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 28 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 789eea3e..10de59d7 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -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 \ appstream-util \ @@ -29,69 +42,91 @@ sudo apt install \ python3-venv ``` -## Source code -```bash +### 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\ +``` + + +### Obtain the source code + +```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. +### Set up Python -> 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 +```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 ``` + From 6baaf18dc16e5630430d0d17c96ca1e5481aa775 Mon Sep 17 00:00:00 2001 From: rdbende Date: Wed, 29 Nov 2023 17:49:47 +0100 Subject: [PATCH 3/4] Better section titles --- DEVELOPMENT.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 10de59d7..1b3e1508 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -63,7 +63,7 @@ sudo dnf install\ ``` -### Obtain the source code +### Source code ```console git clone https://github.com/geigi/cozy.git @@ -71,7 +71,7 @@ cd cozy ``` -### Set up Python +### Python packages > [!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. From ca6ec9d0e8df7a56ee464fbdb4c4518b267ca8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20D=C3=A9v=C3=A9nyi?= Date: Wed, 6 Dec 2023 16:19:50 +0100 Subject: [PATCH 4/4] Add missing backslash and some spaces --- DEVELOPMENT.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 0b2005c8..eb661f79 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -35,7 +35,7 @@ sudo apt install \ libgirepository1.0-dev \ libgstreamer1.0-0 \ libgtk-4-dev \ - libadwaita-1-dev + libadwaita-1-dev \ pip \ python-gi-cairo \ python3-gst-1.0 \ @@ -46,20 +46,20 @@ sudo apt install \ ### Requirements (Fedora) ```console -sudo dnf install\ - appstream\ - cmake\ - gettext\ - gstreamer1-libav\ - gstreamer1-plugins-ugly\ - gstreamer1-plugins-bad\ - gstreamer1-plugins-good\ +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\ + gtk4-devel \ + libadwaita-devel \ + pipenv \ + python3-cairo-devel \ + python3-gstreamer1 ```