| 1 |
"""This script is used by the py2exe to freeze the library into executables.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
import contextlib |
| 6 |
import ctypes.util |
| 7 |
import functools |
| 8 |
import os |
| 9 |
import platform |
| 10 |
import shutil |
| 11 |
import sys |
| 12 |
from configparser import ConfigParser |
| 13 |
from distutils.util import get_platform |
| 14 |
from fnmatch import fnmatch |
| 15 |
from time import strftime |
| 16 |
|
| 17 |
from py2exe import freeze |
| 18 |
|
| 19 |
|
| 20 |
# Borrowed from setuptools |
| 21 |
def _find_all_simple(path: str) -> list[str]: |
| 22 |
"""Find all files under 'path'. |
| 23 |
|
| 24 |
Args: |
| 25 |
path (str): The directory path to search for files. |
| 26 |
|
| 27 |
Returns: |
| 28 |
list[str]: A list of full filenames found under the specified path. |
| 29 |
""" |
| 30 |
results = ( |
| 31 |
os.path.join(base, file) |
| 32 |
for base, dirs, files in os.walk(path, followlinks=True) |
| 33 |
for file in files |
| 34 |
) |
| 35 |
return filter(os.path.isfile, results) |
| 36 |
|
| 37 |
|
| 38 |
def findall(directory: str = os.curdir) -> list[str]: |
| 39 |
"""Find all files under 'dir' and return the list of full filenames. |
| 40 |
|
| 41 |
Unless dir is '.', return full filenames with dir prepended. |
| 42 |
|
| 43 |
Args: |
| 44 |
directory (str, optional): The directory path to search for files. |
| 45 |
Defaults to the current directory. |
| 46 |
|
| 47 |
Returns: |
| 48 |
list[str]: A list of full filenames found under the specified |
| 49 |
directory. |
| 50 |
""" |
| 51 |
files = _find_all_simple(directory) |
| 52 |
if directory == os.curdir: |
| 53 |
make_rel = functools.partial(os.path.relpath, start=directory) |
| 54 |
files = map(make_rel, files) |
| 55 |
return list(files) |
| 56 |
|
| 57 |
|
| 58 |
import distutils.filelist |
| 59 |
|
| 60 |
distutils.filelist.findall = findall # Fix findall bug in distutils |
| 61 |
|
| 62 |
|
| 63 |
bits = platform.architecture()[0][:2] |
| 64 |
pypath = os.path.abspath(__file__) |
| 65 |
pydir = os.path.dirname(pypath) |
| 66 |
source_dir = os.path.dirname(pydir) |
| 67 |
|
| 68 |
print(f"pydir : {pydir}") |
| 69 |
print(f"source_dir: {source_dir}") |
| 70 |
sys.path.append(source_dir) |
| 71 |
|
| 72 |
|
| 73 |
from DisplayCAL.meta import ( |
| 74 |
APPSTREAM_ID, |
| 75 |
AUTHOR, |
| 76 |
AUTHOR_ASCII, |
| 77 |
AUTHOR_EMAIL, |
| 78 |
DESCRIPTION, |
| 79 |
DEVELOPMENT_HOME_PAGE, |
| 80 |
DOMAIN, |
| 81 |
LONG_DESCRIPTION, |
| 82 |
NAME, |
| 83 |
PY_MAXVERSION, |
| 84 |
PY_MINVERSION, |
| 85 |
VERSION_STRING, |
| 86 |
VERSION_TUPLE, |
| 87 |
script2pywname, |
| 88 |
) |
| 89 |
from DisplayCAL.util_os import getenvu, safe_glob |
| 90 |
from DisplayCAL.util_str import safe_str |
| 91 |
|
| 92 |
appname = NAME |
| 93 |
|
| 94 |
|
| 95 |
if sys.platform in ("darwin", "win32"): |
| 96 |
# Adjust PATH so ctypes.util.find_library can find SDL2 DLLs (if present) |
| 97 |
pth = getenvu("PATH") |
| 98 |
libpth = os.path.join(pydir, "lib") |
| 99 |
if not pth.startswith(libpth + os.pathsep): |
| 100 |
pth = libpth + os.pathsep + pth |
| 101 |
os.environ["PATH"] = safe_str(pth) |
| 102 |
|
| 103 |
|
| 104 |
config = { |
| 105 |
"data": ["tests/data/icc/*.icc"], |
| 106 |
"doc": [ |
| 107 |
"CHANGES.html", |
| 108 |
"LICENSE.txt", |
| 109 |
"README.html", |
| 110 |
"README-fr.html", |
| 111 |
"screenshots/*.png", |
| 112 |
"theme/*.png", |
| 113 |
"theme/*.css", |
| 114 |
"theme/*.js", |
| 115 |
"theme/*.svg", |
| 116 |
"theme/icons/favicon.ico", |
| 117 |
"theme/slimbox2/*.css", |
| 118 |
"theme/slimbox2/*.js", |
| 119 |
], |
| 120 |
# Excludes for .app/.exe builds |
| 121 |
# numpy.lib.utils imports pydoc, which imports Tkinter, but |
| 122 |
# numpy.lib.utils is not even used by DisplayCAL, so omit all |
| 123 |
# Tk stuff |
| 124 |
# Use pyglet with OpenAL as audio backend. pyglet 2.x media import paths |
| 125 |
# pull in additional submodules dynamically, so don't exclude pyglet.* |
| 126 |
"excludes": { |
| 127 |
"all": [ |
| 128 |
"Tkconstants", |
| 129 |
"Tkinter", |
| 130 |
"pygame", |
| 131 |
"pyo", |
| 132 |
"setuptools", |
| 133 |
"tcl", |
| 134 |
"test", |
| 135 |
"yaml", |
| 136 |
"zeroconf", |
| 137 |
], |
| 138 |
"darwin": ["gdbm"], |
| 139 |
"win32": ["gi", "win32com.client.genpy"], |
| 140 |
}, |
| 141 |
"package_data": { |
| 142 |
NAME: [ |
| 143 |
"beep.wav", |
| 144 |
"camera_shutter.wav", |
| 145 |
"ColorLookupTable.fx", |
| 146 |
"lang/*.yaml", |
| 147 |
"linear.cal", |
| 148 |
"pnp.ids", |
| 149 |
"presets/*.icc", |
| 150 |
"quirk.json", |
| 151 |
"ref/*.cie", |
| 152 |
"ref/*.gam", |
| 153 |
"ref/*.icm", |
| 154 |
"ref/*.ti1", |
| 155 |
"report/*.css", |
| 156 |
"report/*.html", |
| 157 |
"report/*.js", |
| 158 |
"test.cal", |
| 159 |
"theme/*.png", |
| 160 |
"theme/*.wav", |
| 161 |
"theme/icons/10x10/*.png", |
| 162 |
"theme/icons/16x16/*.png", |
| 163 |
"theme/icons/32x32/*.png", |
| 164 |
"theme/icons/48x48/*.png", |
| 165 |
"theme/icons/72x72/*.png", |
| 166 |
"theme/icons/128x128/*.png", |
| 167 |
"theme/icons/256x256/*.png", |
| 168 |
"theme/icons/512x512/*.png", |
| 169 |
"theme/jet_anim/*.png", |
| 170 |
"theme/patch_anim/*.png", |
| 171 |
"theme/splash_anim/*.png", |
| 172 |
"theme/shutter_anim/*.png", |
| 173 |
"ti1/*.ti1", |
| 174 |
"x3d-viewer/*.css", |
| 175 |
"x3d-viewer/*.html", |
| 176 |
"x3d-viewer/*.js", |
| 177 |
"xrc/*.xrc", |
| 178 |
"VERSION", |
| 179 |
] |
| 180 |
}, |
| 181 |
"xtra_package_data": {NAME: {"win32": [f"theme/icons/{NAME}-uninstall.ico"]}}, |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
msiversion = ".".join( |
| 186 |
( |
| 187 |
str(VERSION_TUPLE[0]), |
| 188 |
str(VERSION_TUPLE[1]), |
| 189 |
str(VERSION_TUPLE[2]), |
| 190 |
) |
| 191 |
) |
| 192 |
|
| 193 |
|
| 194 |
class Target: |
| 195 |
"""Target class for py2exe.""" |
| 196 |
|
| 197 |
def __init__(self, **kwargs) -> None: |
| 198 |
self.__dict__.update(kwargs) |
| 199 |
|
| 200 |
|
| 201 |
def get_data( |
| 202 |
tgt_dir: str, |
| 203 |
key: str, |
| 204 |
pkgname: None | str = None, |
| 205 |
subkey: None | str = None, |
| 206 |
excludes: None | list[str] = None, |
| 207 |
) -> list[tuple[str, list[str]]]: |
| 208 |
"""Return configured data files. |
| 209 |
|
| 210 |
Args: |
| 211 |
tgt_dir (str): Target directory where the files should be placed. |
| 212 |
key (str): Key in the config dictionary to retrieve the file paths. |
| 213 |
pkgname (None | str, optional): Package name to filter the files. |
| 214 |
Default is None. |
| 215 |
subkey (None | str, optional): Subkey to further filter the files. |
| 216 |
Default is None. |
| 217 |
excludes (None | list[str], optional): List of patterns to exclude |
| 218 |
files. Default is None. |
| 219 |
|
| 220 |
Returns: |
| 221 |
list[tuple[str, list[str]]]: List of tuples where each tuple contains |
| 222 |
the target directory and a list of file paths that match the |
| 223 |
specified key and package name. |
| 224 |
""" |
| 225 |
files = config[key] |
| 226 |
src_dir = source_dir |
| 227 |
resource_dir = src_dir |
| 228 |
if pkgname: |
| 229 |
files = files[pkgname] |
| 230 |
resource_dir = os.path.join(src_dir, pkgname) |
| 231 |
if subkey: |
| 232 |
files = files.get(subkey, []) |
| 233 |
data = [] |
| 234 |
for pth in files: |
| 235 |
if not [exclude for exclude in excludes or [] if fnmatch(pth, exclude)]: |
| 236 |
normalized_path = os.path.normpath( |
| 237 |
os.path.join(tgt_dir, os.path.dirname(pth)) |
| 238 |
) |
| 239 |
safe_path = [ |
| 240 |
os.path.relpath(p, src_dir) |
| 241 |
for p in safe_glob(os.path.join(resource_dir, pth)) |
| 242 |
] |
| 243 |
data.append((normalized_path, safe_path)) |
| 244 |
return data |
| 245 |
|
| 246 |
|
| 247 |
def sort_by_name(a: str, b: str) -> int: |
| 248 |
"""Compare two script names for sorting. |
| 249 |
|
| 250 |
Args: |
| 251 |
a (str): First script name. |
| 252 |
b (str): Second script name. |
| 253 |
|
| 254 |
Returns: |
| 255 |
int: -1 if a < b, 1 if a > b, 0 if a == b. |
| 256 |
""" |
| 257 |
a, b = [os.path.splitext(v)[0] for v in (a, b)] |
| 258 |
if a > b: |
| 259 |
return 1 |
| 260 |
if a < b: |
| 261 |
return -1 |
| 262 |
return 0 |
| 263 |
|
| 264 |
|
| 265 |
def get_scripts(excludes: None | list[str] = None) -> list[tuple[str, str]]: |
| 266 |
"""Return a list of scripts with their descriptions. |
| 267 |
|
| 268 |
Args: |
| 269 |
excludes (None | list[str]): List of scripts to exclude. Default is |
| 270 |
None. |
| 271 |
|
| 272 |
Returns: |
| 273 |
list[tuple[str, str]]: List of tuples containing script names and their |
| 274 |
descriptions. |
| 275 |
""" |
| 276 |
# It is required that each script has an accompanying .desktop file |
| 277 |
scripts_with_desc = [] |
| 278 |
scripts = safe_glob(os.path.join(pydir, "..", "scripts", appname.lower() + "*")) |
| 279 |
|
| 280 |
scripts = sorted(scripts, key=functools.cmp_to_key(sort_by_name)) |
| 281 |
for script in scripts: |
| 282 |
script = os.path.basename(script) |
| 283 |
if script == appname.lower() + "-apply-profiles-launcher": |
| 284 |
continue |
| 285 |
desktop_file = os.path.join(pydir, "..", "misc", f"{script}.desktop") |
| 286 |
if os.path.isfile(desktop_file): |
| 287 |
cfg = ConfigParser() |
| 288 |
cfg.read(desktop_file) |
| 289 |
script = cfg.get("Desktop Entry", "Exec").split()[0] |
| 290 |
desc = cfg.get("Desktop Entry", "Name") |
| 291 |
else: |
| 292 |
desc = "" |
| 293 |
if not [exclude for exclude in excludes or [] if fnmatch(script, exclude)]: |
| 294 |
scripts_with_desc.append((script, desc)) |
| 295 |
return scripts_with_desc |
| 296 |
|
| 297 |
|
| 298 |
def build_py2exe() -> None: |
| 299 |
"""py2exe builder that uses the new freeze API.""" |
| 300 |
use_sdl = False |
| 301 |
sys.path.insert(1, os.path.join(pydir, "..", "util")) |
| 302 |
|
| 303 |
setuptools = True |
| 304 |
debug = False |
| 305 |
dry_run = False |
| 306 |
# do_full_install = False |
| 307 |
|
| 308 |
doc = "." |
| 309 |
data = "." |
| 310 |
# Use CA file from certifi project |
| 311 |
import certifi |
| 312 |
|
| 313 |
if cacert := certifi.where(): |
| 314 |
shutil.copyfile(cacert, os.path.join(pydir, "cacert.pem")) |
| 315 |
config["package_data"][NAME].append("cacert.pem") |
| 316 |
else: |
| 317 |
print("WARNING: cacert.pem from certifi project not found!") |
| 318 |
|
| 319 |
# on Mac OS X and Windows, we want data files in the package dir |
| 320 |
# (package_data will be ignored when using py2exe) |
| 321 |
package_data = { |
| 322 |
NAME: ["theme/icons/22x22/*.png", "theme/icons/24x24/*.png"], |
| 323 |
} |
| 324 |
scripts = get_scripts() |
| 325 |
# Doc files |
| 326 |
data_files = [] |
| 327 |
data_files += get_data(doc, "doc", excludes=["LICENSE.txt"]) |
| 328 |
if data_files: |
| 329 |
data_files.append( |
| 330 |
( |
| 331 |
doc, |
| 332 |
[os.path.relpath(os.path.join(pydir, "..", "LICENSE.txt"), source_dir)], |
| 333 |
) |
| 334 |
) |
| 335 |
# metainfo / appdata.xml |
| 336 |
data_files.append( |
| 337 |
( |
| 338 |
os.path.join(os.path.dirname(data), "metainfo"), |
| 339 |
[ |
| 340 |
os.path.relpath( |
| 341 |
os.path.normpath( |
| 342 |
os.path.join(pydir, "..", "dist", f"{APPSTREAM_ID}.appdata.xml") |
| 343 |
), |
| 344 |
source_dir, |
| 345 |
) |
| 346 |
], |
| 347 |
) |
| 348 |
) |
| 349 |
data_files += get_data(data, "package_data", NAME, excludes=["theme/icons/*"]) |
| 350 |
data_files += get_data(data, "data") |
| 351 |
data_files += get_data(data, "xtra_package_data", NAME, sys.platform) |
| 352 |
|
| 353 |
# Add python and pythonw |
| 354 |
data_files.extend( |
| 355 |
[ |
| 356 |
( |
| 357 |
os.path.join(data, "lib"), |
| 358 |
[ |
| 359 |
sys.executable, |
| 360 |
os.path.join(os.path.dirname(sys.executable), "pythonw.exe"), |
| 361 |
], |
| 362 |
) |
| 363 |
] |
| 364 |
) |
| 365 |
if use_sdl: |
| 366 |
# SDL DLLs for audio module |
| 367 |
sdl2 = ctypes.util.find_library("SDL2") |
| 368 |
sdl2_mixer = ctypes.util.find_library("SDL2_mixer") |
| 369 |
if sdl2: |
| 370 |
sdl2_libs = [sdl2] |
| 371 |
if sdl2_mixer: |
| 372 |
sdl2_libs.append(sdl2_mixer) |
| 373 |
data_files.append((os.path.join(data, "lib"), sdl2_libs)) |
| 374 |
config["excludes"]["all"].append("pyglet") |
| 375 |
else: |
| 376 |
print("WARNING: SDL2_mixer not found!") |
| 377 |
else: |
| 378 |
print("WARNING: SDL2 not found!") |
| 379 |
if "pyglet" not in config["excludes"]["all"]: |
| 380 |
# OpenAL DLLs for pyglet |
| 381 |
openal32 = ctypes.util.find_library("OpenAL32.dll") |
| 382 |
wrap_oal = ctypes.util.find_library("wrap_oal.dll") |
| 383 |
if openal32: |
| 384 |
oal = [openal32] |
| 385 |
if wrap_oal: |
| 386 |
oal.append(wrap_oal) |
| 387 |
else: |
| 388 |
print("WARNING: wrap_oal.dll not found!") |
| 389 |
data_files.append((data, oal)) |
| 390 |
else: |
| 391 |
print("WARNING: OpenAL32.dll not found!") |
| 392 |
|
| 393 |
for dname in ( |
| 394 |
"10x10", |
| 395 |
"16x16", |
| 396 |
"22x22", |
| 397 |
"24x24", |
| 398 |
"32x32", |
| 399 |
"48x48", |
| 400 |
"64x64", |
| 401 |
"72x72", |
| 402 |
"128x128", |
| 403 |
"256x256", |
| 404 |
"512x512", |
| 405 |
): |
| 406 |
# Get all the icons needed, depending on platform |
| 407 |
# Only the icon sizes 10, 16, 32, 72, 256 and 512 include icons |
| 408 |
# that are used exclusively for UI elements. |
| 409 |
# These should be installed in an app-specific location, e.g. |
| 410 |
# under Linux $XDG_DATA_DIRS/DisplayCAL/theme/icons/ |
| 411 |
# The app icon sizes 16, 32, 48 and 256 (128 under Mac OS X), |
| 412 |
# which are used for taskbar icons and the like, as well as the |
| 413 |
# other sizes can be installed in a generic location, e.g. |
| 414 |
# under Linux $XDG_DATA_DIRS/icons/hicolor/<size>/apps/ |
| 415 |
# Generally, icon filenames starting with the lowercase app name |
| 416 |
# should be installed in the generic location. |
| 417 |
icons = [] |
| 418 |
desktopicons = [] |
| 419 |
if sys.platform == "darwin": |
| 420 |
largest_iconbundle_icon_size = "128x128" |
| 421 |
else: |
| 422 |
largest_iconbundle_icon_size = "256x256" |
| 423 |
for iconpath in safe_glob( |
| 424 |
os.path.join(pydir, "theme", "icons", dname, "*.png") |
| 425 |
): |
| 426 |
if not os.path.basename(iconpath).startswith(NAME.lower()) or ( |
| 427 |
sys.platform in ("darwin", "win32") |
| 428 |
and dname in ("16x16", "32x32", "48x48", largest_iconbundle_icon_size) |
| 429 |
): |
| 430 |
# In addition to UI element icons, we also need all the app |
| 431 |
# icons we use in get_icon_bundle under macOS/Windows, |
| 432 |
# otherwise they wouldn't be included (under Linux, these |
| 433 |
# are included for installation to the system-wide icon |
| 434 |
# theme location instead) |
| 435 |
icons.append(iconpath) |
| 436 |
elif sys.platform not in ("darwin", "win32"): |
| 437 |
desktopicons.append(iconpath) |
| 438 |
if icons: |
| 439 |
data_files.append((os.path.join(data, "theme", "icons", dname), icons)) |
| 440 |
if desktopicons: |
| 441 |
data_files.append( |
| 442 |
( |
| 443 |
os.path.join( |
| 444 |
os.path.dirname(data), "icons", "hicolor", dname, "apps" |
| 445 |
), |
| 446 |
desktopicons, |
| 447 |
) |
| 448 |
) |
| 449 |
ext_modules = [] |
| 450 |
requires = [] |
| 451 |
requires.append("pywin32 (>= 213.0)") |
| 452 |
packages = [NAME, f"{NAME}.lib", f"{NAME}.lib.agw"] |
| 453 |
# On Windows we want separate libraries |
| 454 |
packages.extend( |
| 455 |
[ |
| 456 |
f"{NAME}.lib{bits}", |
| 457 |
f"{NAME}.lib{bits}.python{sys.version_info[0]}{sys.version_info[1]}", |
| 458 |
] |
| 459 |
) |
| 460 |
|
| 461 |
attrs = { |
| 462 |
"author": AUTHOR_ASCII, |
| 463 |
"author_email": AUTHOR_EMAIL, |
| 464 |
"classifiers": [ |
| 465 |
"Development Status :: 5 - Production/Stable", |
| 466 |
"Environment :: MacOS X", |
| 467 |
"Environment :: Win32 (MS Windows)", |
| 468 |
"Environment :: X11 Applications", |
| 469 |
"Intended Audience :: End Users/Desktop", |
| 470 |
"License :: OSI Approved :: GNU General Public License v3 " |
| 471 |
"or later (GPLv3+)", |
| 472 |
"Operating System :: OS Independent", |
| 473 |
"Programming Language :: Python :: 3.9", |
| 474 |
"Programming Language :: Python :: 3.10", |
| 475 |
"Programming Language :: Python :: 3.11", |
| 476 |
"Programming Language :: Python :: 3.12", |
| 477 |
"Programming Language :: Python :: 3.13", |
| 478 |
"Programming Language :: Python :: 3.14", |
| 479 |
"Topic :: Multimedia :: Graphics", |
| 480 |
], |
| 481 |
"data_files": data_files, |
| 482 |
"description": DESCRIPTION, |
| 483 |
"download_url": f"{DEVELOPMENT_HOME_PAGE}/releases/download/" |
| 484 |
f"{VERSION_STRING}/{NAME}-{VERSION_STRING}.tar.gz", |
| 485 |
"ext_modules": ext_modules, |
| 486 |
"license": "GPL v3", |
| 487 |
"long_description": LONG_DESCRIPTION, |
| 488 |
"long_description_content_type": "text/x-rst", |
| 489 |
"name": NAME, |
| 490 |
"packages": packages, |
| 491 |
"package_data": package_data, |
| 492 |
"package_dir": {NAME: NAME}, |
| 493 |
"platforms": [ |
| 494 |
"Python >= {} <= {}".format( |
| 495 |
".".join(str(n) for n in PY_MINVERSION), |
| 496 |
".".join(str(n) for n in PY_MAXVERSION), |
| 497 |
), |
| 498 |
"Linux/Unix with X11", |
| 499 |
"Mac OS X >= 10.4", |
| 500 |
"Windows 2000 and newer", |
| 501 |
], |
| 502 |
"requires": requires, |
| 503 |
"provides": [NAME], |
| 504 |
"scripts": [], |
| 505 |
"url": f"https://{DOMAIN}/", |
| 506 |
"version": msiversion if "bdist_msi" in sys.argv[1:] else VERSION_STRING, |
| 507 |
} |
| 508 |
if setuptools: |
| 509 |
attrs["entry_points"] = { |
| 510 |
"gui_scripts": [ |
| 511 |
"{} = {}.main:main{}".format( |
| 512 |
script, |
| 513 |
NAME, |
| 514 |
( |
| 515 |
"" |
| 516 |
if script == NAME.lower() |
| 517 |
else script[len(NAME) :].lower().replace("-", "_") |
| 518 |
), |
| 519 |
) |
| 520 |
for script, desc in scripts |
| 521 |
] |
| 522 |
} |
| 523 |
attrs["exclude_package_data"] = {} |
| 524 |
attrs["include_package_data"] = False |
| 525 |
install_requires = [req.replace("(", "").replace(")", "") for req in requires] |
| 526 |
attrs["install_requires"] = install_requires |
| 527 |
attrs["zip_safe"] = False |
| 528 |
else: |
| 529 |
attrs["scripts"].extend( |
| 530 |
os.path.join("scripts", script) |
| 531 |
for script, desc in [ |
| 532 |
script_desc |
| 533 |
for script_desc in scripts |
| 534 |
if script_desc[0] != f"{NAME.lower()}-apply-profiles" |
| 535 |
or sys.platform != "darwin" |
| 536 |
] |
| 537 |
) |
| 538 |
|
| 539 |
from winmanifest_util import getmanifestxml |
| 540 |
|
| 541 |
arch = "amd64" if platform.architecture()[0] == "64bit" else "x86" |
| 542 |
manifest_xml = getmanifestxml( |
| 543 |
os.path.join( |
| 544 |
pydir, |
| 545 |
"..", |
| 546 |
"misc", |
| 547 |
NAME |
| 548 |
+ ( |
| 549 |
f".exe.{arch}.VC90.manifest" |
| 550 |
if hasattr(sys, "version_info") and sys.version_info[:2] >= (3, 8) |
| 551 |
else ".exe.manifest" |
| 552 |
), |
| 553 |
) |
| 554 |
) |
| 555 |
tmp_scripts_dir = os.path.join(source_dir, "build", "temp.scripts") |
| 556 |
if not os.path.isdir(tmp_scripts_dir): |
| 557 |
os.makedirs(tmp_scripts_dir) |
| 558 |
apply_profiles_launcher = ( |
| 559 |
f"{appname.lower()}-apply-profiles-launcher", |
| 560 |
f"{appname} Profile Loader Launcher", |
| 561 |
) |
| 562 |
for script, _desc in [*scripts, apply_profiles_launcher]: |
| 563 |
shutil.copy( |
| 564 |
os.path.join(source_dir, "scripts", script), |
| 565 |
os.path.join(tmp_scripts_dir, script2pywname(script)), |
| 566 |
) |
| 567 |
attrs["windows"] = [ |
| 568 |
Target( |
| 569 |
script=os.path.join(tmp_scripts_dir, script2pywname(script)), |
| 570 |
icon_resources=[ |
| 571 |
( |
| 572 |
1, |
| 573 |
os.path.join( |
| 574 |
pydir, |
| 575 |
"theme", |
| 576 |
"icons", |
| 577 |
os.path.splitext(os.path.basename(script))[0] + ".ico", |
| 578 |
), |
| 579 |
) |
| 580 |
], |
| 581 |
other_resources=[(24, 1, manifest_xml)], |
| 582 |
copyright="© {} {}".format(strftime("%Y"), AUTHOR), |
| 583 |
description=desc, |
| 584 |
) |
| 585 |
for script, desc in [ |
| 586 |
script_desc1 |
| 587 |
for script_desc1 in scripts |
| 588 |
if script_desc1[0] != appname.lower() + "-eecolor-to-madvr-converter" |
| 589 |
and not script_desc1[0].endswith("-console") |
| 590 |
] |
| 591 |
] |
| 592 |
|
| 593 |
# Add profile loader launcher |
| 594 |
attrs["windows"].append( |
| 595 |
Target( |
| 596 |
script=os.path.join( |
| 597 |
tmp_scripts_dir, script2pywname(apply_profiles_launcher[0]) |
| 598 |
), |
| 599 |
icon_resources=[ |
| 600 |
( |
| 601 |
1, |
| 602 |
os.path.join( |
| 603 |
pydir, |
| 604 |
"theme", |
| 605 |
"icons", |
| 606 |
appname + "-apply-profiles" + ".ico", |
| 607 |
), |
| 608 |
) |
| 609 |
], |
| 610 |
other_resources=[(24, 1, manifest_xml)], |
| 611 |
copyright="© {} {}".format(strftime("%Y"), AUTHOR), |
| 612 |
description=apply_profiles_launcher[1], |
| 613 |
) |
| 614 |
) |
| 615 |
|
| 616 |
# Programs that can run with and without GUI |
| 617 |
console_scripts = [f"{NAME}-VRML-to-X3D-converter"] # No "-console" suffix! |
| 618 |
for console_script in console_scripts: |
| 619 |
console_script_path = os.path.join(tmp_scripts_dir, console_script + "-console") |
| 620 |
if not os.path.isfile(console_script_path): |
| 621 |
shutil.copy( |
| 622 |
os.path.join( |
| 623 |
source_dir, "scripts", console_script.lower() + "-console" |
| 624 |
), |
| 625 |
console_script_path, |
| 626 |
) |
| 627 |
attrs["console"] = [ |
| 628 |
Target( |
| 629 |
script=os.path.join(tmp_scripts_dir, script2pywname(script) + "-console"), |
| 630 |
icon_resources=[ |
| 631 |
( |
| 632 |
1, |
| 633 |
os.path.join( |
| 634 |
pydir, |
| 635 |
"theme", |
| 636 |
"icons", |
| 637 |
os.path.splitext(os.path.basename(script))[0] + ".ico", |
| 638 |
), |
| 639 |
) |
| 640 |
], |
| 641 |
other_resources=[(24, 1, manifest_xml)], |
| 642 |
copyright="© {} {}".format(strftime("%Y"), AUTHOR), |
| 643 |
description=desc, |
| 644 |
) |
| 645 |
for script, desc in [ |
| 646 |
script_desc2 |
| 647 |
for script_desc2 in scripts |
| 648 |
if script2pywname(script_desc2[0]) in console_scripts |
| 649 |
] |
| 650 |
] |
| 651 |
|
| 652 |
# Programs without GUI |
| 653 |
attrs["console"].append( |
| 654 |
Target( |
| 655 |
script=os.path.join( |
| 656 |
tmp_scripts_dir, appname + "-eeColor-to-madVR-converter" |
| 657 |
), |
| 658 |
icon_resources=[ |
| 659 |
( |
| 660 |
1, |
| 661 |
os.path.join(pydir, "theme", "icons", appname + "-3DLUT-maker.ico"), |
| 662 |
) |
| 663 |
], |
| 664 |
other_resources=[(24, 1, manifest_xml)], |
| 665 |
copyright="© {} {}".format(strftime("%Y"), AUTHOR), |
| 666 |
description="Convert eeColor 65^3 to madVR 256^3 3D LUT " |
| 667 |
"(video levels in, video levels out)", |
| 668 |
) |
| 669 |
) |
| 670 |
|
| 671 |
dist_dir = os.path.join( |
| 672 |
pydir, |
| 673 |
"..", |
| 674 |
"dist", |
| 675 |
f"py2exe.{get_platform()}-py{sys.version_info[0]}.{sys.version_info[1]}", |
| 676 |
f"{NAME}-{VERSION_STRING}", |
| 677 |
) |
| 678 |
os.makedirs(dist_dir, exist_ok=True) |
| 679 |
attrs["options"] = { |
| 680 |
"py2exe": { |
| 681 |
"dist_dir": dist_dir, |
| 682 |
"dll_excludes": [ |
| 683 |
"iertutil.dll", |
| 684 |
"MPR.dll", |
| 685 |
"msvcm90.dll", |
| 686 |
"msvcp90.dll", |
| 687 |
"msvcr90.dll", |
| 688 |
"mswsock.dll", |
| 689 |
"urlmon.dll", |
| 690 |
"w9xpopen.exe", |
| 691 |
"gdiplus.dll", |
| 692 |
"mfc90.dll", |
| 693 |
], |
| 694 |
"excludes": config["excludes"]["all"] + config["excludes"]["win32"], |
| 695 |
"bundle_files": 3, # if wx.VERSION >= (2, 8, 10, 1) else 1, |
| 696 |
"compressed": 1, |
| 697 |
"optimize": 0, # 0 = don't optimize (generate .pyc) |
| 698 |
# 1 = normal optimization (like python -O) |
| 699 |
# 2 = extra optimization (like python -OO) |
| 700 |
} |
| 701 |
} |
| 702 |
if debug: |
| 703 |
attrs["options"]["py2exe"].update( |
| 704 |
{"bundle_files": 3, "compressed": 0, "optimize": 0, "skip_archive": 1} |
| 705 |
) |
| 706 |
if setuptools: |
| 707 |
attrs["setup_requires"] = ["py2exe"] |
| 708 |
attrs["zipfile"] = os.path.join("lib", "library.zip") |
| 709 |
|
| 710 |
# To have a working sdist and bdist_rpm when using distutils, |
| 711 |
# we go to the length of generating MANIFEST.in from scratch everytime, |
| 712 |
# using the information available from setup. |
| 713 |
manifest_in = ["# This file will be re-generated by setup.py - do not edit"] |
| 714 |
manifest_in.extend( |
| 715 |
[ |
| 716 |
"include LICENSE.txt", |
| 717 |
"include MANIFEST", |
| 718 |
"include MANIFEST.in", |
| 719 |
"include README.html", |
| 720 |
"include README-fr.html", |
| 721 |
"include CHANGES.html", |
| 722 |
f"include {NAME}*.pyw", |
| 723 |
f"include {NAME}-*.pyw", |
| 724 |
f"include {NAME}-*.py", |
| 725 |
"include use-distutils", |
| 726 |
f"include {NAME}/VERSION", |
| 727 |
] |
| 728 |
) |
| 729 |
manifest_in.append("include " + os.path.basename(sys.argv[0])) |
| 730 |
manifest_in.append( |
| 731 |
"include " + os.path.splitext(os.path.basename(sys.argv[0]))[0] + ".cfg" |
| 732 |
) |
| 733 |
for _datadir, datafiles in attrs.get("data_files", []): |
| 734 |
for datafile in datafiles: |
| 735 |
datafile_relpath = None |
| 736 |
with contextlib.suppress(ValueError): |
| 737 |
datafile_relpath = os.path.relpath( |
| 738 |
os.path.sep.join(datafile.split("/")), source_dir |
| 739 |
) |
| 740 |
manifest_in.append(f"include {datafile_relpath or datafile}") |
| 741 |
for extmod in attrs.get("ext_modules", []): |
| 742 |
manifest_in.extend( |
| 743 |
f"include {os.path.sep.join(src.split('/'))}" for src in extmod.sources |
| 744 |
) |
| 745 |
for pkg in attrs.get("packages", []): |
| 746 |
pkg = os.path.join(*pkg.split(".")) |
| 747 |
pkgdir = os.path.sep.join(attrs.get("package_dir", {}).get(pkg, pkg).split("/")) |
| 748 |
manifest_in.append("include " + os.path.join(pkgdir, "*.py")) |
| 749 |
# manifest_in.append("include " + os.path.join(pkgdir, "*.pyd")) |
| 750 |
# manifest_in.append("include " + os.path.join(pkgdir, "*.so")) |
| 751 |
for obj in attrs.get("package_data", {}).get(pkg, []): |
| 752 |
print(f"obj: {obj}") |
| 753 |
manifest_in.append(f"include {os.path.sep.join([pkgdir, *obj.split('/')])}") |
| 754 |
manifest_in.extend( |
| 755 |
"include {}".format(os.path.join(*pymod.split("."))) |
| 756 |
for pymod in attrs.get("py_modules", []) |
| 757 |
) |
| 758 |
manifest_in.append( |
| 759 |
"include {}".format(os.path.join(NAME, "theme", "theme-info.txt")) |
| 760 |
) |
| 761 |
manifest_in.append( |
| 762 |
"recursive-include {} {} {}".format( |
| 763 |
os.path.join(NAME, "theme", "icons"), "*.icns", "*.ico" |
| 764 |
) |
| 765 |
) |
| 766 |
manifest_in.append("include {}".format(os.path.join("man", "*.1"))) |
| 767 |
manifest_in.append("recursive-include misc *") |
| 768 |
# if skip_instrument_conf_files: |
| 769 |
# manifest_in.extend( |
| 770 |
# [ |
| 771 |
# "exclude misc/Argyll", |
| 772 |
# "exclude misc/*.rules", |
| 773 |
# "exclude misc/*.usermap", |
| 774 |
# ] |
| 775 |
# ) |
| 776 |
manifest_in.append("include {}".format(os.path.join("screenshots", "*.png"))) |
| 777 |
manifest_in.append("include {}".format(os.path.join("scripts", "*"))) |
| 778 |
manifest_in.append("include {}".format(os.path.join("tests", "*"))) |
| 779 |
manifest_in.append("recursive-include theme *") |
| 780 |
manifest_in.append("recursive-include util *.cmd *.py *.sh") |
| 781 |
manifest_in.append("global-exclude *~") |
| 782 |
manifest_in.append("global-exclude *.backup") |
| 783 |
manifest_in.append("global-exclude *.bak") |
| 784 |
manifest_in.append("global-exclude */__pycache__/*") |
| 785 |
if not dry_run: |
| 786 |
with open("MANIFEST.in", "w") as manifest: |
| 787 |
manifest.write("\n".join(manifest_in)) |
| 788 |
if os.path.exists("MANIFEST"): |
| 789 |
os.remove("MANIFEST") |
| 790 |
|
| 791 |
py2exe_kwargs = { |
| 792 |
"console": attrs["console"], |
| 793 |
"windows": attrs["windows"], |
| 794 |
"data_files": attrs["data_files"], |
| 795 |
"zipfile": attrs["zipfile"], |
| 796 |
"options": attrs["options"], |
| 797 |
} |
| 798 |
|
| 799 |
print("Running py2exe.freeze!") |
| 800 |
freeze(**py2exe_kwargs) |
| 801 |
# setup(**attrs) |
| 802 |
print("py2exe.freeze DONE!") |
| 803 |
|
| 804 |
shutil.copy( |
| 805 |
os.path.join(dist_dir, f"python{sys.version_info[0]}{sys.version_info[1]}.dll"), |
| 806 |
os.path.join( |
| 807 |
dist_dir, "lib", f"python{sys.version_info[0]}{sys.version_info[1]}.dll" |
| 808 |
), |
| 809 |
) |
| 810 |
|
| 811 |
from vc90crt import vc90crt_copy_files |
| 812 |
|
| 813 |
vc90crt_copy_files(dist_dir) |
| 814 |
vc90crt_copy_files(os.path.join(dist_dir, "lib")) |
| 815 |
|
| 816 |
|
| 817 |
if __name__ == "__main__": |
| 818 |
build_py2exe() |