PKzK\G›Yôo3 3 pyqt_distutils/build_ui.py# -*- coding: utf-8 -*- """ Distutils extension for PyQt/PySide applications """ import glob import os from setuptools import Command from .config import Config class build_ui(Command): """ Builds the Qt ui files as described in pyuic.json (or pyuic.cfg). """ user_options = [ ('force', None, 'Force flag, will force recompilation of every ui/qrc file'), ] def initialize_options(self): self.force = False def finalize_options(self): try: self.cfg = Config() self.cfg.load() except (IOError, OSError): print('cannot open pyuic.json (or pyuic.cfg)') self.cfg = None def is_outdated(self, src, dst, ui): if src.endswith('.qrc') or self.force: return True outdated = (not os.path.exists(dst) or (os.path.getmtime(src) > os.path.getmtime(dst))) if not outdated and not ui: # for qrc files, we need to check each individual resources. # If one of them is newer than the dst file, the qrc file must be # considered as outdated # file paths are relative to the qrc file path qrc_dirname = os.path.dirname(src) with open(src, 'r') as f: lines = f.read().splitlines() lines = [l for l in lines if '' in l] cwd = os.getcwd() os.chdir(qrc_dirname) for line in lines: filename = line.replace('', '').replace( '', '').strip() filename = os.path.abspath(filename) if os.path.getmtime(filename) > os.path.getmtime(dst): outdated = True break os.chdir(cwd) return outdated def run(self): if not self.cfg: return for glob_exp, dest in self.cfg.files: for src in glob.glob(glob_exp): if not os.path.exists(src): print('skipping target %s, file not found' % src) continue src = os.path.join(os.getcwd(), src) dst = os.path.join(os.getcwd(), dest) ui = True if src.endswith('.ui'): ext = '_ui.py' cmd = self.cfg.uic_command() elif src.endswith('.qrc'): ui = False ext = '_rc.py' cmd = self.cfg.rcc_command() else: continue filename = os.path.split(src)[1] filename = os.path.splitext(filename)[0] dst = os.path.join(dst, filename + ext) cmd = cmd % (src, dst) try: os.makedirs(os.path.split(dst)[0]) except OSError: pass if self.is_outdated(src, dst, ui): print(cmd) os.system(cmd) else: print('skipping %s, up to date' % src) PKL\Gæ“·~““pyqt_distutils/__init__.py""" A set of PyQt distutils extensions for build qt ui files in a pythonic way: - build_ui: build qt ui/qrc files """ __version__ = '0.5.1' PKzK\G&:r¢› › pyqt_distutils/config.py""" Contains the config class (pyuic.cfg or pyuic.json) """ import json from enum import Enum class QtApi(Enum): pyqt4 = 0 pyqt5 = 1 pyside = 2 class Config: def __init__(self): self.files = [] self.pyuic = '' self.pyuic_options = '' self.pyrcc = '' self.pyrcc_options = '' def uic_command(self): return self.pyuic + ' ' + self.pyuic_options + ' %s -o %s' def rcc_command(self): return self.pyrcc + ' ' + self.pyrcc_options + ' %s -o %s' def load(self): for ext in ['.cfg', '.json']: try: with open('pyuic' + ext, 'r') as f: self.__dict__ = json.load(f) except (IOError, OSError): pass else: break else: print('failed to open configuration file') def save(self): with open('pyuic.json', 'w') as f: json.dump(self.__dict__, f, indent=4, sort_keys=True) def generate(self, api): if api == QtApi.pyqt4: self.pyrcc = 'pyrcc4' self.pyrcc_options = '-py3' self.pyuic = 'pyuic4' self.pyuic_options = '--from-import' self.files[:] = [] elif api == QtApi.pyqt5: self.pyrcc = 'pyrcc5' self.pyrcc_options = '' self.pyuic = 'pyuic5' self.pyuic_options = '--from-import' self.files[:] = [] elif api == QtApi.pyside: self.pyrcc = 'pyside-rcc' self.pyrcc_options = '-py3' self.pyuic = 'pyside-uic' self.pyuic_options = '--from-import' self.files[:] = [] self.save() print('pyuic.json generated') def add(self, src, dst): self.load() for fn, _ in self.files: if fn == src: print('ui file already added: %s' % src) return self.files.append((src, dst)) self.save() print('file added to pyuic.json: %s -> %s' % (src, dst)) def remove(self, filename): self.load() to_remove = None for i, files in enumerate(self.files): src, dest = files if filename == src: to_remove = i break if to_remove is not None: self.files.pop(to_remove) self.save() print('file removed from pyuic.json: %s' % filename) PKzK\GV*Šôôpyqt_distutils/pyuicfg.py"""Help you manage your pyuic.json file (pyqt-distutils) Usage: pyuicfg -g pyuicfg -g --pyqt5 pyuicfg -g --pyside pyuicfg -a SOURCE_FILE DESTINATION_PACKAGE pyuicfg -r SOURCE_FILE pyuicfg (-h | --help) pyuicfg --version Options: -h, --help Show help --version Show version -g Generate pyuic.json -a SOURCE_FILE DESTINATION_PACKAGE Add file to pyuic.json -r SOURCE_FILE Remove file from pyuic.json --pyqt5 Generate a pyuic.json file for PyQt5 instead of PyQt4 --pyside Generate a pyuic.json file for PySide instead of PyQt4 """ import os from docopt import docopt from pyqt_distutils import __version__ from pyqt_distutils.config import Config, QtApi def qt_api_from_args(arguments): if arguments['--pyqt5']: return QtApi.pyqt5 elif arguments['--pyside']: return QtApi.pyside return QtApi.pyqt4 def main(): arguments = docopt(__doc__, version=__version__) generate = arguments['-g'] file_to_add = arguments['-a'] destination_package = arguments['DESTINATION_PACKAGE'] file_to_remove = arguments['-r'] api = qt_api_from_args(arguments) cfg = Config() if generate: if os.path.exists('pyuic.json'): choice = input('pyuic.json already exists. Do you want to replace ' 'it? (y/N) ').lower() if choice != 'y': return cfg.generate(api) elif file_to_add: cfg.add(file_to_add, destination_package) elif file_to_remove: cfg.remove(file_to_remove) if __name__ == '__main__': main()PK²L\G^-Ò .pyqt_distutils-0.5.1.dist-info/DESCRIPTION.rstUNKNOWN PK²L\Gböê99/pyqt_distutils-0.5.1.dist-info/entry_points.txt[console_scripts] pyuicfg = pyqt_distutils.pyuicfg:main PK²L\GÒöï‰  ,pyqt_distutils-0.5.1.dist-info/metadata.json{"classifiers": ["Development Status :: 5 - Production/Stable", "Framework :: Setuptools Plugin", "Environment :: Console", "Environment :: X11 Applications :: Qt", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: Microsoft", "Operating System :: MacOS", "Operating System :: POSIX", "Programming Language :: Python :: 3", "Programming Language :: Python :: 2", "Topic :: Software Development :: Build Tools", "Topic :: System :: Software Distribution", "Topic :: Text Editors :: Integrated Development Environments (IDE)"], "extensions": {"python.commands": {"wrap_console": {"pyuicfg": "pyqt_distutils.pyuicfg:main"}}, "python.details": {"contacts": [{"email": "colin.duquesnoy@gmail.com", "name": "Colin Duquesnoy", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/ColinDuquesnoy/pyqt_distutils"}}, "python.exports": {"console_scripts": {"pyuicfg": "pyqt_distutils.pyuicfg:main"}}}, "extras": [], "generator": "bdist_wheel (0.26.0)", "license": "MIT", "metadata_version": "2.0", "name": "pyqt-distutils", "run_requires": [{"requires": ["docopt"]}], "summary": "A set of distutils extension for building Qt ui files", "version": "0.5.1"}PK²L\GÁs˜,pyqt_distutils-0.5.1.dist-info/top_level.txtpyqt_distutils PK²L\Gìndªnn$pyqt_distutils-0.5.1.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py2-none-any Tag: py3-none-any PK²L\G¨‚:™'pyqt_distutils-0.5.1.dist-info/METADATAMetadata-Version: 2.0 Name: pyqt-distutils Version: 0.5.1 Summary: A set of distutils extension for building Qt ui files Home-page: https://github.com/ColinDuquesnoy/pyqt_distutils Author: Colin Duquesnoy Author-email: colin.duquesnoy@gmail.com License: MIT Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Framework :: Setuptools Plugin Classifier: Environment :: Console Classifier: Environment :: X11 Applications :: Qt Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Natural Language :: English Classifier: Operating System :: Microsoft Classifier: Operating System :: MacOS Classifier: Operating System :: POSIX Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 2 Classifier: Topic :: Software Development :: Build Tools Classifier: Topic :: System :: Software Distribution Classifier: Topic :: Text Editors :: Integrated Development Environments (IDE) Requires-Dist: docopt UNKNOWN PK²L\GHZEÂÊÊ%pyqt_distutils-0.5.1.dist-info/RECORDpyqt_distutils/__init__.py,sha256=Cfnkh7jtoakrjiN1aznVw3q5arJmt3pD0kZdjItbzRw,147 pyqt_distutils/build_ui.py,sha256=rlvr3x8_Jyznx4duufw26d1Ynz4VU4vZ2VjuILDNyyw,3123 pyqt_distutils/config.py,sha256=P_pGs-DFYlssVLVLWMjZSrqVBL6koWAZg-TeF-RRTqw,2459 pyqt_distutils/pyuicfg.py,sha256=yo0QzzEAZdN65G4Z4TzNHJdoEh0IHAu4YS3fMvU6oCI,1780 pyqt_distutils-0.5.1.dist-info/DESCRIPTION.rst,sha256=OCTuuN6LcWulhHS3d5rfjdsQtW22n7HENFRh6jC6ego,10 pyqt_distutils-0.5.1.dist-info/METADATA,sha256=A8XzFKAk6w1x2Qo7-GCEaNPEp2yLkHQMOHKAgK3lG0A,1031 pyqt_distutils-0.5.1.dist-info/RECORD,, pyqt_distutils-0.5.1.dist-info/WHEEL,sha256=GrqQvamwgBV4nLoJe0vhYRSWzWsx7xjlt74FT0SWYfE,110 pyqt_distutils-0.5.1.dist-info/entry_points.txt,sha256=EwjLnfiOSHUDmVvMpy0UWOGbOFSCutYtIkJqD8F6ypw,57 pyqt_distutils-0.5.1.dist-info/metadata.json,sha256=SO7Dfnmo8th2rDTqf_MhcokYVQPZLZ1XMyJuOXp1Hys,1289 pyqt_distutils-0.5.1.dist-info/top_level.txt,sha256=P7xaO8N3KHpJigciHb3FyEP4Zl_-JKoxTLwve5Gz_MY,15 PKzK\G›Yôo3 3 pyqt_distutils/build_ui.pyPKL\Gæ“·~““k pyqt_distutils/__init__.pyPKzK\G&:r¢› › 6 pyqt_distutils/config.pyPKzK\GV*Šôôpyqt_distutils/pyuicfg.pyPK²L\G^-Ò .2pyqt_distutils-0.5.1.dist-info/DESCRIPTION.rstPK²L\Gböê99/ˆpyqt_distutils-0.5.1.dist-info/entry_points.txtPK²L\GÒöï‰  ,pyqt_distutils-0.5.1.dist-info/metadata.jsonPK²L\GÁs˜,a$pyqt_distutils-0.5.1.dist-info/top_level.txtPK²L\Gìndªnn$º$pyqt_distutils-0.5.1.dist-info/WHEELPK²L\G¨‚:™'j%pyqt_distutils-0.5.1.dist-info/METADATAPK²L\GHZEÂÊÊ%¶)pyqt_distutils-0.5.1.dist-info/RECORDPK „Ã-