-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
146 lines (115 loc) · 4.24 KB
/
setup.py
File metadata and controls
146 lines (115 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import os
import re
import shutil
from distutils.command.build import build
from distutils.core import Command
from distutils.errors import DistutilsExecError
from distutils.spawn import spawn
from glob import glob
from subprocess import call
from setuptools import setup
ENV_PATH = None
# find_executable doesn't support `~`
if "PATH" in os.environ:
paths = os.environ["PATH"].split(os.pathsep)
ENV_PATH = ""
for p in paths:
ENV_PATH += (os.pathsep + p) if ENV_PATH else p
if p.startswith("~"):
ENV_PATH += os.pathsep + os.path.expanduser(p)
def _find_qt_tool(toolSuffix: str):
tool = shutil.which(f"pyside6-{toolSuffix}", path=ENV_PATH)
if not tool:
tool = shutil.which(toolSuffix, path=ENV_PATH)
return tool
class CustomBuild(build):
def get_sub_commands(self):
subCommands = super(CustomBuild, self).get_sub_commands()
subCommands.insert(0, "build_qt")
return subCommands
class BuildQt(Command):
description = "Build Qt files"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
methos = ("ui", "ts")
for m in methos:
getattr(self, "compile_" + m)()
def compile_ui(self):
uic_bin = _find_qt_tool("uic")
if not uic_bin:
raise DistutilsExecError("Missing uic")
pattern = re.compile(rb"from (diffview"
rb"|logview"
rb"|waitingspinnerwidget"
rb"|gitview"
rb"|colorwidget"
rb"|linkeditwidget"
rb"|coloredicontoolbutton"
rb"|patchviewer"
rb"|emptystatelistview"
rb"|commitmessageedit"
rb"|menubutton"
rb"|commitactionwidget"
rb"|fontchooserwidget"
rb"|searchlineedit"
rb"|repopathinput"
rb"|commitpanel"
rb"|commitdetailpanel"
rb") (import .*$)")
for uiFile in glob("qgitc/*.ui"):
name = os.path.basename(uiFile)
pyFile = "qgitc/ui_" + name[:-3] + ".py"
# "--from-imports" seems no use at all
spawn([uic_bin, "-g", "python", "-o", pyFile, uiFile])
self._fix_import(pyFile, pattern)
def compile_ts(self):
lrelease = _find_qt_tool("lrelease")
if not lrelease:
print("Missing lrelease, no translation will be built.")
return
path = os.path.realpath("qgitc/data/translations/qgitc.json")
call([lrelease, "-project", path], cwd="qgitc/data/translations")
def _fix_import(self, pyFile, pattern):
f = open(pyFile, "rb")
lines = f.readlines()
f.close()
f = open(pyFile, "wb+")
for line in lines:
text = pattern.sub(rb"from qgitc.\1 \2", line)
f.write(text)
f.close()
class UpdateTs(Command):
description = "Update *.ts files"
user_options = [
("no-obsolete", None, "Drop all obsolete and vanished strings")
]
def initialize_options(self):
self.no_obsolete = False
def finalize_options(self):
pass
def run(self):
lupdate = _find_qt_tool("lupdate")
if not lupdate:
raise DistutilsExecError("Missing lupdate")
cmd = [lupdate, "-extensions", "py,ui", "qgitc", "-ts", "qgitc/data/translations/zh_CN.ts"]
if self.no_obsolete:
cmd.append("-no-obsolete")
call(cmd)
with open("README.md", "r") as f:
long_description = ""
pattern = re.compile(r"\./screenshots/(.*\.png)")
for line in f.readlines():
long_description += pattern.sub(
"https://raw.githubusercontent.com/timxx/qgitc/refs/heads/master/screenshots/\\1", line)
setup(
long_description_content_type="text/markdown",
long_description=long_description,
cmdclass=dict(build=CustomBuild,
build_qt=BuildQt,
update_ts=UpdateTs
)
)