Skip to content
Merged
Show file tree
Hide file tree
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
Empty file.
15 changes: 2 additions & 13 deletions lua/LazyDeveloperHelper/python/c_installers/conan_install.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import shutil as sh
import sys
from subprocess import run, CalledProcessError
import os
import re

from ..logger import log_message

# --- VARIABLES ---
CONAN = sh.which("conan")


# --- LOGGING MESSAGE ---
def log_message(message: str, level: str = "info") -> None:
prefixes = {
"info": "\U0001f4cd", # πŸ“
"success": "\U0001f4e6", # πŸ“¦
"error": "\u274c", # ❌
}

prefix = prefixes.get(level, "πŸ“")
print(f"{prefix} {message}")


# --- CHECK CONAN EXIST ---
def conan_exist():
if CONAN:
Expand Down
35 changes: 35 additions & 0 deletions lua/LazyDeveloperHelper/python/c_installers/nuget_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import shutil as sh
import sys
from subprocess import run, CalledProcessError

from ..logger import log_message


# --- CHECK NuGet is exist ---
def nuget_exist() -> bool:
dotnet_path = sh.which("dotnet")
if dotnet_path:
log_message("Dotnet exists!", "info")
return True
else:
log_message("Dotnet isnt exists, try install it!", "critical")
return False


# --- INSTALLLING LIBS ---
def install_lib(lib_name: str):
message_for_run = ["dotnet", "add", "package", lib_name]
try:
result = run(message_for_run, check=True, capture_output=True, text=True)
log_message(f"NuGet install output:\n{result.stdout}", "info")
except CalledProcessError as err:
log_message(f"Dotnet install failed:\n{err.stderr}", "error")


# --- POINT OF ENTER ---
if __name__ == "__main__":
if not nuget_exist():
sys.exit(1)

for lib in sys.argv[1:]:
install_lib(lib)
9 changes: 2 additions & 7 deletions lua/LazyDeveloperHelper/python/cargo_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
from subprocess import run, CalledProcessError
from shutil import which
from functools import lru_cache
from logger import log_message


# --- VARIABLES ---
CARGO_TOML = "Cargo.toml"
cargo_path = which("cargo")


# --- INITIALIZE LOGGING MESSAGE
def log_message(message: str, level: str = "info") -> None:
"""Print a formatted message with an emoji prefix."""
prefixes = {"info": "πŸ“", "success": "πŸ“¦", "error": "❌"}
print(f"{prefixes.get(level, 'πŸ“')} {message}")


# --- CACHE Cargo.toml LOCATION ---
@lru_cache(maxsize=1)
def find_cargo_toml(start_dir: str = ".") -> str | None:
Expand Down
12 changes: 12 additions & 0 deletions lua/LazyDeveloperHelper/python/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-


# --- LOGGING MESSAGE ---
def log_message(message: str, level: str = "info") -> None:
prefixes = {
"info": "\U0001f4cd", # πŸ“
"success": "\U0001f4e6", # πŸ“¦
"error": "\u274c", # ❌
}

print(f"{prefixes.get(level, '\U0001f4cd')} {message}")
12 changes: 1 addition & 11 deletions lua/LazyDeveloperHelper/python/luarocks_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@
import argparse
from subprocess import run, CalledProcessError
from shutil import which
from logger import log_message

# --- VARIABLES ---
LUAROCKS_FLAG = "--local"
luarocks_path = which("luarocks")


# --- LOGGING MESSAGE ---
def log_message(message: str, level: str = "info") -> None:
prefixes = {
"info": "\U0001f4cd", # πŸ“
"success": "\U0001f4e6", # πŸ“¦
"error": "\u274c", # ❌
}

print(f"{prefixes.get(level, '\U0001f4cd')} {message}")


# --- CHECKING LIBRARY NAME ---
def validate_library_name(lib: str) -> bool:
if not lib or any(c in lib for c in '<>|&;"'):
Expand Down
7 changes: 1 addition & 6 deletions lua/LazyDeveloperHelper/python/npm_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
from subprocess import run, CalledProcessError, PIPE
from shutil import which
import sys
from logger import log_message

# --- npm PATH ---
npm_path = which("npm")


# --- LOGGING MESSAGE ---
def log_message(message: str, level: str = "info") -> None:
prefixes = {"info": "πŸ“", "success": "πŸ“¦", "error": "❌"}
print(f"{prefixes.get(level, 'πŸ“')} {message}")


# --- CHECKING npm INSTALLED
def check_npm_installed() -> bool:
if not npm_path:
Expand Down
13 changes: 4 additions & 9 deletions lua/LazyDeveloperHelper/python/pip_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from subprocess import run, CalledProcessError
from shutil import which
from typing import Set
from logger import log_message


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


def log_message(message: str, level: str = "info") -> None:
prefixes = {"info": "πŸ“", "success": "πŸ“¦", "error": "❌"}
print(f"{prefixes.get(level, 'πŸ“')} {message}")


# --- VALIDATE LIB NAME
def validate_library_name(lib_name: str) -> bool:
"""Check if the library name is valid."""
Expand Down Expand Up @@ -74,7 +69,7 @@ def install_lib(
file.write(f"{lib_name}\n")
libs_list.add(lib_name.lower())

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

if "requirement already satisfied" in stdout_lower:
log_message(f"{lib_name} already installed", "success")

elif "successfully installed" in stdout_lower:
# Find the line with "Successfully installed {lib_name}
for line in stdout.splitlines():
if "Successfully installed" in line:
log_message(line.strip(), "success")

# If somewhat went wrong
else:
log_message(f"{lib_name} installation output:", "info")
Expand Down
8 changes: 1 addition & 7 deletions lua/LazyDeveloperHelper/python/ruby_gem_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
from subprocess import run, CalledProcessError, PIPE
from shutil import which
import sys


# --- LOGGING MESSAGE ---
def log_message(message: str, level: str = "info") -> None:
"""Log a message with a specified level (info, success, error)."""
prefixes = {"info": "πŸ“", "success": "πŸ“¦", "error": "❌"}
print(f"{prefixes.get(level, 'πŸ“')} {message}")
from logger import log_message


# -- VARIABLES --
Expand Down