Skip to content

Commit

Permalink
Add support for BSD + other *nix systems (#385)
Browse files Browse the repository at this point in the history
Closes: #359

Adds also support for other Unix-like systems with following conditions:

(1) If platform.system() returns one of 'Linux', 'FreeBSD', 'OpenBSD',
'NetBSD', 'DragonFly', 'SunOS', 'AIX', 'Minix', d-bus python library
jeepney is installed, which enables any D-Bus based methods.

(2) The system must be running a Desktop Environment that supports one
of the wakepy.Methods. Currently those are KDE
(org.freedesktop.PowerManagement) and GNOME (org.gnome.SessionManager)

Tested this on FreeBSD 14.1 + GNOME 42.5 and successfully prevented the
idle action (locking session + starting screensaver).
  • Loading branch information
fohrloop authored Sep 19, 2024
1 parent 1514b95 commit c258ea5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ htmlcov/
.tox/
.coverage
.ruff_cache
.mypy_cache

# pyenv
.python-version
Expand Down
5 changes: 5 additions & 0 deletions DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ python -m pip install -r requirements/requirements-dev.txt -e .

where `.` means the current directory (assuming cwd is at root of the repository).

### FreeBSD notes (installing for development)

- To install ruff, You need a recent version of Rust. Recommended to use rustup. You'll also need gmake.
- You'll also need the Standard Python binding to the SQLite3 library (py3**-sqlite3)

## Documentation

- The documentation is done with Sphinx and the source code lives at
Expand Down
2 changes: 2 additions & 0 deletions docs/source/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
### ✨ Features
- 📢 CLI arguments: Change `-k, --keep-running` to be `-r, --keep-running` and `-p, --presentation` to be `-p, --keep-presenting`; Be more consistent with the naming of the [Modes](#wakepy-modes). The old alternatives are deprecated and will be removed in a future release. ([#356](https://github.com/fohrloop/wakepy/pull/356))
- If platform is unknown to wakepy, do not fail any Method in the platform check phase anymore, but try to use it. This means for example that any system running GNOME that is not Linux (or BSD) could still use wakepy with the [org.gnome.SessionManager](https://wakepy.readthedocs.io/stable/methods-reference.html#org-gnome-sessionmanager) ([#379](https://github.com/fohrloop/wakepy/pull/379))
- Add support for BSD and other non-Linux Unix-like FOSS desktop systems. All systems running a supported Desktop Environment (currently: KDE, Gnome + other freedesktop compliant DEs) should be supported. ([#379](https://github.com/fohrloop/wakepy/pull/379), [#385](https://github.com/fohrloop/wakepy/pull/385))


### 🚨 Backwards incompatible
- Renamed [`PlatformName`](https://wakepy.readthedocs.io/v0.9.0.post1/api-reference.html#wakepy.core.constants.PlatformName) to [`PlatformType`](https://wakepy.readthedocs.io/v0.10.0/api-reference.html#wakepy.core.constants.PlatformType) and added new types: `ANY`, which means "any platform", `BSD`, meaning "any BSD system" in the future, but currently just FreeBSD / GhostBSD, and `UNIX_LIKE_FOSS`, which means "Unix-like desktop environment, but FOSS". Includes: Linux and BSD. Excludes: Android (mobile), MacOS (non-FOSS), ChromeOS (non-FOSS). Only affects you if you have created custom [Method](https://wakepy.readthedocs.io/v0.9.0.post1/api-reference.html#wakepy.Method) subclasses. ([#379](https://github.com/fohrloop/wakepy/pull/379))
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ authors = [
{name = "Niko Föhr", email = "fohrloop@gmail.com"},
]
dependencies = [
# For using the D-Bus based methods
"jeepney >= 0.7.1;sys_platform=='linux'",
# For using the D-Bus based methods. All Unix-öike FOSS desktop operating
# systems should be listed here (as they might use Gnome, XFCE, etc.)
# Full list of the environment markers at https://peps.python.org/pep-0508/
"jeepney >= 0.7.1;platform_system=='Linux' or platform_system=='FreeBSD' or platform_system=='OpenBSD' or platform_system=='NetBSD' or platform_system=='DragonFly' or platform_system=='SunOS' or platform_system=='AIX' or platform_system=='Minix'",
# The typing.Literal was introduced in Python 3.8. Need to install
# typing-extensions for Python 3.7 support.
'typing-extensions; python_version < "3.8.0"',
Expand Down
2 changes: 1 addition & 1 deletion src/wakepy/methods/freedesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FreedesktopInhibitorWithCookieMethod(Method):
"""Base class for freedesktop.org D-Bus based methods."""

service_dbus_address: DBusAddress
supported_platforms = (PlatformType.LINUX,)
supported_platforms = (PlatformType.UNIX_LIKE_FOSS,)

def __init__(self, **kwargs: object) -> None:
super().__init__(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion src/wakepy/methods/gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _GnomeSessionManager(Method, ABC):
params=("inhibit_cookie",),
).of(session_manager)

supported_platforms = (PlatformType.LINUX,)
supported_platforms = (PlatformType.UNIX_LIKE_FOSS,)

@property
@abstractmethod
Expand Down
22 changes: 20 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,28 @@
from __future__ import annotations

import os
import platform
import typing
from pathlib import Path

from colorama import Fore
from invoke import task # type: ignore

from wakepy.core import CURRENT_PLATFORM
from wakepy.core.platform import is_unix_like_foss

if typing.TYPE_CHECKING:
from invoke.runners import Result


def get_run_with_print(c):
def run_with_print(cmd: str, ignore_errors: bool = False) -> Result:
print("Running:", Fore.YELLOW, cmd, Fore.RESET)
res: Result = c.run(cmd, pty=platform.system() == "Linux", warn=ignore_errors)
res: Result = c.run(
cmd,
pty=is_unix_like_foss(CURRENT_PLATFORM),
warn=ignore_errors,
shell=get_shell(),
)
return res

return run_with_print
Expand Down Expand Up @@ -95,3 +103,13 @@ def test(c, pdb: bool = False) -> None:
run(f"coverage html && python -m webbrowser -t htmlcov{os.sep}index.html")

check(c)


def get_shell():
bash = "/bin/bash"
usr_bash = "/usr/local/bin/bash"
if Path(bash).exists():
return bash
elif Path(usr_bash).exists():
return usr_bash
raise RuntimeError("Could not find a shell to be be used with invoke!")

0 comments on commit c258ea5

Please sign in to comment.