Skip to content

Commit

Permalink
feat: Support installation using pip (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
linkfrg authored Jan 13, 2025
1 parent 92a861c commit ae0af78
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 100 deletions.
44 changes: 37 additions & 7 deletions docs/dev/env.rst
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
Setting up a Development Environment
=====================================

Firstly, clone the repository:
This guide with walk you through process of setting up a Development Environment for working on Ignis.

Source
------

Firstly, you have to grab the Ignis sources:

.. code-block:: bash
# replace with the actual URL of your fork (if needed)
git clone https://github.com/linkfrg/ignis.git
cd ignis
Then, run the script:
Virtual Environment
-------------------

It's always a good practice to work within a Python virtual environment.

.. code-block:: bash
python -m venv venv
source venv/bin/activate # for fish: . venv/bin/activate.fish
Editable install
----------------

Ignis is build with Meson and meson-python.
In order to support editable installs, Meson-python, Meson, and Ninja should be installed in the virtual environment.

.. code-block:: python
pip install meson-python meson ninja
Now, install Ignis in the local virtual environment with the ``--no-build-isolation`` and ``-e`` options for an editable install.

.. code-block:: bash
pip install --no-build-isolation -e .
Additionally, you can install useful development tools by running:

.. code-block:: bash
bash tools/setup_devenv.sh
It will create a Python virtual environment,
install Ignis with its dependencies (including dev dependencies), and create a symbolic link to the Ignis source files.
pip install -r dev.txt
Done!

Now you can edit the ``ignis`` directory at the root of the repository,
You can now edit the ``ignis`` directory at the root of the repository,
and the changes will be applied without the need to reinstall Ignis.
36 changes: 35 additions & 1 deletion docs/user/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,40 @@ Then add the following to ``environment.systemPackages`` or ``home.packages``:
inputs.ignis.packages.${system}.ignis
Pip
----

Pip is the standard package manager for Python.
You can install Ignis directly from the Git repository using Pip.

.. hint::

You can do this in a Python virtual environment.
Create and activate one with the following commands:

.. code-block:: bash
python -m venv venv
source venv/bin/activate # for fish: . venv/bin/activate.fish
To install the latest (Git) version of Ignis:

.. code-block:: bash
pip install git+https://github.com/linkfrg/ignis.git
To install a specific version (e.g., ``v0.5``):

.. code-block:: bash
# replace "TAG" with the desired Git tag
pip install git+https://github.com/linkfrg/ignis.git@TAG
.. seealso::

For advanced usage, you can `set up a development environment <../dev/env.html>`_ and install Ignis in editable mode.
This allows you to easily switch between commits, versions, branches, or pull requests using `git`, without having to reinstall Ignis.

Building from source
---------------------

Expand All @@ -66,7 +100,7 @@ Building from source
git clone https://github.com/linkfrg/ignis.git
cd ignis
meson setup build --prefix=/usr --libdir "lib/ignis"
meson setup build --prefix=/usr
meson compile -C build
meson install -C build
Expand Down
17 changes: 13 additions & 4 deletions ignis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
from ctypes import CDLL
from gi.repository import GLib # type: ignore
from ignis._get_lib_dir import get_lib_dir

__version__ = "0.4.dev0"
__lib_dir__ = None
Expand All @@ -29,8 +28,18 @@
try:
from gi.repository import GIRepository # type: ignore

__lib_dir__ = get_lib_dir()
GIRepository.Repository.prepend_library_path(__lib_dir__) # type: ignore
GIRepository.Repository.prepend_search_path(__lib_dir__) # type: ignore
current_dir = os.path.dirname(os.path.abspath(__file__))
build_libdir = os.path.join(
os.path.abspath(os.path.join(current_dir, "..")),
"build",
f"cp{sys.version_info.major}{sys.version_info.minor}",
"subprojects",
"gvc",
)

for directory in current_dir, build_libdir:
GIRepository.Repository.prepend_library_path(directory)
GIRepository.Repository.prepend_search_path(directory)

except TypeError:
pass
1 change: 0 additions & 1 deletion ignis/__lib_dir__.py.in

This file was deleted.

21 changes: 0 additions & 21 deletions ignis/_get_lib_dir.py

This file was deleted.

26 changes: 5 additions & 21 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
project(
'ignis',
license: 'GPL-3.0-only',
version: run_command(['tools/get_version.py'], check: true).stdout().strip(),
default_options: ['warning_level=2', 'werror=false']
)


# Find Python installation
python = import('python').find_installation()
python = import('python').find_installation(pure: false)

# Set folders
prefix = get_option('prefix')
datadir = join_paths(prefix, get_option('datadir'))
libdir = join_paths(prefix, get_option('libdir'))
bindir = get_option('bindir')

pylibdir = python.get_install_dir()

pkgdatadir = join_paths(datadir, meson.project_name())

pkginstalldir = join_paths(pylibdir, meson.project_name())

# Dependencies
Expand All @@ -31,8 +25,6 @@ dependency('gtk4-layer-shell-0')
subproject('gvc',
default_options: [
'package_name=' + meson.project_name(),
'pkgdatadir=' + pkgdatadir,
'pkglibdir=' + libdir,
'static=false',
'introspection=true',
'alsa=false'
Expand All @@ -46,10 +38,9 @@ install_subdir(
)

config = configuration_data()
config.set('LIB_DIR', libdir)
config.set('COMMIT', run_command('git', 'rev-parse', 'HEAD').stdout().strip())
config.set('BRANCH', run_command('git', 'branch', '--show-current').stdout().strip())
config.set('COMMIT_MSG', run_command('git', 'log', '-1', '--pretty=%B').stdout().strip())
config.set('COMMIT', run_command('git', 'rev-parse', 'HEAD', check: false).stdout().strip())
config.set('BRANCH', run_command('git', 'branch', '--show-current', check: false).stdout().strip())
config.set('COMMIT_MSG', run_command('git', 'log', '-1', '--pretty=%B', check: false).stdout().strip())

install_data(
files('bin/ignis'),
Expand All @@ -63,10 +54,3 @@ configure_file(
configuration: config,
install_dir: pkginstalldir
)

configure_file(
input: 'ignis/__lib_dir__.py.in',
output: '__lib_dir__.py',
configuration: config,
install_dir: pkginstalldir
)
13 changes: 6 additions & 7 deletions nix/ignis.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{ fetchFromGitLab, pkgs, version ? "git", ... }:
{ fetchFromGitHub, pkgs, version ? "git", ... }:
let
inherit (pkgs.lib) concatStringsSep;

gvc = fetchFromGitLab {
domain = "gitlab.gnome.org";
owner = "GNOME";
repo = "libgnome-volume-control";
rev = "5f9768a2eac29c1ed56f1fbb449a77a3523683b6";
hash = "sha256-gdgTnxzH8BeYQAsvv++Yq/8wHi7ISk2LTBfU8hk12NM=";
gvc = fetchFromGitHub {
owner = "linkfrg";
repo = "libgnome-volume-control-wheel";
rev = "60c21982203cad242938efb6295e535e1c28a10d";
hash = "sha256-ts7GKD1eXGEx/2/2NBDDx+QhumlydMh8pnQtzpCBGUU=";
};
in
pkgs.stdenv.mkDerivation {
Expand Down
55 changes: 40 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
[project]
name = 'ignis'
description = 'A modern widget system'
readme = 'README.md'
license = { file = 'LICENSE' }
authors = [{ name = 'linkfrg' }]
dynamic = ['version']
dependencies = [
"click>=8.1.7",
"pycairo>=1.26.1",
"PyGObject>=3.48.2",
"requests>=2.32.3",
"loguru>=0.7.2",
]

[project.urls]
Homepage = "https://linkfrg.github.io/ignis"
Documentation = "https://linkfrg.github.io/ignis"
Repository = "https://github.com/linkfrg/ignis"
Issues = "https://github.com/linkfrg/ignis/issues"

[build-system]
build-backend = 'mesonpy'
requires = ['meson-python', 'setuptools']

[tool.mypy]
python_version = "3.10"
packages = ["ignis", "examples"]
exclude = ["venv"]
disable_error_code = [
"no-redef", # allow variable redefinition (needed for GObject.Property decorator)
"method-assign" # also needed for GObject.Property
"no-redef", # allow variable redefinition (needed for GObject.Property decorator)
"method-assign", # also needed for GObject.Property
]
mypy_path = ["stubs"]
check_untyped_defs = true
Expand All @@ -18,21 +43,21 @@ include = ["ignis/**/*.py", "examples/**/*.py"]

[tool.ruff.lint]
select = [
"F", # pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"I", # isort
"UP", # pyupgrade
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"F", # pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"I", # isort
"UP", # pyupgrade
"B", # flake8-bugbear
"C4", # flake8-comprehensions
]
ignore = [
"E501", # line too long, handled by black
"B008", # do not perform function calls in argument defaults
"C901", # too complex
"W191", # indentation contains tabs
"I001", # import block is un-sorted or un-formatted
"E501", # line too long, handled by black
"B008", # do not perform function calls in argument defaults
"C901", # too complex
"W191", # indentation contains tabs
"I001", # import block is un-sorted or un-formatted
]

fixable = ["ALL"]
unfixable = []
unfixable = []
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ click>=8.1.7
pycairo>=1.26.1
PyGObject>=3.48.2
requests>=2.32.3
setuptools>=72.1.0
loguru>=0.7.2
4 changes: 2 additions & 2 deletions subprojects/gvc.wrap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[wrap-git]
url = https://gitlab.gnome.org/GNOME/libgnome-volume-control.git
revision = master
url = https://github.com/linkfrg/libgnome-volume-control-wheel.git
revision = main
12 changes: 12 additions & 0 deletions tools/get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3
"""Extract version number from __init__.py"""
import os

init_py = os.path.join(os.path.dirname(__file__), "../ignis/__init__.py")

data = open(init_py).readlines()
version_line = next(line for line in data if line.startswith("__version__ ="))

version = version_line.strip().split(" = ")[1].replace('"', "").replace("'", "")

print(version)
20 changes: 0 additions & 20 deletions tools/setup_devenv.sh

This file was deleted.

0 comments on commit ae0af78

Please sign in to comment.