hbutils.system.os

Operating System Utilities Module.

This module provides utilities for operating system operations, including executable detection and OS type identification.

The module exports functionality from two submodules:

  • executable: Functions for detecting and working with executable files in the system PATH

  • type: Functions for identifying operating system types (Linux, Windows, macOS)

This serves as a convenience module that aggregates OS-related utilities into a single namespace, allowing users to import all OS-related functionality from a single location.

Example::
>>> from hbutils.system.os import is_windows, where
>>> is_windows()
False
>>> where('python')
['/usr/bin/python', '/usr/local/bin/python']

is_linux

hbutils.system.os.is_linux() bool[source]

Check if the current operating system is Linux.

Return True if current operating system is linux, otherwise return False.

Returns:

This OS is linux or not.

Return type:

bool

Example::
>>> is_linux()  # On a Linux system
True
>>> is_linux()  # On a Windows system
False

is_windows

hbutils.system.os.is_windows() bool[source]

Check if the current operating system is Windows.

Return True if current operating system is windows, otherwise return False.

Returns:

This OS is windows or not.

Return type:

bool

Example::
>>> is_windows()  # On a Windows system
True
>>> is_windows()  # On a Linux system
False

is_darwin

hbutils.system.os.is_darwin() bool[source]

Check if the current operating system is Darwin (macOS).

Return True if current operating system is darwin, otherwise return False.

Returns:

This OS is darwin or not.

Return type:

bool

Note

Darwin is macOS.

Example::
>>> is_darwin()  # On a macOS system
True
>>> is_darwin()  # On a Linux system
False

is_macos

hbutils.system.os.is_macos = <function is_darwin>

Check if the current operating system is Darwin (macOS).

Return True if current operating system is darwin, otherwise return False.

Returns:

This OS is darwin or not.

Return type:

bool

Note

Darwin is macOS.

Example::
>>> is_darwin()  # On a macOS system
True
>>> is_darwin()  # On a Linux system
False

which

hbutils.system.os.which(execfile: str) str | None[source]

Returns first matching file path, which is the one when we operate in terminal.

This function returns the first executable file found in the system PATH, which is typically the one that would be executed when running the command in a terminal. Returns None if no matching executable is found.

Deprecated since version 0.9: Use the native shutil.which() instead. This function will be removed in version 1.0.

Parameters:

execfile (str) – Executable file to locate (such as python).

Returns:

Absolute path of the executable file, or None if not found.

Return type:

Optional[str]

Examples::
>>> from hbutils.system import which
>>>
>>> which('apt-get')
'/usr/bin/apt-get'
>>> which('bash')
'/usr/bin/bash'
>>> which('not_installed')
None

Deprecated since version 0.9: This will be removed in 1.0. Use the native shutil.which() instead

where

hbutils.system.os.where(execfile: str) List[str][source]

Returns all matching file paths for the given executable file.

This function searches through all directories in the system PATH environment variable and returns a list of all absolute paths where the executable file can be found. On Windows, it also checks for common executable extensions (.bat, .cmd, .com, .exe).

Parameters:

execfile (str) – Executable file to locate (such as python).

Returns:

The list of absolute paths of the executable files.

Return type:

List[str]

Examples::
>>> from hbutils.system import where
>>>
>>> where('apt-get')
['/usr/bin/apt-get', '/bin/apt-get']
>>> where('bash')
['/usr/bin/bash', '/bin/bash']
>>> where('not_installed')
[]