Skip to content

Commit

Permalink
setup.py: Add automatic installation of nmstate C library
Browse files Browse the repository at this point in the history
This commit adds functionality to the setup.py script to automatically install the nmstate C library if it's not found on the system during installation. This enhancement ensures a smoother installation process for users by handling the dependency on the nmstate C library automatically.

The script checks for the presence of the nmstate package, and if it's not found, it attempts to install the C library using the install_nmstate_lib() function. If the installation fails, an error message is printed to the console, guiding the user to install the nmstate C library separately before retrying the installation of the Python package.

Signed-off-by: jona42-ui <jonathanthembo123@gmail.com>
  • Loading branch information
jona42-ui committed Mar 26, 2024
1 parent 65c77a2 commit 0be45b0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions rust/src/python/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

import subprocess
import sys
import setuptools


Expand All @@ -13,6 +15,24 @@ def requirements():
return req


def install_nmstate_lib():
try:
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "nmstate"]
)
except subprocess.CalledProcessError as e:
print("Error installing nmstate C library:", e)
sys.exit(1)


try:
import nmstate # noqa: F401

print("nmstate C library found. No further action needed.")
except ImportError:
print("nmstate C library not found. Attempting to install...")
install_nmstate_lib()

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

0 comments on commit 0be45b0

Please sign in to comment.