So I made an initial script "strip_pylib.py".
This script should be runned in pythonista at the phone.
It will make a "pylib_clean.sh" file, which should be copied to:
"PATH/PythonistaAppTemplate/PythonistaKit.framework"
at the Xcode project.
And then issue:
source pylib_clean.sh
rm pylib_clean.sh
(Note: pylib_clean.sh should be deleted in the PythonistaKit.framework folder afterwards,
or there will be problems with signing and sending to App store.)
pylib_clean.sh will delete a lot of files.
After compilation in Xcode, the program did not work.
I had to manually copy back the directory: "/pylib/encodings" from another copy of PythonistaAppTemplate, and then it worked.
The compilation in Xcode is a lot faster. :)
And the app size went from 60 MB to 30 MB.
There are still some files left, but I am not sure why they survived.
strip_pylib.py
# Clear all
# To get pythonista to work again, restart the app
import sys
sys.modules[__name__].__dict__.clear()
# Now import
import sys
import inspect
import importlib
splitstr = "PythonistaKit.framework"
pyt_mods = [
"os",
"datetime",
"json",
"requests",
"operator",
"time",
]
pythonista_mods = [
"ui",
"console",
"dialogs",
"objc_util"
]
all_mods = pyt_mods + pythonista_mods
keep_list = []
for imods in all_mods:
try:
m = importlib.import_module(imods)
dirpath, filepath = inspect.getfile(m).split(splitstr)
keep_list.append(filepath)
except TypeError as e:
#print(e)
pass
# Get the imported modules
dict = sys.modules
for key in dict:
val = dict[key]
if val == None:
continue
else:
try:
filepath = inspect.getfile(val)
if splitstr in filepath:
filepath_append = filepath.split(splitstr)[1]
keep_list.append(filepath_append)
else:
pass
except TypeError as e:
#print(e)
pass
# Make uniq and sort
keep_list = sorted(set(keep_list))
# Now find all files
import os
fp = dirpath+splitstr
extensions = [".py", ".pyo"]
all_files = []
for path, dirs, files in os.walk(fp):
for f in files:
filename, file_extension = os.path.splitext(f)
if "/pylib/" in path or "/pylib_ext/" in path:
if file_extension in extensions:
stringfp = os.path.join(path, f)
dirpath, filepath = stringfp.split(splitstr)
all_files.append(filepath)
# Make uniq and sort
all_files = sorted(set(all_files))
# Make a delete list
dellist = [x for x in all_files if x not in keep_list]
# Write delete file
fname = 'pylib_clean.sh'
f = open(fname,'w')
f.write("#!/usr/bin/env bash\n")
for idel in dellist:
f.write("rm ."+idel+"\n")
f.close()
f = open(fname, "r")
for line in f:
print(line),
f.close()