Skip to content

Commit

Permalink
Fix exe (#176)
Browse files Browse the repository at this point in the history
* Move config import

Issues in config.py shouldn't crash the program entirely

* Add db-requirements.txt to built executable

Needed by config.py

* Use only library name when building exe

Strip the version specification
  • Loading branch information
solaluset authored Aug 13, 2024
1 parent c099077 commit 6ee3a69
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion config/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@
for file in glob.glob("musicbot/**/*.py", recursive=True)
if file not in yt_dlp_plugins
],
"--hidden-import=" + config.DATABASE_LIBRARY,
"--hidden-import=" + config.DATABASE_LIBRARY_NAME,
*[
"--add-data=" + file + os.pathsep + "."
for file in glob.glob("config/*.json")
],
(
"--add-data="
+ os.path.join("config", "db-requirements.txt")
+ os.pathsep
+ "config"
),
*[
"--add-data=" + file + os.pathsep + "assets"
for file in glob.glob("assets/*.mp3")
Expand Down
1 change: 1 addition & 0 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(self):
self.DATABASE = self.DATABASE.replace(
self.DATABASE_LIBRARY, db_req.name, 1
)
self.DATABASE_LIBRARY_NAME = db_req.name
if not db_req.specifier:
with open(
os.path.join(os.path.dirname(__file__), "db-requirements.txt")
Expand Down
10 changes: 5 additions & 5 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"""


def shutdown(config, p):
def shutdown(p):
from config import config

print(config.SHUTDOWN_MESSAGE)
p.stdin.write("shutdown\n")
p.stdin.flush()
Expand All @@ -24,8 +26,6 @@ def main():
import signal
import subprocess

from config import config

print("You can close this window and the bot will run in the background")
print("To stop the bot, press Ctrl+C")

Expand All @@ -44,7 +44,7 @@ def main():
def handler(event):
if event != signal.CTRL_C_EVENT:
return
shutdown(config, p)
shutdown(p)
SetHandler(handler, False)

kwargs = {
Expand Down Expand Up @@ -89,7 +89,7 @@ def new_handler(sig, frame):
print(line, end="")
except KeyboardInterrupt:
if not on_windows:
shutdown(config, p)
shutdown(p)
# display shutdown message
print(p.stdout.read(), end="")

Expand Down

0 comments on commit 6ee3a69

Please sign in to comment.