Merge pull request #118 from Plovchikdeval/patch-6

Update __main__.py
pull/119/head
Who? 2025-03-08 11:47:05 +07:00 committed by GitHub
commit 4baca4bbfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 47 additions and 31 deletions

View File

@ -16,30 +16,18 @@ import getpass
import os
import subprocess
import sys
import hashlib
from ._internal import restart
if (
getpass.getuser() == "root"
and "--root" not in " ".join(sys.argv)
and all(trigger not in os.environ for trigger in {"DOCKER", "GOORM", "NO_SUDO"})
):
print("🚫" * 15)
print("You attempted to run Heroku on behalf of root user")
print("Please, create a new user and restart script")
print("If this action was intentional, pass --root argument instead")
print("🚫" * 15)
print()
print("Type force_insecure to ignore this warning")
print("Type no_sudo if your system has no sudo (Debian vibes)")
inp = input('> ').lower()
if inp != "force_insecure":
sys.exit(1)
elif inp == "no_sudo":
os.environ["NO_SUDO"] = "1"
print("Added NO_SUDO in your environment variables")
restart()
def get_file_hash(filename):
hasher = hashlib.sha256()
try:
with open(filename, "rb") as f:
hasher.update(f.read())
return hasher.hexdigest()
except FileNotFoundError:
return None
def deps():
subprocess.run(
@ -57,12 +45,34 @@ def deps():
],
check=True,
)
with open(".requirements_hash", "w") as f:
f.write(get_file_hash("requirements.txt"))
if (
getpass.getuser() == "root"
and "--root" not in " ".join(sys.argv)
and all(trigger not in os.environ for trigger in {"DOCKER", "GOORM", "NO_SUDO"})
):
print("\U0001F6AB" * 15)
print("You attempted to run Heroku on behalf of root user")
print("Please, create a new user and restart script")
print("If this action was intentional, pass --root argument instead")
print("\U0001F6AB" * 15)
print()
print("Type force_insecure to ignore this warning")
print("Type no_sudo if your system has no sudo (Debian vibes)")
inp = input('> ').lower()
if inp != "force_insecure":
sys.exit(1)
elif inp == "no_sudo":
os.environ["NO_SUDO"] = "1"
print("Added NO_SUDO in your environment variables")
restart()
if sys.version_info < (3, 8, 0):
print("🚫 Error: you must use at least Python version 3.8.0")
elif __package__ != "hikka": # In case they did python __main__.py
print("🚫 Error: you cannot run this as a script; you must execute as a package")
print("\U0001F6AB Error: you must use at least Python version 3.8.0")
elif __package__ != "hikka":
print("\U0001F6AB Error: you cannot run this as a script; you must execute as a package")
else:
try:
import herokutl
@ -71,29 +81,35 @@ else:
else:
try:
import herokutl # noqa: F811
if tuple(map(int, herokutl.__version__.split("."))) < (2, 0, 8):
raise ImportError
except ImportError:
print("🔄 Installing dependencies...")
print("\U0001F504 Installing dependencies...")
deps()
restart()
try:
from . import log
log.init()
from . import main
except ImportError as e:
print(f"{str(e)}\n🔄 Attempting dependencies installation... Just wait ⏱")
print(f"{str(e)}\n\U0001F504 Attempting dependencies installation... Just wait ⏱")
deps()
restart()
if "HIKKA_DO_NOT_RESTART" in os.environ:
del os.environ["HIKKA_DO_NOT_RESTART"]
if "HIKKA_DO_NOT_RESTART2" in os.environ:
del os.environ["HIKKA_DO_NOT_RESTART2"]
main.hikka.main() # Execute main function
prev_hash = None
if os.path.exists(".requirements_hash"):
with open(".requirements_hash", "r") as f:
prev_hash = f.read().strip()
if prev_hash != get_file_hash("requirements.txt"):
print("\U0001F504 Detected changes in requirements.txt, updating dependencies...")
deps()
restart()
main.hikka.main()