diff --git a/novelWriter.py b/novelWriter.py index 58af6c06..4f609f24 100755 --- a/novelWriter.py +++ b/novelWriter.py @@ -1,11 +1,10 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -novelWriter – Terminal Start Script -=================================== -The main start script for the terminal +novelWriter – Start Script +========================== """ - +import os import sys try: @@ -13,9 +12,11 @@ try: import PyQt5.QtGui # noqa: F401 import PyQt5.QtCore # noqa: F401 except Exception: - print("ERROR: Failed to load dependency python3-pyqt5") + print("ERROR: Failed to load dependency PyQt5") sys.exit(1) +os.curdir = os.path.abspath(os.path.dirname(__file__)) + if __name__ == "__main__": import nw nw.main(sys.argv[1:]) diff --git a/novelWriter.pyw b/novelWriter.pyw deleted file mode 100644 index 6a39bd3c..00000000 --- a/novelWriter.pyw +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -novelWriter – Windows Start Script -================================== -The main start script for Windows GUI -""" - -import os - -os.curdir = os.path.abspath(os.path.dirname(__file__)) - -if __name__ == "__main__": - import nw - nw.main() diff --git a/setup.py b/setup.py index 2d00ea6d..411eab50 100755 --- a/setup.py +++ b/setup.py @@ -234,7 +234,7 @@ def buildSampleZip(): # Make Minimal Package (minimal-zip) ## -def makeMinimalPackage(): +def makeMinimalPackage(targetOS): """Pack the core source file in a single zip file. """ from nw import __version__ @@ -256,41 +256,53 @@ def makeMinimalPackage(): if not os.path.isdir("dist"): os.mkdir("dist") - outFile = os.path.join("dist", "novelWriter-%s-minimal.zip" % __version__) + if targetOS == OS_LINUX: + targName = "-linux" + elif targetOS == OS_DARWIN: + targName = "-darwin" + elif targetOS == OS_WIN: + targName = "-win" + else: + targName = "" + + outFile = os.path.join("dist", f"novelWriter-{__version__}-minimal{targName}.zip") if os.path.isfile(outFile): os.unlink(outFile) - rootFiles = [ - "LICENSE.md", - "README.md", - "CHANGELOG.md", - "novelWriter.pyw", - "requirements.txt", - "setup.py", - "setup_windows.bat", - ] + rootFiles = ["LICENSE.md", "README.md", "CHANGELOG.md", "requirements.txt", "setup.py"] with ZipFile(outFile, "w", compression=ZIP_DEFLATED, compresslevel=9) as zipObj: - for nRoot, _, nFiles in os.walk("setup"): - print("Compressing: %s [%d files]" % (nRoot, len(nFiles))) - for aFile in nFiles: - zipObj.write(os.path.join(nRoot, aFile)) + + if targetOS != OS_WIN: + for nRoot, _, nFiles in os.walk("setup"): + print("Adding Folder: %s [%d files]" % (nRoot, len(nFiles))) + for aFile in nFiles: + zipObj.write(os.path.join(nRoot, aFile)) for nRoot, _, nFiles in os.walk("nw"): if nRoot.endswith("__pycache__"): - print("Skipping: %s" % nRoot) + print("Skipping Folder: %s" % nRoot) continue - print("Compressing: %s [%d files]" % (nRoot, len(nFiles))) + print("Adding Folder: %s [%d files]" % (nRoot, len(nFiles))) for aFile in nFiles: if aFile.endswith(".pyc"): - print("Skipping: %s" % aFile) + print("Skipping File: %s" % aFile) continue zipObj.write(os.path.join(nRoot, aFile)) + if targetOS == OS_WIN: + zipObj.write("novelWriter.py", "novelWriter.pyw") + print("Adding File: novelWriter.pyw") + zipObj.write("setup_windows.bat") + print("Adding File: setup_windows.bat") + else: + zipObj.write("novelWriter.py") + print("Adding File: novelWriter.py") + for aFile in rootFiles: assert os.path.isfile(aFile) - print("Compressing: %s" % aFile) + print("Adding File: %s" % aFile) zipObj.write(aFile) print("") @@ -913,7 +925,6 @@ def innoSetup(setupType): if __name__ == "__main__": """Parse command line options and run the commands. """ - # Detect OS if sys.platform.startswith("linux"): hostOS = OS_LINUX @@ -926,6 +937,19 @@ if __name__ == "__main__": else: hostOS = OS_NONE + # Set Target OS + if "--linux" in sys.argv: + sys.argv.remove("--linux") + targetOS = OS_LINUX + elif "--darwin" in sys.argv: + sys.argv.remove("--darwin") + targetOS = OS_DARWIN + elif "--win" in sys.argv: + sys.argv.remove("--win") + targetOS = OS_WIN + else: + targetOS = hostOS + helpMsg = ( "\n" "novelWriter Setup Tool\n" @@ -934,6 +958,9 @@ if __name__ == "__main__": "This tool provides setup and build commands for installing or distibuting novelWriter\n" "as a package on Linux, Mac and Windows. The available options are as follows:\n" "\n" + "Some of the commands can be targeted towards a different OS than the host OS. To target\n" + "the command, add one of '--linux', '--darwin' or '--win'.\n" + "\n" "General:\n" "\n" " help Print the help message.\n" @@ -950,7 +977,7 @@ if __name__ == "__main__": "Python Packaging:\n" "\n" " minimal-zip Creates a minimal zip file of the core application without all the\n" - " other source files.\n" + " other source files. Accepts a target OS flag.\n" " pack-pyz Creates a pyz package in a folder with all dependencies using the\n" " zipapp tool. On Windows, python embeddable is added to the folder.\n" " freeze Freeze the package and produces a folder with all dependencies using\n" @@ -1015,7 +1042,7 @@ if __name__ == "__main__": if "minimal-zip" in sys.argv: sys.argv.remove("minimal-zip") - makeMinimalPackage() + makeMinimalPackage(targetOS) if "pack-pyz" in sys.argv: sys.argv.remove("pack-pyz")