From 9235c0484c21b8a8130cd524deb4bf031281db08 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 19 Nov 2022 18:13:16 +0100 Subject: [PATCH] Add binary file generation for windows --- evennia/__main__.py | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 evennia/__main__.py diff --git a/evennia/__main__.py b/evennia/__main__.py new file mode 100644 index 0000000000..af7f9fa00c --- /dev/null +++ b/evennia/__main__.py @@ -0,0 +1,52 @@ +""" +Entrypoint for calling Evennia as a module, with + + python -m evennia (linux/unix) + py -m evennia (windows) + +Notably, this should work also if evennia is installed with pip but +the executable is not on the path (so the plain `evennia` command +doesn't work). + +For windows, this will try to inject the evennia launcher into the executable path +to make the `evennia` command available. + +""" + +import os +import sys + +from .server.evennia_launcher import main + +if os.name == "nt": + # we are on windows; we aim to place the executable in the + # same place as the python file (for a virtualenv, this + # would be the virtualenv's Scripts\ folder). + binpath = os.path.join(sys.prefix, os.path.dirname(sys.executable)) + pyscript = """# auto-generated by py -m evennia (__main__.py) +import os +import sys +from evennia.server.evennia_launcher import main +sys.path.insert(0, os.path.abspath(os.getcwd())) +sys.path.insert(0, os.path.join(sys.prefix, "Lib", "site-packages")) +main() +""" + pyscript_path = os.path.join(binpath, "evennia_launcher.py") + + batfile = f'@"{sys.executable}" "{pyscript_path}" %*' + batfile_path = os.path.join(binpath, "evennia.bat") + + if not os.path.exists(pyscript_path): + try: + with open(pyscript_path, "w") as fil: + fil.write(pyscript) + except FileNotFoundError: + print("Failed to add evennia_launcher.py to {pyscript_path}.") + if not os.path.exists(batfile_path): + try: + with open(batfile_path, "w") as fil: + fil.write(batfile) + except FileNotFoundError: + print("Failed to add evennia.bat to {batfile_path}.") + +main()