Skip to content

Commit

Permalink
Add a UIC-compiling setup.py command 'build_qt'
Browse files Browse the repository at this point in the history
  • Loading branch information
ndevenish authored and dagewa committed Apr 14, 2021
1 parent db11d02 commit 3a96614
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
import os
import subprocess
from glob import glob

from setuptools import setup
from setuptools import Command, setup

# Read the DUI version out of a version file in the package
_ver_file = os.path.join(os.path.dirname(__file__), "src", "dui", "_version.py")
_ver_locals = {}
exec(open(_ver_file).read(), _ver_locals)
DUI_VERSION = _ver_locals["__version__"]

# Borrowed from: https://github.com/glue-viz/glue/blob/master/setup.py
# Copyright (c) 2013, Glue developers


# Based off https://gist.github.com/ivanalejandro0/6758741
class BuildQt(Command):
"""
Defines a command for setup.py that compiles the *.ui and *.qrc files
into python files.
It looks for *.ui files in _UI_PATH subfolder.
"""

_UI_PATH = os.path.join("src", "dui", "resources")

user_options = [("uic=", "u", "Custom uic command (usually pyside-uic or pyuic4)")]

def initialize_options(self):
"""
Sets the proper command names for the compiling tools.
"""
self.pyuic = "pyside2-uic"

def finalize_options(self):
pass

def _compile_ui(self, infile, outfile):
try:
subprocess.call([self.pyuic, infile, "-o", outfile])
except OSError:
print("uic command failed - make sure that pyside-uic " "is in your $PATH")

def run(self):
# compile ui files
for infile in glob(os.path.join(self._UI_PATH, "*.ui")):
directory, ui_filename = os.path.split(infile)
py_filename = ui_filename.replace(".ui", ".py")
outfile = os.path.join(directory, "ui_" + py_filename)
print("Compiling: {0} -> {1}".format(infile, outfile))
self._compile_ui(infile, outfile)


setup(
name="dui",
version=DUI_VERSION,
Expand Down Expand Up @@ -63,6 +106,7 @@
],
include_package_data=True,
entry_points={"console_scripts": ["dui=dui.main_dui:main"]},
cmdclass={"build_qt": BuildQt},
)

# TODO(nick): Work out how to get requirements working, including non-pip like PyQT
Expand Down

0 comments on commit 3a96614

Please sign in to comment.