-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsettings-py39.py
211 lines (181 loc) · 7.05 KB
/
settings-py39.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import re
import shutil
import json
# ===============================================================================
# General settings applicable to all apps
# ===============================================================================
# Name of the app
APP_NAME = "OpenSesame"
# The short version string
# In this script, this value is overwritten later, because the value of OpenSesame
# is automatically retrieved from its source code.
VERSION = "3.3.0"
# The website in reversered order (domain first, etc.)
IDENTIFIER = "nl.cogsci.osdoc"
# The author of this package
AUTHOR = "Sebastiaan Mathôt"
# Full path to the anaconda environment folder to package
# Make sure it is the full path (and not a relative one, also to the homedir with ~) so this can be
# correctly replaced later. Conda usßes hardcoded paths, which we convert to `/Applications/<APP_NAME>`
CONDA_ENV_PATH = "~/miniconda3/envs/os3.3-py39"
# Folders to include from Anaconda environment, if ommitted everything will be
# copied
# CONDA_FOLDERS = ["lib", "bin", "share", "qsci", "ssl", "translations"]
# Paths of files and folders to remove from the copied anaconda environment,
# relative to the environment's root.
# For instance, this could be the qt4 apps (an app inside an app is useless)
CONDA_EXCLUDE_FILES = [
'bin/*.app',
'bin/*.prl',
'bin/qmake',
'bin/2to3*',
'bin/autopoint',
'conda-meta',
'include',
'lib/*.prl',
'lib/pkg-config',
'org.freedesktop.dbus-session.plist'
]
CONDA_EXCLUDE_FILES += map(lambda x: f'translations/{x}', [
'assistant*', 'designer*', 'linguist*', 'qt_*', 'qtbase*', 'qtconnectivity*', 'qtdeclarative*',
'qtlocation*', 'qtmultimedia*', 'qtquickcontrols*', 'qtscript*', 'qtserialport*',
'qtwebsockets*', 'qtxmlpatterns*'
])
# Path to the icon of the app
ICON_PATH = "~/Git/OpenSesame/opensesame_resources/opensesame.icns"
# The entry script of the application in the environment's bin folder
ENTRY_SCRIPT = "opensesame"
# Folder to place created APP and DMG in.
OUTPUT_FOLDER = "~/EXPERIMENTAL/"
# Information about file types that the app can handle
APP_SUPPORTED_FILES = {
"CFBundleDocumentTypes": [
{
'CFBundleTypeName': "OpenSesame experiment",
'CFBundleTypeRole': "Editor",
'LSHandlerRank': "Owner",
'CFBundleTypeIconFile': os.path.basename(ICON_PATH),
'LSItemContentTypes': ["nl.cogsci.osdoc.osexp"],
'NSExportableTypes': ["nl.cogsci.osdoc.osexp"]
}
],
"UTExportedTypeDeclarations": [
{
'UTTypeConformsTo': ['org.gnu.gnu-zip-archive'],
'UTTypeDescription': "OpenSesame experiment",
'UTTypeIdentifier': "nl.cogsci.osdoc.osexp",
'UTTypeTagSpecification': {
'public.filename-extension': 'osexp',
'public.mime-type': 'application/gzip'
}
}
]
}
# Placed here to not let linter go crazy. Will be overwritten by main program
RESOURCE_DIR = ""
# ===== Settings specific to dmgbuild =====
# Create a DMG template name, so version can be overwritten if it can be
# determined from the OS libraries.
os_dmg_template = 'opensesame_{}-py39-macos-1.dmg'
# Name of the DMG file that will be created in OUTPUT_FOLDER
DMG_FILE = os_dmg_template.format(VERSION)
# DMG format
DMG_FORMAT = 'UDZO'
# Locations of shortcuts in DMG window
DMG_ICON_LOCATIONS = {
APP_NAME + '.app': (5, 452),
'Applications': (200, 450)
}
# Size of DMG window when mounted
DMG_WINDOW_RECT = ((300, 200), (358, 570))
# Size of icons in DMG
DMG_ICON_SIZE = 80
# Background of DMG file
DMG_BACKGROUND = "~/Git/OpenSesame/opensesame_resources/einstein.png"
# ===============================================================================
# Extra settings and functions specific to OpenSesame (Remove for other apps)
# ===============================================================================
LOCAL_LIB_FOLDER = "/usr/local/lib"
# Try to obtain OpenSesame version from OpenSesame source
os_metadata_file = os.path.expanduser(os.path.join(CONDA_ENV_PATH, 'lib', 'python3.9',
'site-packages', 'libopensesame', 'metadata.py'))
try:
with open(os_metadata_file, 'r') as fp:
metadata = fp.read()
except Exception as e:
print("Could not read OpenSesame version from metadata: {}".format(e))
else:
version_match = re.search("(?<=__version__)\s*=\s*u'(.*)'", metadata)
if version_match:
VERSION = version_match.group(1)
codename_match = re.search("(?<=codename)\s*=\s*u'(.*)'", metadata)
if codename_match:
codename = codename_match.group(1)
LONG_VERSION = VERSION + ' ' + codename
else:
LONG_VERSION = VERSION
# Overwrite name of the DMG file that will be created in OUTPUT_FOLDER
DMG_FILE = os_dmg_template.format(VERSION)
print("Creating app for {} {}".format(APP_NAME, LONG_VERSION))
def extra():
# copy the opensesame entry script to a file with the .py extension again
# otherwise multiprocessing doesn't work
copy_opensesame_with_py_ext()
# Create qt.conf files, to enable Qt to find all libraries inside the app.
compose_qtconf()
# Remove superfluous conda files
# cleanup_conda()
# Fix some hardcoded conda paths
fix_paths()
def fix_paths():
kernel_json = os.path.join(
RESOURCE_DIR, 'share', 'jupyter', 'kernels', 'python3', 'kernel.json')
if os.path.exists(kernel_json):
print('Fixing kernel.json')
with open(kernel_json, 'r') as fp:
kernelCfg = json.load(fp)
kernelCfg['argv'][0] = 'python'
with open(kernel_json, 'w+') as fp:
json.dump(kernelCfg, fp)
def compose_qtconf():
""" Create a qt.conf file to remap all the Qt paths to their relative locations
in the app. The QtWebEngineProcess uses its own qt.conf, and ignores the general one
so a separate one is created for QtWebEngineProcess in the libexec dir. """
qtconf = os.path.join(RESOURCE_DIR, 'bin', 'qt.conf')
qtconf_wep = os.path.join(RESOURCE_DIR, 'libexec', 'qt.conf')
contents = """[Paths]
Prefix = ..
Binaries = bin
Libraries = lib
Headers = include/qt
Plugins = plugins
Translations = translations
"""
contents_wep = """[Paths]
Prefix = ..
Translations = translations
"""
with open(qtconf, "w+") as f:
f.write(contents)
with open(qtconf_wep, "w+") as f:
f.write(contents_wep)
def copy_opensesame_with_py_ext():
""" Copy bin/opensesame to bin/opensesame.py to enable multiprocessing """
try:
shutil.copy(
os.path.join(RESOURCE_DIR, 'bin', ENTRY_SCRIPT),
os.path.join(RESOURCE_DIR, 'bin', ENTRY_SCRIPT + '.py')
)
except IOError as e:
print("Could not copy opensesame to opensesame.py: {}".format(e))
def cleanup_conda():
try:
folders = [
os.path.join(RESOURCE_DIR, 'translations'),
]
map(shutil.rmtree, folders)
except IOError as e:
print("Error during cleanup: {}".format(e))