Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·106 lines (90 loc) · 4.74 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·106 lines (90 loc) · 4.74 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
#!/usr/bin/env python
#
# Copyright (C) Virtaal contributors.
#
# This file is part of Virtaal. It is distributed under the GPL2 or
# later license. See the LICENSE file for a copy of the license and
# the AUTHORS.md file for copyright and authorship information.
"""setup.py now only handles what pyproject.toml can't express
declaratively: compiling .mo files from .po sources, and (on Linux)
collecting freedesktop desktop-integration data files. Everything else
- metadata, dependencies, the package list - lives in pyproject.toml.
The old py2exe/InnoSetup and py2app packaging paths that used to live
here are gone entirely, not modernized: both were Python-2-only code
that couldn't even be parsed under Python 3 (the InnoSetup script
generator used `print >> ofi` statement syntax), let alone run. macOS
packaging now lives in devsupport/packaging/macos/, independent of
`pip install .`; Windows packaging follows the same pattern
separately. The custom `DepCheckInstall` install command is
also gone - it duplicated bin/virtaal's own startup dependency check,
and re-checking importability at *build* time (in a possibly
not-yet-fully-set-up environment) rather than at actual app *startup*
caused real, confusing CI failures during this exact rewrite.
"""
import os
import os.path as path
import sys
from glob import glob
from setuptools import setup
SOURCE_DATA_DIR = 'share'
TARGET_DATA_DIR = 'share'
# Compile .mo files from available .po files. This has to happen here,
# at setup.py's top level, rather than in a proper build hook, because
# data_files (below) needs the resulting file list before `setup()` is
# even called - deferring it cleanly would need a bigger rework of how
# data_files works here than this packaging cleanup is scoped for.
from translate.tools.pocompile import convertmo
mo_files = []
for lang in open(path.join('po', 'LINGUAS'), encoding='utf-8'):
lang = lang.rstrip()
po_filename = path.join('po', lang + '.po')
mo_filename = path.join('mo', lang, 'virtaal.mo')
if not path.exists(path.join('mo', lang)):
os.makedirs(path.join('mo', lang))
convertmo(open(po_filename, 'rb'), open(mo_filename, 'w'), None)
mo_files.append(
(path.join(TARGET_DATA_DIR, 'locale', lang, 'LC_MESSAGES'), [mo_filename])
)
# Build lite files as needed on Win32 and OS X: each merged into the
# library's own catalog on this build machine, so its other messages
# stay translated (see virtaal/support/libi18n/lite.py).
if os.name == 'nt' or sys.platform == 'darwin':
import importlib.util
_spec = importlib.util.spec_from_file_location(
'lite', path.join(path.dirname(path.abspath(__file__)), 'virtaal', 'support', 'libi18n', 'lite.py'))
lite = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(lite)
for lang in open(path.join('po', 'LINGUAS-lite'), encoding='utf-8'):
app, lang = lang.rstrip().split('/')
po_filename = path.join('po', 'lite', app, lang + '.po')
mo_filename = path.join('mo', lang, app + '.mo')
# iso639-3 and iso639-5 have no library: language names fall back
# to Virtaal's own catalog at runtime (translate_compat).
upstream_dir = lite.upstream_locale_dir(app)
upstream_mo = path.join(upstream_dir, lang, 'LC_MESSAGES', app + '.mo') if upstream_dir else None
lite.merge(upstream_mo, po_filename, mo_filename)
mo_files.append(
(path.join(TARGET_DATA_DIR, 'locale', lang, 'LC_MESSAGES'), [mo_filename])
)
data_files = [
(path.join(TARGET_DATA_DIR, "virtaal"), glob(path.join(SOURCE_DATA_DIR, "virtaal", "*.*"))),
(path.join(TARGET_DATA_DIR, "icons"), glob(path.join(SOURCE_DATA_DIR, "icons", "*.*"))),
] + mo_files
# Freedesktop desktop-integration files (.desktop, mime, metainfo,
# hicolor icons) - Linux-specific.
if sys.platform not in ('win32', 'darwin'):
data_files.extend([
(path.join(TARGET_DATA_DIR, "mime", "packages"), glob(path.join(SOURCE_DATA_DIR, "mime", "packages", "*.xml"))),
(path.join(TARGET_DATA_DIR, "applications"), glob(path.join(SOURCE_DATA_DIR, "applications", "*.desktop"))),
(path.join(TARGET_DATA_DIR, "metainfo"), glob(path.join(SOURCE_DATA_DIR, "metainfo", "*.metainfo.xml"))),
])
# App icon itself, so `Icon=io.github.translate.Virtaal` in
# io.github.translate.Virtaal.desktop.in resolves via the hicolor
# theme instead of falling back to a generic icon - no scalable/
# yet, there's no SVG source for the app icon.
for size in ("16x16", "24x24", "32x32", "48x48", "64x64", "128x128", "256x256"):
data_files.append(
(path.join(TARGET_DATA_DIR, "icons", "hicolor", size, "apps"),
glob(path.join(SOURCE_DATA_DIR, "icons", "hicolor", size, "apps", "*.*")))
)
setup(data_files=data_files)