forked from brechtm/rinohtype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macapp.py
101 lines (81 loc) · 3.37 KB
/
macapp.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
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
# Build an application bundle for macOS
# FIXME: briefcase changed how it is configured and run
# https://briefcase.readthedocs.io/en/latest/how-to/upgrade-from-v0.2.html
import argparse
import os
import re
import shutil
import subprocess
from pkg_resources import WorkingSet
from setuptools import setup
from gitlabpypi import gitlab_pypi_server
TOX_DIST_DIR = os.path.join('.tox', 'dist')
def find_tox_sdist():
sdist, = os.listdir(TOX_DIST_DIR)
assert sdist.endswith('.zip') or sdist.endswith('.tar.gz')
return os.path.join(TOX_DIST_DIR, sdist)
def create_app(name, requirements):
os.environ['MACAPP_NAME'] = name
setup(
name='rinoh_macapp',
options = {
'app': {
'formal_name': 'rinoh',
'bundle': 'com.opqode.rinoh'
},
'macos': {
'icon': '../icons/rinoh'
},
},
install_requires=requirements,
setup_requires=['briefcase'],
script_name='setup.py',
script_args=['macos']
)
parser = argparse.ArgumentParser(description='Create a macOS application.')
parser.add_argument('distribution', type=str, nargs='?',
help='requirement specifier or distribution archive for '
'the rinohtype version to include in the installer')
parser.add_argument('-t', '--use-tox-sdist', action='store_true',
help='install the tox-built distribution')
parser.add_argument('-p', '--pro', action='store_true',
help='build a Pro version installer (with DITA support)')
APP_DIR = os.path.join('macapp', 'macOS')
RE_SDIST_VERSION = re.compile(r'^rinohtype-'
r'(?P<version>\d+\.\d+\.\d+'
r'(\.dev\d+)?(\+[a-z0-9]+(\.dirty\d{8})?)?)'
r'\.zip$')
if __name__ == '__main__':
args = parser.parse_args()
if os.path.exists(APP_DIR):
shutil.rmtree(APP_DIR)
if args.use_tox_sdist:
assert args.distribution is None
# Work around a problem with pip wheel caching
# (https://github.com/pypa/pip/issues/4183)
os.environ['PIP_NO_CACHE_DIR'] = '0'
os.environ['PIP_FIND_LINKS'] = os.path.abspath(TOX_DIST_DIR)
_, sdist_filename = os.path.split(find_tox_sdist())
m = RE_SDIST_VERSION.match(sdist_filename)
rinohtype_dist = 'rinohtype=={}'.format(m.group('version'))
else:
assert args.distribution is not None
rinohtype_dist = args.distribution
requirements = ['pygments', rinohtype_dist]
os.chdir('macapp')
if args.pro:
requirements.append('rinoh-frontend-dita')
with gitlab_pypi_server() as index_url:
os.environ['PIP_EXTRA_INDEX_URL'] = index_url
app_name = 'rinoh pro'
create_app(app_name, requirements)
else:
app_name = 'rinoh'
create_app(app_name, requirements)
print('Creating disk image...')
working_set = WorkingSet([os.path.join('macOS', 'rinoh.app', 'Contents',
'Resources', 'app_packages')])
app_version = working_set.by_key['rinohtype'].version
dmg_filename = '{}-{}.dmg'.format(app_name.replace(' ', '_'), app_version)
subprocess.call(['hdiutil', 'create', '-ov', '-srcfolder', 'macOS',
'-volname', app_name, '../dist/{}'.format(dmg_filename)])