Skip to content

Commit

Permalink
Add logic to identify system pm
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteOtter committed Oct 9, 2023
1 parent 9a7a445 commit 5b5b2ee
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/nester/core/opinionated/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@


class UnsupportedLanguageException(Exception):
"""
This exception is raised, whenever the user tries to use opinionated creation for a language that does not
support this feature.
"""

def __str__(self) -> str:
return "\033[91mError: The chosen language is not supported for opinionated creation!\033[0m"
7 changes: 6 additions & 1 deletion src/nester/core/opinionated/opinionated_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ def install_build_system(language: str) -> None:
match language:
case "py":
for tool in supported_tools.py_build:
subprocess.run(["pip", "install", tool])
try:
subprocess.run(["pip", "install", tool])
except subprocess.CalledProcessError:
print(
"\033[91mError: Pip does not seem to be installed on your system. Install it and try again.\033[0m"
)
case _:
raise exceptions.UnsupportedLanguageException

Expand Down
2 changes: 2 additions & 0 deletions src/nester/core/opinionated/supported_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

py_build = ["setuptools", "setuptools-scm", "wheel"]
py_linters = ["black", "isort", "pylint"]

package_managers = ["zypper", "apt", "dnf"]
23 changes: 23 additions & 0 deletions src/nester/core/opinionated/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
This module provides support functionality for the opinionated creation module.
"""

import subprocess

from . import supported_tools


def identify_package_manager() -> str:
"""
Identify which distribution's package manager is installed via trial and error.
:return: The name of the package manager to be used to install dependencies.
:rtype: str
"""
for pm in supported_tools.package_managers:
try:
subprocess.run(pm)
except subprocess.CalledProcessError:
continue
return pm
return ""

0 comments on commit 5b5b2ee

Please sign in to comment.