diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 5438dabe..eb661f79 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 \ appstreamcli \ @@ -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 ``` -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) -[Glade](https://glade.gnome.org/) is the GUI tool we have been using for generating and managing application [windows and widgets](data/ui/). +```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 +``` -## Source code -```bash +### 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. +### 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 -``` \ No newline at end of file +``` + diff --git a/data/meson.build b/data/meson.build index 7eb59a61..f9d19af9 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 0d73029c..2a5b4e87 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,11 @@ -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 @@ -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'