From 4fb771a4509acb59f464431e6caa2c046ebc19d0 Mon Sep 17 00:00:00 2001 From: Alberto Sottile Date: Thu, 26 Apr 2018 23:34:09 +0200 Subject: [PATCH] Add preliminary support of PyInstaller on AppVeyor --- .appveyor.yml | 21 +++++++++------------ .gitignore | 1 + pyinstaller-onedir.spec | 34 ++++++++++++++++++++++++++++++++++ pyinstaller-onefile.spec | 30 ++++++++++++++++++++++++++++++ syncplay/players/vlc.py | 5 ++++- syncplay/utils.py | 6 +++++- 6 files changed, 83 insertions(+), 14 deletions(-) create mode 100755 pyinstaller-onedir.spec create mode 100755 pyinstaller-onefile.spec diff --git a/.appveyor.yml b/.appveyor.yml index 6f66438..f796de9 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -12,7 +12,7 @@ init: - conda install python=3.5 -y - conda install pywin32 -y - conda install -c conda-forge pyside2 -y - - pip install twisted py2exe zope.interface + - pip install twisted pyinstaller zope.interface - type nul > C:\Miniconda\envs\syncplay\lib\site-packages\zope\__init__.py - pip freeze - conda list @@ -20,25 +20,22 @@ init: install: - cd %APPVEYOR_BUILD_FOLDER% - for /F "tokens=2 delims='" %%a in ('findstr version syncplay\__init__.py') do @set ver=%%a - - python buildPy2exe.py - - del syncplay_v%ver%\lib\api-* - - del syncplay_v%ver%\lib\DNSAPI.dll - - del syncplay_v%ver%\lib\IPHLPAPI.dll - - del syncplay_v%ver%\lib\MPR.dll - - mkdir syncplay_v%ver%\platforms - - copy C:\Miniconda\envs\syncplay\library\plugins\platforms\qwindows.dll syncplay_v%ver%\platforms\ - - copy Syncplay-%ver%-Setup.exe Syncplay-%ver%-Setup-Py3-PySide2.exe + - pyinstaller pyinstaller-onefile.spec + - move dist\Syncplay.exe Syncplay-%ver%-win-Py3-PySide2.exe + - del build /s /Q + - del dist /s /Q + - pyinstaller pyinstaller-onedir.spec # Not a project with an msbuild file, build done at install. build: off artifacts: - - path: 'syncplay_v$(ver)' + - path: 'dist' type: zip name: Syncplay-$(ver)-win-py3-pyside2 - - path: Syncplay-$(ver)-Setup-Py3-PySide2.exe - name: Syncplay-$(ver)-win-setup-py3-pyside2 + - path: Syncplay-$(ver)-win-Py3-PySide2.exe + name: Syncplay-$(ver)-win-py3-pyside2 # Push artefact to S3 bucket and list all before_deploy: diff --git a/.gitignore b/.gitignore index 9b9e6b4..5b13d1c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ dist.7z .* !.travis.yml !.appveyor.yml +__pycache__ \ No newline at end of file diff --git a/pyinstaller-onedir.spec b/pyinstaller-onedir.spec new file mode 100755 index 0000000..0569b89 --- /dev/null +++ b/pyinstaller-onedir.spec @@ -0,0 +1,34 @@ +# -*- mode: python -*- + +block_cipher = None + + +a = Analysis(['syncplayClient.py'], + pathex=['C:\\Users\\Alberto\\Documents\\syncplay-py3-qtpy-pyside2'], + binaries=[], + datas=[('resources/*', 'resources')], + hiddenimports=['PySide2', 'PySide2.QtCore', 'PySide2.QtWidgets'], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + exclude_binaries=True, + name='Syncplay', + debug=False, + strip=False, + upx=True, + console=False, + icon='resources/icon.ico') +coll = COLLECT(exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + name='Syncplay') diff --git a/pyinstaller-onefile.spec b/pyinstaller-onefile.spec new file mode 100755 index 0000000..0d26e97 --- /dev/null +++ b/pyinstaller-onefile.spec @@ -0,0 +1,30 @@ +# -*- mode: python -*- + +block_cipher = None + + +a = Analysis(['syncplayClient.py'], + pathex=['C:\\Users\\Alberto\\Documents\\syncplay-py3-qtpy-pyside2'], + binaries=[], + datas=[('resources/*', 'resources')], + hiddenimports=['PySide2', 'PySide2.QtCore', 'PySide2.QtWidgets'], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + name='Syncplay', + debug=False, + strip=False, + upx=False, + runtime_tmpdir=None, + console=False, + icon='resources/icon.ico') diff --git a/syncplay/players/vlc.py b/syncplay/players/vlc.py index f4ec57b..f8eefe3 100755 --- a/syncplay/players/vlc.py +++ b/syncplay/players/vlc.py @@ -373,7 +373,10 @@ class VlcPlayer(BasePlayer): self.__playerController.drop(getMessage("vlc-interface-version-mismatch").format(self.oldIntfVersion,constants.VLC_INTERFACE_MIN_VERSION)) else: - self.__process = subprocess.Popen(call, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + if isWindows() and getattr(sys, 'frozen', '') and getattr(sys, '_MEIPASS', '') is not None: #Needed for pyinstaller --onefile bundle + self.__process = subprocess.Popen(call, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False, creationflags=0x08000000) + else: + self.__process = subprocess.Popen(call, stderr=subprocess.PIPE, stdout=subprocess.PIPE) self.timeVLCLaunched = time.time() if self._shouldListenForSTDOUT(): for line in iter(self.__process.stderr.readline, ''): diff --git a/syncplay/utils.py b/syncplay/utils.py index 2d76c46..d0ce940 100755 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -143,12 +143,16 @@ def findWorkingDir(): path = os.path.dirname(os.path.dirname(__file__)) elif frozen in ('dll', 'console_exe', 'windows_exe', 'macosx_app'): path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) + elif frozen: #needed for PyInstaller + if getattr(sys, '_MEIPASS', '') is not None: + path = getattr(sys, '_MEIPASS', '') #--onefile + else: + path = os.path.dirname(sys.executable) #--onedir else: path = "" return path def getResourcesPath(): - if isWindows(): return findWorkingDir() + "\\resources\\" else: