feat(apm): add Aira Package Manager with rotating spinner & youtube module v1.4.6
This commit is contained in:
1 parent
960a8fc91f
commit
cea8982b0f
4 files changed
+280
-3
No files matched your search
+103
-1
@@ -1,5 +1,8 @@
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
import threading
|
||||
|
||||
# Cross-platform UTF-8 Console and ANSI Color configuration
|
||||
if sys.platform == "win32":
|
||||
@@ -23,7 +26,7 @@ from lexer import Lexer
|
||||
from parser import Parser
|
||||
from evaluator import Evaluator
|
||||
|
||||
VERSION = "1.4.5 (Aira Self-Healing AI Compiler Edition)"
|
||||
VERSION = "1.4.6 (Aira Package Manager & YouTube Edition)"
|
||||
AUTHOR = "Adam Eehan (Aira Group of Technology)"
|
||||
|
||||
ASCII_BANNER = f"""\033[1;36m
|
||||
@@ -291,6 +294,96 @@ def revoke_ai_api_key():
|
||||
|
||||
prompt_developer_for_ai_key()
|
||||
|
||||
class AiraSpinner:
|
||||
def __init__(self, message="Processing..."):
|
||||
self.message = message
|
||||
self.stop_running = False
|
||||
self.thread = None
|
||||
self.frames = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"]
|
||||
|
||||
def _spin(self):
|
||||
i = 0
|
||||
while not self.stop_running:
|
||||
f = self.frames[i % len(self.frames)]
|
||||
sys.stdout.write(f"\r\033[1;36m {f}\033[0m {self.message}")
|
||||
sys.stdout.flush()
|
||||
time.sleep(0.08)
|
||||
i += 1
|
||||
|
||||
def __enter__(self):
|
||||
self.stop_running = False
|
||||
self.thread = threading.Thread(target=self._spin, daemon=True)
|
||||
self.thread.start()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.stop_running = True
|
||||
if self.thread:
|
||||
self.thread.join(timeout=0.3)
|
||||
sys.stdout.write("\r\033[K")
|
||||
sys.stdout.flush()
|
||||
|
||||
def install_package(pkg_name):
|
||||
pkg_name = pkg_name.lower().strip()
|
||||
print(f"\033[1;36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m")
|
||||
print(f"\033[1;35m📦 [Aira Package Manager (APM v1.0)]\033[0m")
|
||||
print(f"\033[1;36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m")
|
||||
|
||||
with AiraSpinner(f"Resolving package '{pkg_name}' from Aira Package Registry..."):
|
||||
time.sleep(0.8)
|
||||
print(f" \033[1;32m[✓]\033[0m Package \033[1;33m{pkg_name}\033[0m resolved successfully.")
|
||||
|
||||
if pkg_name in ("youtube", "yt"):
|
||||
with AiraSpinner("Verifying engine dependencies (yt-dlp)..."):
|
||||
import subprocess
|
||||
try:
|
||||
import yt_dlp
|
||||
engine_ready = True
|
||||
except ImportError:
|
||||
engine_ready = False
|
||||
time.sleep(0.4)
|
||||
|
||||
if engine_ready:
|
||||
print(" \033[1;32m[✓]\033[0m Backend engine yt-dlp is ready.")
|
||||
else:
|
||||
with AiraSpinner("Installing yt-dlp backend engine via pip..."):
|
||||
subprocess.check_call([sys.executable, "-m", "pip", "install", "yt-dlp"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
print(" \033[1;32m[✓]\033[0m Backend engine installed successfully.")
|
||||
|
||||
with AiraSpinner("Configuring package registry and setting up permissions..."):
|
||||
config_dir = os.path.expanduser("~/.config/airalang")
|
||||
os.makedirs(config_dir, exist_ok=True)
|
||||
packages_file = os.path.join(config_dir, "installed_packages.json")
|
||||
packages = {}
|
||||
if os.path.exists(packages_file):
|
||||
try:
|
||||
with open(packages_file, "r", encoding="utf-8") as f:
|
||||
packages = json.load(f)
|
||||
except Exception:
|
||||
packages = {}
|
||||
packages["youtube"] = {
|
||||
"version": "1.0.0",
|
||||
"installed_at": time.time(),
|
||||
"description": "YouTube video and audio download engine for AiraLang"
|
||||
}
|
||||
packages["yt"] = packages["youtube"]
|
||||
with open(packages_file, "w", encoding="utf-8") as f:
|
||||
json.dump(packages, f, indent=2)
|
||||
time.sleep(0.5)
|
||||
|
||||
print(f" \033[1;32m[✓]\033[0m Module '{pkg_name}' registered in APM.")
|
||||
print(f"\n\033[1;32m✨ Successfully installed '{pkg_name}' v1.0.0!\033[0m")
|
||||
print(f"\033[1;36m💡 Usage in your .aira scripts:\033[0m")
|
||||
print(f" import \"youtube\";")
|
||||
print(f" let video = youtube.get(url);")
|
||||
print(f" let stream = video.stream(\"mp4\");")
|
||||
print(f" let save = os.save(\"video.mp4\");")
|
||||
print(f" stream.download(save);")
|
||||
print(f"\033[1;36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m")
|
||||
else:
|
||||
print(f" \033[1;31m[✗]\033[0m Package '{pkg_name}' not found in Aira Package Registry.")
|
||||
print(f"Available packages: youtube (yt)")
|
||||
|
||||
def print_help():
|
||||
print(f"""\033[1;36mAiraLang v{VERSION}\033[0m
|
||||
Creator: {AUTHOR}
|
||||
@@ -299,6 +392,8 @@ Creator: {AUTHOR}
|
||||
airalang Start interactive REPL
|
||||
airalang <script.aira> Execute an AiraLang script
|
||||
airalang run <script.aira> Execute an AiraLang script
|
||||
airalang install <package> Install a module via Aira Package Manager (APM)
|
||||
aira install <package> Install a module via Aira Package Manager (APM)
|
||||
airalang build <file.aira> [-o out] Compile script to standalone executable
|
||||
airalang new <project_name> Create a new AiraLang project scaffold
|
||||
airalang --ai api revoke Revoke active API key and configure a fresh one
|
||||
@@ -328,6 +423,13 @@ def main():
|
||||
print(f"AiraLang v{VERSION} | Creator: {AUTHOR}")
|
||||
elif arg1 in ("-h", "--help"):
|
||||
print_help()
|
||||
elif arg1 in ("install", "i", "add"):
|
||||
if len(sys.argv) > 2:
|
||||
install_package(sys.argv[2])
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("\033[1;31m[!] Error: Specify package name: airalang install <package_name>\033[0m")
|
||||
sys.exit(1)
|
||||
elif arg1 in ("--ai-setup", "--setup-ai"):
|
||||
from stdlib_modules import prompt_developer_for_ai_key
|
||||
prompt_developer_for_ai_key()
|
||||
|
||||
Reference in new issue
Block a user