Skip to content

Commit 2d613aa

Browse files
authored
[CODE REFACTOR: lua/LazyDeveloperHelper/python/* | NEW FILE/DIR: lua/LazyDeveloperHelper/python/logger.py, lua/LazyDeveloperHelper/python/c_installers/nuget_install.py] (#108)
2 parents 2c9009b + c2ec916 commit 2d613aa

File tree

9 files changed

+58
-53
lines changed

9 files changed

+58
-53
lines changed

lua/LazyDeveloperHelper/python/c_installers/__init__.py

Whitespace-only changes.

lua/LazyDeveloperHelper/python/c_installers/conan_install.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
#!/usr/bin/python3
2-
# -*- coding: utf-8 -*-
32

43
import shutil as sh
54
import sys
65
from subprocess import run, CalledProcessError
76
import os
87
import re
98

9+
from ..logger import log_message
10+
1011
# --- VARIABLES ---
1112
CONAN = sh.which("conan")
1213

1314

14-
# --- LOGGING MESSAGE ---
15-
def log_message(message: str, level: str = "info") -> None:
16-
prefixes = {
17-
"info": "\U0001f4cd", # 📍
18-
"success": "\U0001f4e6", # 📦
19-
"error": "\u274c", # ❌
20-
}
21-
22-
prefix = prefixes.get(level, "📍")
23-
print(f"{prefix} {message}")
24-
25-
2615
# --- CHECK CONAN EXIST ---
2716
def conan_exist():
2817
if CONAN:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import shutil as sh
2+
import sys
3+
from subprocess import run, CalledProcessError
4+
5+
from ..logger import log_message
6+
7+
8+
# --- CHECK NuGet is exist ---
9+
def nuget_exist() -> bool:
10+
dotnet_path = sh.which("dotnet")
11+
if dotnet_path:
12+
log_message("Dotnet exists!", "info")
13+
return True
14+
else:
15+
log_message("Dotnet isnt exists, try install it!", "critical")
16+
return False
17+
18+
19+
# --- INSTALLLING LIBS ---
20+
def install_lib(lib_name: str):
21+
message_for_run = ["dotnet", "add", "package", lib_name]
22+
try:
23+
result = run(message_for_run, check=True, capture_output=True, text=True)
24+
log_message(f"NuGet install output:\n{result.stdout}", "info")
25+
except CalledProcessError as err:
26+
log_message(f"Dotnet install failed:\n{err.stderr}", "error")
27+
28+
29+
# --- POINT OF ENTER ---
30+
if __name__ == "__main__":
31+
if not nuget_exist():
32+
sys.exit(1)
33+
34+
for lib in sys.argv[1:]:
35+
install_lib(lib)

lua/LazyDeveloperHelper/python/cargo_install.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@
55
from subprocess import run, CalledProcessError
66
from shutil import which
77
from functools import lru_cache
8+
from logger import log_message
9+
810

911
# --- VARIABLES ---
1012
CARGO_TOML = "Cargo.toml"
1113
cargo_path = which("cargo")
1214

1315

14-
# --- INITIALIZE LOGGING MESSAGE
15-
def log_message(message: str, level: str = "info") -> None:
16-
"""Print a formatted message with an emoji prefix."""
17-
prefixes = {"info": "📍", "success": "📦", "error": "❌"}
18-
print(f"{prefixes.get(level, '📍')} {message}")
19-
20-
2116
# --- CACHE Cargo.toml LOCATION ---
2217
@lru_cache(maxsize=1)
2318
def find_cargo_toml(start_dir: str = ".") -> str | None:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
# --- LOGGING MESSAGE ---
5+
def log_message(message: str, level: str = "info") -> None:
6+
prefixes = {
7+
"info": "\U0001f4cd", # 📍
8+
"success": "\U0001f4e6", # 📦
9+
"error": "\u274c", # ❌
10+
}
11+
12+
print(f"{prefixes.get(level, '\U0001f4cd')} {message}")

lua/LazyDeveloperHelper/python/luarocks_install.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,13 @@
66
import argparse
77
from subprocess import run, CalledProcessError
88
from shutil import which
9+
from logger import log_message
910

1011
# --- VARIABLES ---
1112
LUAROCKS_FLAG = "--local"
1213
luarocks_path = which("luarocks")
1314

1415

15-
# --- LOGGING MESSAGE ---
16-
def log_message(message: str, level: str = "info") -> None:
17-
prefixes = {
18-
"info": "\U0001f4cd", # 📍
19-
"success": "\U0001f4e6", # 📦
20-
"error": "\u274c", # ❌
21-
}
22-
23-
print(f"{prefixes.get(level, '\U0001f4cd')} {message}")
24-
25-
2616
# --- CHECKING LIBRARY NAME ---
2717
def validate_library_name(lib: str) -> bool:
2818
if not lib or any(c in lib for c in '<>|&;"'):

lua/LazyDeveloperHelper/python/npm_install.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
from subprocess import run, CalledProcessError, PIPE
33
from shutil import which
44
import sys
5+
from logger import log_message
56

67
# --- npm PATH ---
78
npm_path = which("npm")
89

910

10-
# --- LOGGING MESSAGE ---
11-
def log_message(message: str, level: str = "info") -> None:
12-
prefixes = {"info": "📍", "success": "📦", "error": "❌"}
13-
print(f"{prefixes.get(level, '📍')} {message}")
14-
15-
1611
# --- CHECKING npm INSTALLED
1712
def check_npm_installed() -> bool:
1813
if not npm_path:

lua/LazyDeveloperHelper/python/pip_install.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from subprocess import run, CalledProcessError
66
from shutil import which
77
from typing import Set
8+
from logger import log_message
89

910

10-
# LOGGING MESSAGE ---
1111
def check_pip_installed() -> bool:
1212
"""Check if pip3 is installed and available in PATH."""
1313
pip_path = which("pip3")
@@ -17,11 +17,6 @@ def check_pip_installed() -> bool:
1717
return True
1818

1919

20-
def log_message(message: str, level: str = "info") -> None:
21-
prefixes = {"info": "📍", "success": "📦", "error": "❌"}
22-
print(f"{prefixes.get(level, '📍')} {message}")
23-
24-
2520
# --- VALIDATE LIB NAME
2621
def validate_library_name(lib_name: str) -> bool:
2722
"""Check if the library name is valid."""
@@ -74,7 +69,7 @@ def install_lib(
7469
file.write(f"{lib_name}\n")
7570
libs_list.add(lib_name.lower())
7671

77-
# Read existing libs (case-insensitive)
72+
# Read existing libs (case-sensetive)
7873
libs_set: Set[str] = set()
7974
try:
8075
with open(req_path, "r", encoding="utf-8") as file:
@@ -100,8 +95,6 @@ def install_lib(
10095
if flag == "-quiet":
10196
pip_args.append("-q")
10297
try:
103-
# Safely calling pip from argument list, without shell=True (as it was
104-
# in previous commit)
10598
result = run(
10699
pip_args,
107100
check=True,
@@ -113,11 +106,13 @@ def install_lib(
113106

114107
if "requirement already satisfied" in stdout_lower:
115108
log_message(f"{lib_name} already installed", "success")
109+
116110
elif "successfully installed" in stdout_lower:
117111
# Find the line with "Successfully installed {lib_name}
118112
for line in stdout.splitlines():
119113
if "Successfully installed" in line:
120114
log_message(line.strip(), "success")
115+
121116
# If somewhat went wrong
122117
else:
123118
log_message(f"{lib_name} installation output:", "info")

lua/LazyDeveloperHelper/python/ruby_gem_install.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
from subprocess import run, CalledProcessError, PIPE
44
from shutil import which
55
import sys
6-
7-
8-
# --- LOGGING MESSAGE ---
9-
def log_message(message: str, level: str = "info") -> None:
10-
"""Log a message with a specified level (info, success, error)."""
11-
prefixes = {"info": "📍", "success": "📦", "error": "❌"}
12-
print(f"{prefixes.get(level, '📍')} {message}")
6+
from logger import log_message
137

148

159
# -- VARIABLES --

0 commit comments

Comments
 (0)