Created
June 2, 2018 13:03
-
-
Save rodnaxel/2a8b93d60e0b28bde74f8ae758b5464f to your computer and use it in GitHub Desktop.
example my setup.py by Cx_freeze
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python setup.py build | |
from cx_Freeze import setup, Executable | |
import sys | |
import os | |
import shutil | |
import zipfile | |
__appname__ = "userial-qt5" | |
__version__ = "0.9.0" | |
__icon__ = os.path.join(os.curdir, 'rc', 'logo.ico') | |
__author__ = "Aleksandr Smirnov" | |
__copyright__ = "Copyright 2016 by Navi-Dals" | |
BUILD_DIR = "exe.{}-{}".format(sys.platform, sys.version[:3]) | |
path_build = os.path.join(os.curdir, "build", BUILD_DIR) | |
# Build executable file | |
build_exe_options = {"excludes": ["xml", "email", "html", "http", "unittest", "urllib", | |
"pydoc_data", ""]} | |
exe = Executable( | |
script="main.py", | |
base="Win32GUI", | |
targetName=__appname__ + ".exe", | |
icon=__icon__ | |
) | |
try: | |
setup( | |
name=__appname__ + ".exe", | |
version=__version__, | |
author=__author__, | |
description=__copyright__, | |
options={"build_exe": build_exe_options}, | |
executables=[exe] | |
) | |
except Exception as e: | |
print(e) | |
# Remove nonusble resource | |
print("Remove nonusble resource", end=10*'.') | |
try: | |
path_rm = os.path.join(path_build, "PyQt5", "Qt") | |
if os.path.exists(path_rm): | |
shutil.rmtree(path_rm) | |
print('Ok') | |
except Exception as e: | |
print('Error') | |
print(e) | |
# Create zip | |
print("Create zip file", end=10*'.') | |
try: | |
def zipdir(path, ziph): | |
for root, dirs, files in os.walk(path): | |
for file in files: | |
ziph.write(os.path.join(root, file)) | |
zip_name = '.'.join(['{}-{}'.format(__appname__, __version__), 'zip']) | |
zipf = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) | |
zipdir(path_build, zipf) | |
zipf.close() | |
zip_dist = os.path.join(os.curdir, "zip") | |
if not os.path.exists(zip_dist): | |
os.makedirs(zip_dist) | |
shutil.move(os.path.join(os.curdir, zip_name), os.path.join(zip_dist)) | |
print('Ok') | |
except Exception as e: | |
print("Error") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment