-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.py
70 lines (57 loc) · 2.13 KB
/
setup.py
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
from setuptools import setup
from pathlib import Path
from subprocess import check_call
from setuptools.command.build_py import build_py
from setuptools.command.editable_wheel import editable_wheel
import zipfile
import shutil
import requests
def build_icons(target_dir):
target_dir.mkdir(parents=True, exist_ok=True)
icons_pyqt5 = target_dir / '_icons_pyqt5.py'
icons_pyside6 = target_dir / '_icons_pyside6.py'
qrc_file = Path('icons', 'icons.qrc')
check_call(['pyrcc5', '-o', str(icons_pyqt5), str(qrc_file)])
check_call(['pyside6-rcc', '-o', str(icons_pyside6), str(qrc_file)])
def download_fonts(target_dir):
VERSION = '0.83'
HASH = "0cef8205"
NAME = f"ubuntu-font-family-{VERSION}"
ZIPFILE = f"{HASH}-{NAME}.zip"
URL = f"https://assets.ubuntu.com/v1/{ZIPFILE}"
unzip_dir = target_dir / NAME
dest_dir = target_dir / 'ubuntu-font-family'
target_dir.mkdir(parents=True, exist_ok=True)
shutil.rmtree(dest_dir, ignore_errors=True)
print('Downloading Ubuntu fonts...')
response = requests.get(URL)
try:
temp_zip = Path(target_dir) / ZIPFILE
if not response.ok:
raise ValueError(f"{response.status_code} {response.reason}")
temp_zip.write_bytes(response.content)
with zipfile.ZipFile(temp_zip) as zip_ref:
files = [f for f in zip_ref.namelist() if f.startswith(f"{NAME}/")]
zip_ref.extractall(path=target_dir, members=files)
# Rename to remove version number:
unzip_dir.rename(dest_dir)
finally:
temp_zip.unlink(missing_ok=True)
class custom_build_py(build_py):
def run(self):
if not self.dry_run:
build_icons(Path(self.build_lib) / 'qtutils' / 'icons')
download_fonts(Path(self.build_lib) / 'qtutils' / 'fonts')
super().run()
class custom_editable_wheel(editable_wheel):
def run(self):
if not self.dry_run:
build_icons(Path('qtutils/icons'))
download_fonts(Path('qtutils/fonts'))
super().run()
setup(
cmdclass={
'build_py': custom_build_py,
'editable_wheel': custom_editable_wheel,
}
)