Partial build process rewrite.
- Removes files for package building to avoid PyInstaller package beviour. - Removed __main__.py and run_as_subprocess.py for now, calling Python from path is not an acceptable way to mitigate the relative import issue. - Renamed pyinstaller.py to pyinst.py to avoid the script being executed when "python -m PyInstaller" is ran. - Adds Python 3.8 compatible command-line options to pyinst.py
This commit is contained in:
parent
c0760bd519
commit
d62222d6cd
8 changed files with 149 additions and 127 deletions
|
@ -126,12 +126,12 @@ Here's a quick guide on how to freeze Pesterchum, (that is, packaging it with py
|
|||
Ideally, you'll want to create and activate a [virtual environment](https://docs.python.org/3/library/venv.html) before anything else, this is not 100% required though.
|
||||
|
||||
### [CX_FREEZE](https://cx-freeze.readthedocs.io/en/latest/index.html)
|
||||
1. ``pip install cx_freeze``
|
||||
1. ``python3 -m pip install cx_freeze``
|
||||
2. ``python3 setup.py build``
|
||||
|
||||
### [PYINSTALLER](https://pyinstaller.readthedocs.io/en/stable/)
|
||||
1. ``pip install pyinstaller``
|
||||
2. ``python3 pyinstaller.py``
|
||||
1. ``python3 -m pip install pyinstaller``
|
||||
2. ``python3 pyinst.py``
|
||||
|
||||
## SMILIES <img height="32" alt="pesterchum what did you do smilie" src="smilies/whatdidyoudo.gif">
|
||||
|Text|Smilie|
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
|
10
__main__.py
10
__main__.py
|
@ -1,10 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# Tries to run_as_subprocess.py as an absolute and relative import. (for script or module)
|
||||
import sys
|
||||
|
||||
try:
|
||||
from .run_as_subprocess import main
|
||||
except (ImportError, ModuleNotFoundError):
|
||||
from run_as_subprocess import main
|
||||
|
||||
main(sys.argv)
|
|
@ -1,22 +0,0 @@
|
|||
# Copyright (c) 2008 Duncan Fordyce
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
"""A small, simple irc lib for python suitable for bots, clients and anything else.
|
||||
|
||||
For more information and documentation about this package:
|
||||
http://code.google.com/p/oyoyo/
|
||||
"""
|
|
@ -1,8 +0,0 @@
|
|||
# -*- coding=UTF-8; tab-width: 4 -*-
|
||||
|
||||
# These both seem to be worthless because they don't propogate to the modules
|
||||
# lower down....
|
||||
##from __future__ import division
|
||||
##from __future__ import absolute_import # JUST in case.
|
||||
|
||||
# No __all__ or similar, for now.
|
|
@ -49,6 +49,8 @@ upx_exclude = [
|
|||
"qwindows.dll",
|
||||
"Qt6Core.dll",
|
||||
"Qt6Gui.dll",
|
||||
"Qt5Core.dll",
|
||||
"Qt5Gui.dll",
|
||||
"vcruntime140.dll",
|
||||
"MSVCP140.dll",
|
||||
"MSVCP140_1.dll",
|
||||
|
@ -103,69 +105,134 @@ package_universal_crt = ""
|
|||
onefile = ""
|
||||
windowed = ""
|
||||
upx_dir = ""
|
||||
crt_path = ""
|
||||
|
||||
# Command line options
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
|
||||
# Python 3.8 doesn't support optional boolean actions
|
||||
# py3.8 usage is --upx True, py3.9+ usage is --upx/--no-upx
|
||||
# The values for py3.8 are str, for 3.9+ they're booleans
|
||||
# This is very cringe </3
|
||||
if (sys.version_info[0] > 2) and (sys.version_info[1] > 8):
|
||||
# Python 3.9 and up
|
||||
parser.add_argument(
|
||||
"--prompts",
|
||||
help="Prompt for the options below on run",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
)
|
||||
parser.add_argument(
|
||||
)
|
||||
parser.add_argument(
|
||||
"--onefile",
|
||||
help="Create a one-file bundled executable.",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
)
|
||||
parser.add_argument(
|
||||
)
|
||||
parser.add_argument(
|
||||
"--upx",
|
||||
help="Try to compress binaries with UPX.",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
)
|
||||
parser.add_argument(
|
||||
)
|
||||
parser.add_argument(
|
||||
"--crt",
|
||||
help="Try to bundle Universal CRT with the build",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
)
|
||||
parser.add_argument(
|
||||
)
|
||||
parser.add_argument(
|
||||
"--clean",
|
||||
help="Remove build+dist directories with shutil before building.",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
)
|
||||
parser.add_argument(
|
||||
)
|
||||
parser.add_argument(
|
||||
"--windowed",
|
||||
help="Build without console.",
|
||||
action=argparse.BooleanOptionalAction,
|
||||
)
|
||||
_ARGUMENTS = parser.parse_args()
|
||||
|
||||
if _ARGUMENTS.clean == True:
|
||||
)
|
||||
_ARGUMENTS = parser.parse_args()
|
||||
if _ARGUMENTS.clean == True:
|
||||
delete_builddist = "y"
|
||||
elif _ARGUMENTS.clean == False:
|
||||
elif _ARGUMENTS.clean == False:
|
||||
delete_builddist = "n"
|
||||
|
||||
if _ARGUMENTS.upx == True:
|
||||
if _ARGUMENTS.upx == True:
|
||||
upx_enabled = "y"
|
||||
elif _ARGUMENTS.upx == False:
|
||||
elif _ARGUMENTS.upx == False:
|
||||
upx_enabled = "n"
|
||||
|
||||
if _ARGUMENTS.crt == True:
|
||||
if _ARGUMENTS.crt == True:
|
||||
package_universal_crt = "y"
|
||||
elif _ARGUMENTS.crt == False:
|
||||
elif _ARGUMENTS.crt == False:
|
||||
package_universal_crt = "n"
|
||||
|
||||
if _ARGUMENTS.onefile == True:
|
||||
if _ARGUMENTS.onefile == True:
|
||||
onefile = "y"
|
||||
elif _ARGUMENTS.onefile == False:
|
||||
elif _ARGUMENTS.onefile == False:
|
||||
onefile = "n"
|
||||
|
||||
if _ARGUMENTS.windowed == True:
|
||||
if _ARGUMENTS.windowed == True:
|
||||
windowed = "y"
|
||||
elif _ARGUMENTS.windowed == False:
|
||||
elif _ARGUMENTS.windowed == False:
|
||||
windowed = "n"
|
||||
else:
|
||||
# Python 3.8 and below
|
||||
parser.add_argument(
|
||||
"--prompts",
|
||||
help="Prompt for the options below on run",
|
||||
action="store",
|
||||
choices=["True", "False"],
|
||||
)
|
||||
parser.add_argument(
|
||||
"--onefile",
|
||||
help="Create a one-file bundled executable.",
|
||||
action="store",
|
||||
choices=["True", "False"],
|
||||
)
|
||||
parser.add_argument(
|
||||
"--upx",
|
||||
help="Try to compress binaries with UPX.",
|
||||
action="store",
|
||||
choices=["True", "False"],
|
||||
)
|
||||
parser.add_argument(
|
||||
"--crt",
|
||||
help="Try to bundle Universal CRT with the build",
|
||||
action="store",
|
||||
choices=["True", "False"],
|
||||
)
|
||||
parser.add_argument(
|
||||
"--clean",
|
||||
help="Remove build+dist directories with shutil before building.",
|
||||
action="store",
|
||||
choices=["True", "False"],
|
||||
)
|
||||
parser.add_argument(
|
||||
"--windowed",
|
||||
help="Build without console.",
|
||||
action="store",
|
||||
choices=["True", "False"],
|
||||
)
|
||||
_ARGUMENTS = parser.parse_args()
|
||||
if _ARGUMENTS.clean == "True":
|
||||
delete_builddist = "y"
|
||||
elif _ARGUMENTS.clean == "False":
|
||||
delete_builddist = "n"
|
||||
if _ARGUMENTS.upx == "True":
|
||||
upx_enabled = "y"
|
||||
elif _ARGUMENTS.upx == "False":
|
||||
upx_enabled = "n"
|
||||
if _ARGUMENTS.crt == "True":
|
||||
package_universal_crt = "y"
|
||||
elif _ARGUMENTS.crt == "False":
|
||||
package_universal_crt = "n"
|
||||
if _ARGUMENTS.onefile == "True":
|
||||
onefile = "y"
|
||||
elif _ARGUMENTS.onefile == "False":
|
||||
onefile = "n"
|
||||
if _ARGUMENTS.windowed == "True":
|
||||
windowed = "y"
|
||||
elif _ARGUMENTS.windowed == "False":
|
||||
windowed = "n"
|
||||
|
||||
parser.print_usage()
|
||||
|
||||
if _ARGUMENTS.prompts != False:
|
||||
if (_ARGUMENTS.prompts != False) and (_ARGUMENTS.prompts != "False"):
|
||||
try:
|
||||
print(
|
||||
"This is a script to make building with Pyinstaller a bit more conventient."
|
||||
|
@ -204,7 +271,7 @@ if _ARGUMENTS.prompts != False:
|
|||
if package_universal_crt == "y":
|
||||
if is_64bit == True:
|
||||
crt_path = input(
|
||||
"Universal CRT: [C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\10.0.19041.0\\ucrt\\DLLs\\x64]: "
|
||||
"Path to universal CRT: [C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\10.0.19041.0\\ucrt\\DLLs\\x64]: "
|
||||
)
|
||||
if crt_path == "":
|
||||
# crt_path = "C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\10.0.19041.0\\ucrt\\DLLs\\x64" # Default directory.
|
||||
|
@ -220,7 +287,7 @@ if _ARGUMENTS.prompts != False:
|
|||
)
|
||||
else:
|
||||
crt_path = input(
|
||||
"Extra path: [C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\10.0.19041.0\\ucrt\\DLLs\\x86]: "
|
||||
"Path to universal CRT: [C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\10.0.19041.0\\ucrt\\DLLs\\x86]: "
|
||||
)
|
||||
if crt_path == "":
|
||||
# crt_path = "C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\10.0.19041.0\\ucrt\\DLLs\\x86" # Default directory.
|
||||
|
@ -249,6 +316,29 @@ else:
|
|||
if _ARGUMENTS.upx == None:
|
||||
upx_enabled = "n"
|
||||
if _ARGUMENTS.crt == None:
|
||||
if is_64bit == True:
|
||||
crt_path = os.path.join(
|
||||
"C:%s" % os.sep,
|
||||
"Program Files (x86)",
|
||||
"Windows Kits",
|
||||
"10",
|
||||
"10.0.19041.0",
|
||||
"ucrt",
|
||||
"DLLs",
|
||||
"x64",
|
||||
)
|
||||
else:
|
||||
crt_path = os.path.join(
|
||||
"C:%s" % os.sep,
|
||||
"Program Files (x86)",
|
||||
"Windows Kits",
|
||||
"10",
|
||||
"10.0.19041.0",
|
||||
"ucrt",
|
||||
"DLLs",
|
||||
"x86",
|
||||
)
|
||||
print("crt_path = " + crt_path)
|
||||
package_universal_crt = "y"
|
||||
if _ARGUMENTS.onefile == None:
|
||||
onefile = "y"
|
||||
|
@ -298,7 +388,7 @@ if sys.platform == "win32":
|
|||
run_win32.append("--add-data=%s" % x)
|
||||
|
||||
if package_universal_crt == "y":
|
||||
run_win32.append('--paths="%s"' % crt_path)
|
||||
run_win32.append("--paths=%s" % crt_path)
|
||||
if os.path.exists(crt_path):
|
||||
if is_64bit == False:
|
||||
run_win32.append(
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# Wrapper script to run Pesterchum from an import independently of the current working directory. (useful for wheel)
|
||||
# Running MainProgram() from an import would be better, but I think it requires making **all** imports relative depending on __main__,
|
||||
# and probably other stuff too-
|
||||
|
||||
import os
|
||||
import sys
|
||||
from subprocess import call
|
||||
|
||||
# print(sys.argv)
|
||||
def main(argv):
|
||||
arguments = ""
|
||||
for x in argv[1:]:
|
||||
arguments += x + " "
|
||||
# print(arguments)
|
||||
|
||||
directory_path = os.getcwd()
|
||||
print("Working directory: " + directory_path)
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
print("Working directory set to: " + directory_path)
|
||||
print("Running Pesterchum as subprocess, this is not ideal.")
|
||||
retcode = call("python3 pesterchum.py " + " " + str(arguments), shell=True)
|
||||
print(retcode)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
Loading…
Reference in a new issue