Skip to content

Commit

Permalink
build gui script
Browse files Browse the repository at this point in the history
 - updated to support latest pyInstaller (from github master)
 - numpy MKL DLL is now added (wasn't required before for some reason)
 - reworked versioning to support matlab
   - no longer importing __init__.py file to get version
   - instead we search for the module, so we can open the file and change the is_pynastrangui_exe flag to True
 - removal of lots of modules to try & bring down exe size
  • Loading branch information
SteveDoyle2 committed Jul 22, 2016
1 parent adf7fc9 commit f1ae857
Showing 1 changed file with 145 additions and 24 deletions.
169 changes: 145 additions & 24 deletions dev/pyNastranGUI.spec
Original file line number Diff line number Diff line change
@@ -1,28 +1,73 @@
# -*- PyInstaller input file -*-
# -*- mode: python -*-

#pyInstaller_path = 'C:\\Users\\steve\\Desktop\\pyInstaller'
import pyinstaller
pyInstaller_path = os.path.dirname(pyinstaller.__file__)
print "pyInstaller_path = %r" % pyInstaller_path
#pyInstaller_path = ['C:\\Users\\steve\\Desktop\\pyInstaller']
try:
import pyinstaller
pyInstaller_path = [os.path.dirname(pyinstaller.__file__)]
print "pyInstaller_path = %r" % pyInstaller_path
except ImportError:
pyInstaller_path = []

#-------------------------------------------------------------------------
## this block gets/sets the version so it doesn't use git

#import pyNastran
#pyNastran.is_pynastrangui_exe = True
#pyNastran.__version__ = '%r' % pyNastran.__version__
#pyNastran.__releaseDate__ = '%r' % pyNastran.__releaseDate__
#pyNastran.__releaseDate2__ = '%r' % datei.strftime('%d %B %Y')

import os
import sys
import shutil
import datetime
import pyNastran

pkg_path = pyNastran.__path__[0]
from six import PY2

# get pyNastran location
import pkgutil
pkg_path = pkgutil.get_loader('pyNastran').filename
init_filename = os.path.join(pkg_path, '__init__.py')
assert os.path.exists(init_filename), init_filename


# getting pyNastran version without using the __init__.py file
# because we need to hack on it
import subprocess
try:
ghash = subprocess.check_output(['git', 'describe', '--always'], cwd=os.path.dirname(init_filename))
ghash = ghash.decode('utf-8').rstrip()
except:
# git isn't installed
ghash = 'no.checksum.error'
version = '0.8.0+dev.%s' % ghash

# hacking on the __init___.py file to set:
# is_pynastrangui_exe = True
init_filename_bkp = init_filename + '.bkp'
shutil.copyfile(init_filename, init_filename_bkp)
with open(init_filename, 'r') as init_file:
lines = init_file.readlines()
with open(init_filename, 'w') as init_file:
for line in lines:
if 'is_pynastrangui_exe = False' in line:
line = 'is_pynastrangui_exe = True\n'
init_file.write(line)

# write the version
version_filename = os.path.join(pkg_path, 'version.py')
print('version_filename =', version_filename)
with open(version_filename, 'w') as version_file:
datei = datetime.date.today()
version_file.write('# -*- coding: utf-8 -*-\n')
version_file.write('# this file is autogenerated by pyInstaller\n')
version_file.write('__version__ = %r\n' % pyNastran.__version__)
version_file.write('__version__ = %r\n' % version)
version_file.write('__releaseDate__ = %r\n' % str(datei)) # 2016-2-5
version_file.write('__releaseDate2__ = %r\n' % datei.strftime('%d %B %Y')) # 5 Feb 2016


#-------------------------------------------------------------------------

#a1 = os.path.join(pkg_path, 'bdf','bdf.py')
#a2 = os.path.join(pkg_path, 'op2','op2.py')
#a3 = os.path.join(pkg_path, 'f06','f06.py')
Expand Down Expand Up @@ -50,28 +95,99 @@ assert os.path.exists(icon_main), '%s doesnt exist' % icon_main
#-------------------------------------------------------------------------
# main code

#from PyInstaller import compat
#from os import listdir

##mkldir = compat.base_prefix + "/Lib/site-packages/numpy/core"
#logger = logging.getLogger(__name__)
#logger.info("MKL installed as part of numpy, importing that!")
#binaries = [(mkldir + "/" + mkl, '') for mkl in listdir(mkldir) if mkl.startswith('mkl_')]


python_path = 'F:\Anaconda'
if PY2:
mkl_dll = os.path.join(python_path, 'Library', 'bin', 'mkl_def.dll')
else:
mkl_dll = os.path.join(python_path, 'evns', 'py35', 'Library', 'bin', 'mkl_def3.dll')
mkl_dll_base = os.path.basename(mkl_dll)
assert os.path.exists(mkl_dll), '%s doesnt exist' % mlk_dll

binaries = []
if sys.platform == 'win32':
binaries = [('msvcp100.dll', 'C:\\Windows\\System32\\msvcp100.dll', 'BINARY'),
('msvcr100.dll', 'C:\\Windows\\System32\\msvcr100.dll', 'BINARY')]
('msvcr100.dll', 'C:\\Windows\\System32\\msvcr100.dll', 'BINARY'),
(mkl_dll_base, mkl_dll, 'BINARY'),
]

#python_path = 'C:\\Python27_x86'
python_path = 'C:\\Anaconda'
#python_path = 'C:\\Anaconda'


pathex = pyInstaller_path + [
python_path,
os.path.join(python_path, 'Lib'),
os.path.join(python_path, 'Lib', 'site-packages'),

pkg_path,
os.path.join(pkg_path, 'bdf'),
os.path.join(pkg_path, 'op2'),
os.path.join(pkg_path, 'f06'),
os.path.join(pkg_path, 'gui'),
]
excludes = [
#'unittest', # why can't I remove this?
'matplotlib', 'wx', 'nose', 'Tkinter', 'distutils',

'beautifulsoup4', 'bitarray', 'bottleneck', 'bzip2', 'cdecimal',
'cffi', 'comtypes', 'conda-build', 'configobj', 'console_shortcut',
'cryptography', 'cython', 'docutils', 'fastcache', 'flask',
'freetype', 'funcsigs', 'greenlet', 'grin', 'h5py', 'idna',
'ipaddress', 'ipython-notebook', 'ipython-qtconsole',
'ipython_genutils', 'itsdangerous', 'jedi', 'jinja2', 'jpeg',
'jsonschema', 'jupyter_client', 'jupyter_core', 'launcher',
'libsodium', 'markupsafe', 'mistune', 'multipledispatch',
'nbformat', 'nltk', 'node-webkit', 'nose', 'patsy', 'pickleshare',
'ply', 'pyasn1', 'pycosat', 'pycparser', 'pycrypto', 'pycurl',
'pyflakes', 'pyopenssl', 'pyparsing', 'pyreadline', 'pytables',
'python-dateutil', 'rope', 'scikit-image', 'simplegeneric',
'singledispatch', 'sockjs-tornado', 'ssl_match_hostname',
'statsmodels', 'sympy', 'tk', 'toolz', 'ujson', 'unicodecsv',
'xlrd', 'xlwt', 'zeromq', 'zlib', 'alabaster',
'anaconda-client', 'appdirs', 'astroid', 'astroid', 'astropy'
'babel', 'backports_abc', 'blackwidow', 'blaze-core', 'bokeh',
'boto', 'clyent', 'coverage',
'curl', 'cycler', 'cytoolz', 'datashape', 'decorator', 'freeimage',
'gl2ps', 'oce', 'pythonocc-core', 'tbb', 'enum34', 'et_xmlfile',
'futures', 'gevent', 'gevent-websocket', 'hdf5', 'ipykernel',
'ipython', 'ipywidgets', 'jdcal', 'jupyter', 'jupyter_console',
'lazy-object-proxy', 'libtiff', 'llvmlite', 'logilab-common',
'lxml', 'matplotlib', 'menuinst', 'MeshPy',
'msvc_runtime', 'nbconvert', 'networkx', 'notebook', 'numba',
'numexpr', 'numpydoc', 'odo', 'openmdao', 'openpyxl',
'openssl', 'pandas', 'path.py', 'pep8', 'pi', 'pip',
'psutil', 'py', 'pygments', 'pylint', 'pylint', 'pytest',
'pytools', 'pytz', 'pyyaml', 'pyzmq',
'qtconsole', 'requests', 'ruamel_yaml', 'RunSnakeRun',
'scikit-learn', 'setuptools',
'snowballstemmer', 'sphinx', 'sphinx_rtd_theme', 'spyder',
'spyder-app', 'sqlalchemy', 'sqlitedict', 'SquareMap', 'tornado',
'traitlets', 'werkzeug', 'wheel',
'wrapt', 'wxpython', 'xlsxwriter', 'xlwings',


# not required...strange...
'conda', 'conda-env', 'pywin32', 'python', 'vs2008_runtime',
'pyqt', 'anaconda',

# things we're using
'libpng',
#'sip', 'colorama', 'numpy', 'pillow', 'qt','scipy',
#'vtk', 'six', 'mkl', 'mkl-service',
]

a = Analysis(analyze_files,
pathex=[pyInstaller_path,
python_path,
os.path.join(python_path, 'Lib'),
os.path.join(python_path, 'Lib', 'site-packages'),

pkg_path,
os.path.join(pkg_path, 'bdf'),
os.path.join(pkg_path, 'op2'),
os.path.join(pkg_path, 'f06'),
os.path.join(pkg_path, 'gui'),
],
excludes=[#'unittest', # why can't I remove this?
'matplotlib', 'wx', 'nose', 'Tkinter', 'distutils',
],
pathex=pathex,
excludes=excludes,
hiddenimports=[
'vtk.vtkCommonPythonSIP', 'vtk.vtkFilteringPythonSIP',
'PyQt4.QtOpenGL', 'vtk.vtkRenderingPythonSIP'],
Expand Down Expand Up @@ -104,3 +220,8 @@ exe = EXE(pyz,
# upx=True,
# name=os.path.join('dist', 'pyNastranGUI'))

#-------------------------------------------------------------------------
# fix the __init__.py file

shutil.copyfile(init_filename_bkp, init_filename)
os.remove(init_filename_bkp)

0 comments on commit f1ae857

Please sign in to comment.