macOS: Fix kitty not being added to PATH automatically

Fixes #3063. Apparently in newer Python, Py_Initialize() nukes
sys._xoptions when the isolate flag is set.
This commit is contained in:
Kovid Goyal 2020-10-27 10:37:10 +05:30
parent 3ddaa4aff9
commit 93d1aacfb6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 6 deletions

View File

@ -27,6 +27,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Fix selections created by dragging upwards not being auto-cleared when
screen contents change (:pull:`3028`)
- macOS: Fix kitty not being added to PATH automatically when using pre-built
binaries (:iss:`3063`)
- Allow adding MIME definitions to kitty by placing a ``mime.types`` file in
the kitty config directory (:iss:`3056`)

View File

@ -42,10 +42,11 @@ safe_realpath(const char* src, char *buf, size_t buf_sz) {
#endif
static inline void
set_xoptions(const wchar_t *exe_dir, const char *lc_ctype) {
set_xoptions(const wchar_t *exe_dir, const char *lc_ctype, bool from_source) {
wchar_t buf[PATH_MAX+1] = {0};
swprintf(buf, PATH_MAX, L"bundle_exe_dir=%ls", exe_dir);
PySys_AddXOption(buf);
if (from_source) PySys_AddXOption(L"kitty_from_source=1");
if (lc_ctype) {
swprintf(buf, PATH_MAX, L"lc_ctype_before_python=%s", lc_ctype);
PySys_AddXOption(buf);
@ -66,7 +67,6 @@ static int run_embedded(const char* exe_dir_, const char *libpath, int argc, wch
int ret = 1;
wchar_t *exe_dir = Py_DecodeLocale(exe_dir_, NULL);
if (exe_dir == NULL) { fprintf(stderr, "Fatal error: cannot decode exe_dir\n"); return 1; }
set_xoptions(exe_dir, lc_ctype);
wchar_t stdlib[PATH_MAX+1] = {0};
#ifdef __APPLE__
const char *python_relpath = "../Resources/Python/lib";
@ -80,9 +80,9 @@ static int run_embedded(const char* exe_dir_, const char *libpath, int argc, wch
);
if (num < 0 || num >= PATH_MAX) { fprintf(stderr, "Failed to create path to python stdlib\n"); return 1; }
Py_SetPath(stdlib);
PyMem_RawFree(exe_dir);
if (num < 0 || num >= PATH_MAX) { fprintf(stderr, "Failed to create path to kitty lib\n"); return 1; }
Py_Initialize();
set_xoptions(exe_dir, lc_ctype, false);
PyMem_RawFree(exe_dir);
PySys_SetArgvEx(argc - 1, argv + 1, 0);
PySys_SetObject("frozen", Py_True);
PyObject *kitty = PyUnicode_FromString(libpath);
@ -104,10 +104,11 @@ static int run_embedded(const char* exe_dir_, const char *libpath, int argc, wch
(void)libpath;
wchar_t *exe_dir = Py_DecodeLocale(exe_dir_, NULL);
if (exe_dir == NULL) { fprintf(stderr, "Fatal error: cannot decode exe_dir: %s\n", exe_dir_); return 1; }
set_xoptions(exe_dir, lc_ctype);
bool from_source = false;
#ifdef FROM_SOURCE
PySys_AddXOption(L"kitty_from_source=1");
from_source = true;
#endif
set_xoptions(exe_dir, lc_ctype, from_source);
PyMem_RawFree(exe_dir);
return Py_Main(argc, argv);
}