From e2456296fe1a81c2708244ba6054d803c6516bbc Mon Sep 17 00:00:00 2001 From: Nico Zanferrari Date: Sat, 4 Apr 2020 18:31:22 +0200 Subject: [PATCH] revert wrong changes --- build_web2py.py | 97 ++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/build_web2py.py b/build_web2py.py index 147c5f0..d3c9b95 100644 --- a/build_web2py.py +++ b/build_web2py.py @@ -1,10 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +# up to 2019, we have used py2applet, py2exe and bbfreeze for building web2py binaries +# The original scripts can be found on GitHub for web2py up to version 2.18.4 +# See also Niphlod's work on http://www.web2pyslices.com/slice/show/1726/build-windows-binaries +# Then we switched to Pyinstaller in order to fully support Python 3 from distutils.core import setup -#from gluon.import_all import base_modules, contributed_modules -#from gluon.fileutils import readlines_file +from gluon.import_all import base_modules, contributed_modules +from gluon.fileutils import readlines_file from glob import glob import os import shutil @@ -16,26 +20,25 @@ USAGE = """ -build_py4web - make py4web Windows and MacOS binaries with pyinstaller - +build_web2py - make web2py Windows and MacOS binaries with pyinstaller Usage: - Install the pyinstaller program, copy this file (plus py4web.*.spec files) - to py4web root folder and run: + Install the pyinstaller program, copy this file (plus web2py.*.spec files) + to web2py root folder and run: - python build_py4web.py + python build_py3.py - (tested with python 3.7.4 with PyInstaller 3.6) + (tested with python 3.7.3 and 2.7.16 with PyInstaller 3.4) """ BUILD_DEBUG = False """ -If BUILD_DEBUG is set to False, no gluon modules will be embedded inside the binary py4web.exe. +If BUILD_DEBUG is set to False, no gluon modules will be embedded inside the binary web2py.exe. Thus, you can easily update the build version by changing the gluon folder inside the resulting ZIP file. In case of problem , set BUILD_DEBUG to True. Then all the gluon modules will be analyzed and embedded, too. - You can later analyze the .exe with 'pyi-archive_viewer py4web-start.exe' and then 'o PYZ-00.pyz' + You can later analyze the .exe with 'pyi-archive_viewer web2py.exe' and then 'o PYZ-00.pyz' in order to check for missing system modules to be manually inserted in the SPEC file """ -if len(sys.argv) != 1 or not os.path.isfile('py4web-start.py'): +if len(sys.argv) != 1 or not os.path.isfile('web2py.py'): print(USAGE) sys.exit(1) os_version = platform.system() @@ -60,55 +63,65 @@ def recursive_zip(zipf, directory, folder=""): zipf, os.path.join(directory, item), folder + os.sep + item) +# read web2py version from VERSION file +web2py_version_line = readlines_file('VERSION')[0] +# use regular expression to get just the version number +v_re = re.compile('[0-9]+\.[0-9]+\.[0-9]+') +web2py_version = v_re.search(web2py_version_line).group(0) + # Python base version python_version = sys.version_info[:3] -# py4web version -from py4web import __version__ -py4web_version = __version__ - if os_version == 'Windows': - print("\nBuilding binary py4web for Windows\n") + print("\nBuilding binary web2py for Windows\n") if BUILD_DEBUG: # debug only - subprocess.call('pyinstaller --clean --icon=extras/icons/py4web.ico \ + subprocess.call('pyinstaller --clean --icon=extras/icons/web2py.ico \ --hidden-import=site-packages --hidden-import=gluon.packages.dal.pydal \ - --hidden-import=gluon.packages.yatl.yatl py4web-start.py') - zip_filename = 'py4web_win_debug' + --hidden-import=gluon.packages.yatl.yatl web2py.py') + zip_filename = 'web2py_win_debug' else: # normal run - subprocess.call('pyinstaller --clean py4web-start.win.spec') - zip_filename = 'py4web_win_' + py4web_version + subprocess.call('pyinstaller --clean web2py.win.spec') + subprocess.call('pyinstaller --clean web2py.win_no_console.spec') + source_no_console = 'dist/web2py_no_console/' + files = 'web2py_no_console.exe' + shutil.move(os.path.join(source_no_console, files), 'dist') + shutil.rmtree(source_no_console) + shutil.rmtree('build') + zip_filename = 'web2py_win' - source = 'dist/py4web-start/' + source = 'dist/web2py/' for files in os.listdir(source): shutil.move(os.path.join(source, files), 'dist') shutil.rmtree(source) - os.unlink('dist/py4web-start.exe.manifest') + os.unlink('dist/web2py.exe.manifest') + + bin_folders = ['dist',] elif os_version == 'Darwin': - print("\nBuilding binary py4web for MacOS\n") + print("\nBuilding binary web2py for MacOS\n") if BUILD_DEBUG: #debug only - subprocess.call("pyinstaller --clean --icon=extras/icons/py4web.icns --hidden-import=gluon.packages.dal.pydal --hidden-import=gluon.packages.yatl.yatl \ - --hidden-import=site-packages --windowed py4web.py", shell=True) - zip_filename = 'py4web_osx_debug' + subprocess.call("pyinstaller --clean --icon=extras/icons/web2py.icns --hidden-import=gluon.packages.dal.pydal --hidden-import=gluon.packages.yatl.yatl \ + --hidden-import=site-packages --windowed web2py.py", shell=True) + zip_filename = 'web2py_osx_debug' else: # normal run - subprocess.call("pyinstaller --clean py4web-start.mac.spec", shell=True) + subprocess.call("pyinstaller --clean web2py.mac.spec", shell=True) # cleanup + move binary files to dist folder - #shutil.rmtree(os.path.join('dist', 'py4web')) + #shutil.rmtree(os.path.join('dist', 'web2py')) shutil.rmtree('build') - zip_filename = 'py4web_osx_' + py4web_version + zip_filename = 'web2py_osx' - shutil.move((os.path.join('dist', 'py4web-start')),(os.path.join('dist', 'py4web_cmd'))) - bin_folders = [(os.path.join('dist', 'py4web_cmd'))] + shutil.move((os.path.join('dist', 'web2py')),(os.path.join('dist', 'web2py_cmd'))) + bin_folders = [(os.path.join('dist', 'web2py.app/Contents/MacOS')), (os.path.join('dist', 'web2py_cmd'))] + print("\nWeb2py binary successfully built!\n") -print("\npy4web binary successfully built!\n") # add data_files -for req in ['README.md', 'requirements.txt']: +for req in ['CHANGELOG', 'LICENSE', 'VERSION']: for bin_folder in bin_folders: shutil.copy(req, os.path.join(bin_folder, req)) # cleanup unuseful binary cache @@ -124,19 +137,19 @@ def recursive_zip(zipf, directory, folder=""): print("\nPreparing package ...") # misc -for folders in ['py4web', 'extras', 'deployment_tools', 'apps', 'tests']: +for folders in ['gluon', 'extras', 'site-packages', 'scripts', 'applications', 'examples', 'handlers']: for bin_folder in bin_folders: shutil.copytree(folders, os.path.join(bin_folder, folders)) if not os.path.exists(os.path.join(bin_folder, 'logs')): os.mkdir(os.path.join(bin_folder, 'logs')) -# create a py4web folder & copy dist's files into it -shutil.copytree('dist', 'zip_temp/py4web') +# create a web2py folder & copy dist's files into it +shutil.copytree('dist', 'zip_temp/web2py') # create zip file zipf = zipfile.ZipFile(zip_filename + ".zip", "w", compression=zipfile.ZIP_DEFLATED) -# just temp so the py4web directory is included in our zip file +# just temp so the web2py directory is included in our zip file path = 'zip_temp' # leave the first folder as None, as path is root. recursive_zip(zipf, path) @@ -144,8 +157,8 @@ def recursive_zip(zipf, directory, folder=""): shutil.rmtree('zip_temp') shutil.rmtree('dist') -print('... Done!\n') -print("\n\nYour binary version of py4web can be found in " + \ + +print("Your binary version of web2py can be found in " + \ zip_filename + ".zip") -print("You may extract the archive anywhere and then run py4web without worrying about module dependencies") -print("\nEnjoy binary py4web " + py4web_version + "\n with embedded Python " + sys.version + "\n") +print("You may extract the archive anywhere and then run web2py without worrying about dependency") +print("\nEnjoy binary web2py " + web2py_version_line + "\n with embedded Python " + sys.version + "\n")