Skip to content

Commit

Permalink
Fix missing udisk_lib for Linux machines
Browse files Browse the repository at this point in the history
Update `disks` package in pyproject.toml
  • Loading branch information
dormant-user committed Nov 29, 2024
1 parent 741732e commit 459e6b0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

<title>PyNinja &#8212; PyNinja documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

<title>Welcome to PyNinja’s documentation! &#8212; PyNinja documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
Expand Down Expand Up @@ -865,7 +865,7 @@ <h1>PyNinja - Executors<a class="headerlink" href="#pyninja-executors" title="Pe

<dl class="py function">
<dt class="sig sig-object py" id="pyninja.executors.squire.assert_pyudisk">
<span class="sig-prename descclassname"><span class="pre">pyninja.executors.squire.</span></span><span class="sig-name descname"><span class="pre">assert_pyudisk</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pyninja.executors.squire.assert_pyudisk" title="Permalink to this definition"></a></dt>
<span class="sig-prename descclassname"><span class="pre">pyninja.executors.squire.</span></span><span class="sig-name descname"><span class="pre">assert_pyudisk</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#pyninja.executors.squire.assert_pyudisk" title="Permalink to this definition"></a></dt>
<dd><p>Ensure disk_report is enabled only for Linux machines and load <code class="docutils literal notranslate"><span class="pre">udiskctl</span></code> library.</p>
</dd></dl>

Expand Down
25 changes: 14 additions & 11 deletions pyninja/executors/squire.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,23 @@ def dynamic_numbers(string: str) -> int | float | None:
return None


def assert_pyudisk():
def assert_pyudisk() -> None:
"""Ensure disk_report is enabled only for Linux machines and load ``udiskctl`` library."""
if models.env.disk_report:
assert models.OPERATING_SYSTEM == enums.OperatingSystem.linux, ValueError(
"\n\tdisk_report feature can be enabled only on Linux machines!"
)
try:
from pyudisk.config import EnvConfig as PyUdiskConfig
except (ImportError, ModuleNotFoundError):
if models.OPERATING_SYSTEM != enums.OperatingSystem.linux:
if models.env.disk_report:
raise ValueError(
"\n\tPyUdisk has not been installed. Use pip install 'PyNinja[extra]' to use disk reporting feature."
"\n\tdisk_report feature can be enabled only on Linux machines!"
)
if not models.env.udisk_lib:
models.env.udisk_lib = PyUdiskConfig().udisk_lib
return
try:
from pyudisk.config import EnvConfig as PyUdiskConfig
except (ImportError, ModuleNotFoundError):
if models.env.disk_report:
raise ValueError(
"\n\tPyUdisk has not been installed. Use pip install 'PyNinja[extra]' to view disk report metrics."
)
return
models.env.udisk_lib = models.env.udisk_lib or PyUdiskConfig().udisk_lib


def comma_separator(list_: list) -> str:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ packages = [
"pyninja.modules",
"pyninja.monitor",
"pyninja.routes",
"pyninja.features.disks",
"pyninja.monitor.templates"
]
[tool.setuptools.package-data]
Expand Down

0 comments on commit 459e6b0

Please sign in to comment.