11#!/usr/bin/env python
22
3- import fnmatch
4- import glob
53import os
4+ import re
5+ import io
6+ import sys
7+ import glob
68import shutil
9+ import fnmatch
710import subprocess
8- import sys
911import fileinput
1012
1113import setuptools
14+ from setuptools .command .build import build
1215
13- try :
14- from setuptools .modified import newer
15- except ImportError :
16- from distutils .dep_util import newer
17-
18- # Add the src folder to the path
19- sys .path .insert (0 , os .path .realpath ("src" ))
20-
21- from m64py .core .defs import FRONTEND_VERSION
2216
2317BASE_DIR = os .path .dirname (os .path .realpath (__file__ ))
18+ FRONTEND_VERSION = re .search (r'FRONTEND_VERSION\s*=\s*[\'"]([^\'"]*)[\'"]' ,
19+ io .open (os .path .join (BASE_DIR , "src" , "m64py" , "core" , "defs.py" )).read ()).group (1 )
2420
2521
2622class BuildQt (setuptools .Command ):
2723
28- description = "Build the Qt interface"
24+ description = "Build the Qt user interface"
2925
3026 boolean_options = []
3127 user_options = []
@@ -36,15 +32,18 @@ def initialize_options(self):
3632 def finalize_options (self ):
3733 pass
3834
35+ def newer (self , source , target ):
36+ return not os .path .exists (target ) or (os .path .getmtime (source ) > os .path .getmtime (target ))
37+
3938 def compile_rc (self , qrc_file ):
4039 py_file = os .path .splitext (qrc_file )[0 ] + "_rc.py"
41- if not newer (qrc_file , py_file ):
40+ if not self . newer (qrc_file , py_file ):
4241 return
4342 rcc_exe = self .find_executable ("rcc" )
4443 if rcc_exe is None :
4544 self .warn ("Unable to find Qt Resource Compiler (rcc)" )
4645 sys .exit (1 )
47- if subprocess .call (["rcc" , "-g" , "python" , qrc_file , "-o" , py_file ]) > 0 :
46+ if subprocess .call ([rcc_exe , "-g" , "python" , qrc_file , "-o" , py_file ]) > 0 :
4847 self .warn ("Unable to compile resource file {}" .format (qrc_file ))
4948 if not os .path .exists (py_file ):
5049 sys .exit (1 )
@@ -54,16 +53,21 @@ def compile_rc(self, qrc_file):
5453 sys .stdout .write (line )
5554
5655 def compile_ui (self , ui_file ):
57- from PyQt6 import uic
5856 py_file = os .path .splitext (ui_file )[0 ] + "_ui.py"
59- if not newer (ui_file , py_file ):
57+ if not self . newer (ui_file , py_file ):
6058 return
61- with open (py_file , "w" ) as a_file :
62- uic .compileUi (ui_file , a_file )
59+ uic_exe = self .find_executable ("pyuic6" )
60+ if uic_exe is None :
61+ self .warn ("Unable to find Qt User Interface Compiler (pyuic6)" )
62+ sys .exit (1 )
63+ if subprocess .call ([uic_exe , "-o" , py_file , ui_file ]) > 0 :
64+ self .warn ("Unable to compile ui file {}" .format (ui_file ))
65+ if not os .path .exists (py_file ):
66+ sys .exit (1 )
6367
6468 def compile_ts (self , ts_file ):
6569 qm_file = os .path .splitext (ts_file )[0 ] + ".qm"
66- if not newer (ts_file , qm_file ):
70+ if not self . newer (ts_file , qm_file ):
6771 return
6872 lr_exe = self .find_executable ("lrelease" )
6973 if lr_exe is None :
@@ -75,26 +79,11 @@ def compile_ts(self, ts_file):
7579 sys .exit (1 )
7680
7781 def find_executable (self , name ):
78- from PyQt6 .QtCore import QLibraryInfo
7982 path = os .getenv ("PATH" ).split (os .pathsep )
80-
81- bin_path = QLibraryInfo .path (QLibraryInfo .LibraryPath .BinariesPath )
82- path .insert (0 , bin_path )
83- os .environ ["PATH" ] = os .pathsep .join (path )
84- exe = shutil .which (name )
85- if exe :
86- return exe
87-
88- libexec_path = QLibraryInfo .path (QLibraryInfo .LibraryPath .LibraryExecutablesPath )
89- path .insert (0 , libexec_path )
90- os .environ ["PATH" ] = os .pathsep .join (path )
91- exe = shutil .which (name )
92- if exe :
93- return exe
94-
9583 path .extend (["/usr/lib64/qt6/bin" , "/usr/lib64/qt6/libexec" ,
9684 "/usr/lib/qt6/bin" , "/usr/lib/qt6/libexec" ,
9785 "/usr/lib/x86_64-linux-gnu/qt6/bin" , "/usr/lib/x86_64-linux-gnu/qt6/libexec" ])
86+
9887 os .environ ["PATH" ] = os .pathsep .join (path )
9988 exe = shutil .which (name )
10089 if exe :
@@ -334,8 +323,8 @@ class CleanLocal(setuptools.Command):
334323
335324 description = "Clean the local project directory"
336325
337- wildcards = ['*.py[co]' , '*_ui.py' , '*_rc.py' , '__pycache__' , '*.qm' ]
338- excludedirs = ['.git' , 'build' , ' dist' ]
326+ wildcards = ['*.py[co]' , '*_ui.py' , '*_rc.py' , '__pycache__' , '*.qm' , "build" , "*.egg-info" ]
327+ excludedirs = ['.git' , 'dist' ]
339328 user_options = []
340329
341330 def initialize_options (self ):
@@ -367,30 +356,33 @@ def run(self):
367356 os .remove (a_path )
368357
369358
359+ class BuildCustom (build ):
360+ sub_commands = [('build_qt' , None )] + build .sub_commands
361+
362+
370363setuptools .setup (
371- name = "m64py" ,
372- version = FRONTEND_VERSION ,
373- description = "A frontend for Mupen64Plus" ,
374- long_description = "A Qt6 front-end (GUI) for Mupen64Plus, a cross-platform plugin-based Nintendo 64 emulator." ,
375- author = "Milan Nikolic" ,
376- author_email = "gen2brain@gmail.com" ,
377- license = "GNU GPLv3" ,
378- url = "https://m64py.sourceforge.net" ,
379- package_dir = { '' : "src" },
380- packages = [ "m64py" , "m64py.core" , "m64py.frontend" , "m64py.ui" ] ,
381- scripts = ["bin/m64py" ],
382- requires = ["PyQt6" , "PySDL2" ],
383- platforms = [ "Linux" , "Windows" , "Darwin" ],
384- cmdclass = {
385- 'build ' : BuildQt ,
364+ name = "m64py" ,
365+ version = FRONTEND_VERSION ,
366+ description = "A frontend for Mupen64Plus" ,
367+ long_description = "A Qt6 front-end (GUI) for Mupen64Plus, a cross-platform plugin-based Nintendo 64 emulator." ,
368+ author = "Milan Nikolic" ,
369+ author_email = "gen2brain@gmail.com" ,
370+ license = "GNU GPLv3" ,
371+ url = "https://m64py.sourceforge.net" ,
372+ package_dir = { "" : "src" },
373+ packages = setuptools . find_namespace_packages ( where = "src" ) ,
374+ scripts = ["bin/m64py" ],
375+ requires = ["PyQt6" , "PySDL2" ],
376+ cmdclass = {
377+ 'build' : BuildCustom ,
378+ 'build_qt ' : BuildQt ,
386379 'build_dmg' : BuildDmg ,
387380 'build_exe' : BuildExe ,
388- 'build_qt' : BuildQt ,
389381 'build_zip' : BuildZip ,
390382 'clean' : CleanLocal
391383 },
392- data_files = [
393- ("share/pixmaps " , ["xdg/m64py.png" ]),
394- ("share/applications" , ["xdg/m64py.desktop" ]),
384+ data_files = [
385+ ("share/icons/hicolor/96x96/apps " , ["xdg/net.sourceforge. m64py.M64Py .png" ]),
386+ ("share/applications" , ["xdg/net.sourceforge. m64py.M64Py .desktop" ]),
395387 ]
396388)
0 commit comments