Skip to content

Commit 0bf1f9d

Browse files
committed
add $GPODDER_HOME/pip/... to PYTHONPATH
Needs to be done in the native launcher. Switch to objective-c launcher to get ApplicationSupport and ~ directories from Foundation framework. GPODDER_HOME could be set from the native launcher, but let it be recomputed in python launcher
1 parent 01058ee commit 0bf1f9d

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

bundle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
source env.sh
66

77
echo compiling native launcher...
8-
echo 'gcc -L$PREFIX/lib `python3-config --cflags --ldflags --embed` -o $PREFIX/bin/gpodder-launcher misc/bundle/launcher.c'| jhbuild shell
8+
echo 'clang -mmacosx-version-min=10.9 -framework Foundation -L$PREFIX/lib `python3-config --cflags --ldflags --embed` -o $PREFIX/bin/gpodder-launcher misc/bundle/launcher.m'| jhbuild shell
99

1010
echo creating app...
1111
jhbuild run gtk-mac-bundler misc/bundle/gpodder.bundle
Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define PY_SSIZE_T_CLEAN
2222
#include <Python.h>
2323
#include <CoreFoundation/CoreFoundation.h>
24+
#import <Foundation/Foundation.h>
2425
#include <sys/syslimits.h>
2526
#include <stdio.h>
2627

@@ -81,6 +82,80 @@ get_bundle_dir(void)
8182
return retval;
8283
}
8384

85+
static NSString*
86+
gpodder_home(NSFileManager* fm) {
87+
// 1. ${GPODDER_HOME}
88+
char* gpodder_home = getenv("GPODDER_HOME");
89+
if (gpodder_home != NULL) {
90+
NSLog(@"gPodder home from environment GPODDER_HOME is %s", gpodder_home);
91+
return [NSString stringWithUTF8String: gpodder_home];
92+
}
93+
// 2. Application Support/gPodder
94+
NSError *error = nil;
95+
NSURL *applicationSupport = [fm URLForDirectory:NSApplicationSupportDirectory
96+
inDomain:NSUserDomainMask
97+
appropriateForURL:0
98+
create:YES
99+
error:&error];
100+
if (error) {
101+
NSLog(@"Error getting Application Support directory %@", error);
102+
exit(1);
103+
}
104+
NSString* path = applicationSupport.path;
105+
path = [path stringByAppendingString: @"/gPodder"];
106+
if ([fm fileExistsAtPath: path])
107+
{
108+
NSLog(@"gPodder home is %@", path);
109+
return path;
110+
}
111+
112+
// 3. ~/gPodder
113+
NSURL* home = [fm homeDirectoryForCurrentUser];
114+
path = home.path;
115+
path = [path stringByAppendingString: @"/gPodder"];
116+
NSLog(@"Default gPodder home is %@", path);
117+
return path;
118+
}
119+
120+
static NSString*
121+
handle_custom_pip_path(void) {
122+
NSError *error = nil;
123+
NSFileManager* fm = [NSFileManager defaultManager];
124+
NSString* path = gpodder_home(fm);
125+
126+
NSString* new_path = [path stringByAppendingString: @"/new-pip"];
127+
if ([fm fileExistsAtPath: new_path])
128+
{
129+
NSLog(@"new_path %@ exists", new_path);
130+
NSString* old_path = [path stringByAppendingString: @"/pip"];
131+
if ([fm fileExistsAtPath: old_path])
132+
{
133+
NSLog(@"old_path %@ exists, moving to trash", old_path);
134+
NSURL *localURL = [NSURL fileURLWithPath:old_path];
135+
if([fm trashItemAtURL:localURL resultingItemURL:nil error:&error] != YES)
136+
{
137+
NSLog(@"Unable to put old pip %@ to trash: %@", old_path, error);
138+
exit(1);
139+
}
140+
}
141+
NSLog(@"moving new_path %@ to %@", new_path, old_path);
142+
if([fm moveItemAtPath:new_path toPath:old_path error:&error] != YES)
143+
{
144+
NSLog(@"Unable to move new pip %@ to %@: %@", new_path, old_path, error);
145+
exit(1);
146+
}
147+
}
148+
149+
path = [path stringByAppendingString: @"/pip/lib/python3.8/site-packages"];
150+
NSLog(@"considering %@", path);
151+
if ([fm fileExistsAtPath: path])
152+
{
153+
NSLog(@"path %@ exists, adding to PYTHONPATH", path);
154+
return path;
155+
}
156+
return nil;
157+
}
158+
84159
static void
85160
set_python_path(void)
86161
{
@@ -90,7 +165,14 @@ set_python_path(void)
90165
wchar_t *path;
91166
CFStringRef str = make_filesystem_string(bundle_url);
92167
CFRelease(bundle_url);
93-
mstr = CFStringCreateMutableCopy(NULL, 5 * PATH_MAX, str);
168+
mstr = CFStringCreateMutable(NULL, 5 * PATH_MAX);
169+
170+
NSString* customPath = handle_custom_pip_path();
171+
if (customPath != NULL)
172+
{
173+
CFStringAppend(mstr, (__bridge CFStringRef)customPath);
174+
CFStringAppendCString(mstr, ":", kCFStringEncodingUTF8);
175+
}
94176
CFStringAppendCString(mstr, "/lib/python36.zip:", kCFStringEncodingUTF8);
95177
CFStringAppend(mstr, str);
96178
CFStringAppendCString(mstr, "/lib/python3.8:",

misc/bundle/launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def regen(self, dest):
121121
for k, v in os.environ.items():
122122
print("%s=%s" % (k,v))
123123

124-
# Gen cert.pem
125124
def gpodder_home():
126125
# don't inadvertently create the new gPodder home,
127126
# it would be prefered to the old one
@@ -136,6 +135,7 @@ def gpodder_home():
136135
return cand
137136
return default_path
138137

138+
139139
gphome = gpodder_home()
140140
os.makedirs(join(gphome, 'openssl'), exist_ok=True)
141141
# generate cert.extracted.pem

0 commit comments

Comments
 (0)