Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for nmstate C library on pip install #2627

Open
wants to merge 2 commits into
base: base
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions rust/src/python/setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,52 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

import ctypes
import sys
import setuptools
import subprocess


def requirements():
req = []
with open("requirements.txt") as fd:
with open("requirements.txt", encoding="utf-8") as fd:
for line in fd:
line.strip()
if not line.startswith("#"):
req.append(line)
return req


def check_nmstate_c_library():
if "bdist_rpm" not in sys.argv:
try:
# Run the find command
result = subprocess.run(
["find", "/", "-name", "libnmstate.so.2"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True,
)

# Check if the command was successful
if result.returncode == 0:
# Print the result
print("-----Found files:\n", result.stdout)
else:
# Print the error if the command failed
print("----The Error is:\n", result.stderr)
ctypes.cdll.LoadLibrary("libnmstate.so.2")
except OSError as exc:
raise RuntimeError(
"Error: nmstate C library not found. "
"Please install nmstate C library separately "
"before installing the Python package."
"See: https://nmstate.io/user/install.html"
) from exc


check_nmstate_c_library()


setuptools.setup(
name="nmstate",
version="2.2.32",
Expand Down
Loading