fohrloop/wakepy

Add support for BSD systems

fohrloop opened this issue · 6 comments

Currently (v0.9.1), wakepy checks if platform.system() returns "Linux". All wakepy.Methods have to advertise which system they support.

Task:

  • Add support for BSD systems (FreeBSD, OpenBSD, GhostBSD, ...).

I'm just about to install GhostBSD 24.04.1 and try to make wakepy work on it.

This is what wakepy 0.9.1 gives on GhostBSD:

(venv) fohrloop@fohrloop-ghostbsd ~/c/wakepy (main)> wakepy
/home/fohrloop/code/wakepy/venv/lib/python3.9/site-packages/wakepy/core/platform.py:17: UserWarning: Could not detect current platform! platform.system() returned FreeBSD
  warnings.warn(
                  _
                 | |
 __      __ __ _ | | __ ___  _ __   _   _
 \ \ /\ / // _` || |/ // _ \| '_ \ | | | |
  \ V  V /| (_| ||   <|  __/| |_) || |_| |
   \_/\_/  \__,_||_|\_\\___|| .__/  \__, |
  v.0.9.1                   | |      __/ |
                            |_|     |___/ 
 [x] System will continue running programs
 [ ] Presentation mode is on

    Wakepy could not activate the "keep.running" mode. This might occur because
of a bug or because your current platform is not yet supported or your system is
missing required software.

    Check if there is already a related issue in the issue tracker at
https://github.com/fohrloop/wakepy/issues/ and if not, please create a new one.

    Include the following:
    - wakepy version: 0.9.1
    - Mode: keep.running
    - Python version: 3.9.18 (main, Apr 27 2024, 17:22:44)
[Clang 17.0.6 (https://github.com/llvm/llvm-project.git llvmorg-17.0.6-0-g60097
    - Operating system & version: [PLEASE FILL THIS]
    - Desktop Environment & version (if not default): [FILL OR REMOVE THIS LINE]
    - Additional details: [FILL OR REMOVE THIS LINE]

    Thank you!

This is what you can see in GhostBSD 24.04.1, CPython 3.9.18:

>>> os.name
'posix'
>>> sys.platform
'freebsd14'
>>> platform.system()
'FreeBSD'
>>> sysconfig.get_platform()
'freebsd-14.0-STABLE-amd64'

How wakepy works currently

  • The current "platform" is checked. The current platform is set to WINDOWS, MACOS, LINUX or OTHER
  • Each wakepy.Method has a list of supported platforms:
class SomeMethod(Method):
    supported_platforms = (PlatformName.LINUX,)
  • When looping over the potential wakepy.Methods to be used to activate a mode, the current platform is compared to the tuple Method.supported_platforms. If current platform is not in that tuple, the method fails.

How wakepy could work in the future

  • One problem with the current solution is that there's no pre-defined list of all platforms. The GhostBSD shows itself as "FreeBSD" in platform.system() because it's based on FreeBSD. But in the future it may show itself as "GhostBSD". It's also hard (or impossible) to have a perfect list of all platforms.
  • It would therefore be better if the "OTHER" would not fail the platform check, but give "I don't know" as an answer.
  • Another problem with the current solution is the need to update every Method definition when a new platform is added. For example, now when FREEBSD is added, should add that to the .supported_platforms of at least KDE and Gnome methods. When there's OPENBSD added, this has to be done again, and all methods will fail on OpenDSD if there's no such platform constant.

Proposed solution (option A)

  • Each wakepy.Method would have two lists: supported_platforms and unsupported_platforms
  • The platform support step would
    • fail if the current platform is in Method.unsupported_platforms (return False)
    • succeed if the current plarform is in Method.supported_platforms (return True)
    • Say "I don't know" otherwise. (return None)
  • The method prioritization step could prioritize all methods with a supported platform the highest, the unknown cases next, and put the unsupported (known to fail) methods last.

With the proposed solution, every wakepy method is tried on each unknown ("OTHER") platform, which is better than failing without trying any methods.

Proposed solution (option B)

  • Each wakepy.Method implements its own is_platform_supported method, which takes a platform (current platform) as an input and returns None (unknown) by default, and could also return True (is supported) or False (is not supported).
  • There could then be utility functions, like is_unix_like(platform) or is_bsd(platform)

Proposed solution (option C)

  • Some way to do
platform in PlatformSupport((UNIX,), unsupported=(WINDOWS, MACOS))

Here UNIX would be a special platform, which currently would say:

>>> LINUX in PlatformSupport(UNIX)
True
>>> WINDOWS in PlatformSupport(UNIX)
None
>>> OTHER in PlatformSupport(UNIX) # freebsd for example
None

but when UNIX is updated, it would be union of LINUX and BSD, and BSD would be union of all known BSDs, like FREEBSD, OPENBSD.

This way the Methods definitions would hardly ever require update. For example the method for Gnome could be PlatformSupport(UNIX, unsupported=MACOS), and then just the definition of UNIX would be updated in the future.