Xcode Template for Pythonista
I am trying to upload a Pythonista project to the Apple App Store.
I have tried many, many time and keep getting code signing errors.
I am using Xcode 8.2.1
So this is what I have done:
Started with new Xcode Swift single view project, archived it and was able to submit it to the App Store. So my certificates are all working. I downloaded the Xcode template and then archived it. When I submit to Apple, it hangs on the code signing for a really long time and then comes back with this error:
ERROR ITMS-90035: "Invalid Signature. Code object is not signed at all. Make sure you have signed your application with a distribution certificate, not an ad hoc certificate or a development certificate. Verify that the code signing settings in Xcode are correct at the target level (which override any values at the project level). Additionally, make sure the bundle you are uploading was built using a Release target in Xcode, not a Simulator target. If you are certain your code signing settings are correct, choose "Clean All" in Xcode, delete the "build" directory in the Finder, and rebuild your release target. For more information, please consult https://developer.apple.com/library/ios/documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html"
The only thing I can figure out is that it seems to be trying to code sign the PythonistaKit.framework and does not seem to be able to. I can see "PythonistaKit.framework (0 Entitlements), just before I validate it.
Wondering if anyone else is able to reproduce this error, or even better have a fix to the problem.
Have you tried the recommendations here?
I know this is an older thread, but I just wanted to confirm that with the texinfo fix, I have successfully submitted and had an app approved in the last few days.
So the fix is required to get past the automatic filter, but submission is OK with the workaround.
@omz Getting back to the question of @polymerchm : Is it possible to run python3 in Xcode? Using a she-bang line like "#! python3" does not work. sys.version still returns "2.7.5 (default, Feb 15 2016, 15:15:36)". Thanks!
@marcus67 It's currently not possible, I'm afraid.
@omz Thanks for getting back to me.
I was wondering if there is any explanation on why it is no longer possible?
I used Pythonista last year with my grade 11 programming course and got over a dozen apps published on the App Store. I have just started using it again with this years group and told them we will be doing the same thing. If there is anything I can do to help the process along, please let me know. We will not be starting to write the final apps until December.
This post is deleted!last edited by
@JonB The texinfo trick continues to work. Had an app accepted just last week.
Would it be possible to create a repo or a page on Pythonista-Tools that could be a FAQ for using the template? It seems like there are several prereqs and then several steps to complete the process and it would be great to have a landing page for sharing all that tribal knowledge.
I spoke too soon. I had to upgrade Xcode because of iOS11 compatibility, and now I'm back to getting the code signing errors for all the .py files, even if they have the texinfo header. Building apps for local distribution works fine, I just can't sign the code as part of the validation process for the App Store.
Looks like the texinfo hack needs to be modified. The code signing process uses file(1) to check the type of file in the package, and file(1) identifies executable code by checking against different file types and scoring each file type. Apple modified the matching "magic" for python to look for python keywords like "def", "import", "try", "except", etc and each use gives a higher score to python. So for the tex info hack to work, it needs to occur more frequently than the python keywords. Some files just need a single texinfo line; other files need 400+ copies of the texinfo line (some of the python checks only examine the first 4096 characters of the file). Its easy to modify the script above to accomplish this, but hardly elegant.
Hopefully somebody will find this useful and find a simple fix.... like perhaps there's another file type that short-circuits the checking magic? Also, the Apple developer documentation say that script files could go into a specially named subfolder, which would be much simpler, but I've haven't gotten this to work.
out of curiosity, is
fileused locally, or on the server?
Couldn't you use th older file version for identifying text files?
out of curiosity, is file used locally, or on the server?
Yes, It's locally.
You can replace older version of 'usr/bin/file' and 'usr/share/file' to fix it, if your mac os version has updated to 10.13.
Thanks. Will give it a try and test an upload to TestFlight too.
Here's the re-worked script, which throws as many of those dummies at the top of each file as it needs to stop the madness.
EDIT: There are some problems with this method as well, as it bounces the lines indicating the encoding style, which breaks a bunch of stuff... I ended up having to regex replace them back to the top, but will work this script out to do it better later. Just be aware that this will happen!
# Change these: pylib_path1 = '/path/to/PythonistaKit.framework/pylib' pylib_path2 = '/path/to/PythonistaKit.framework/pylib_ext' import shutil import os import subprocess def check_is_executable(file_path): file_output = subprocess.check_output(['file', file_path]) if 'executable' in file_output: return True, file_output return False, file_output def fix_executable(file_path): with open(file_path, 'r') as f: source = f.read() with open(file_path, 'w') as f: f.write('#\input texinfo\n' + source) is_executable, out = check_is_executable(file_path) return not is_executable def fix_pylib(pylib_path, dry_run=False): for path, dirs, files in os.walk(pylib_path): for filename in files: full_path = full_path = os.path.join(path, filename) is_executable, file_output = check_is_executable(full_path) if is_executable: extension = os.path.splitext(full_path).lower() if extension == '.py' or extension == '.pym' or filename == 'command_template': if dry_run: print '### Executable found: %s' % (filename,) else: print 'Fixing %s...' % (filename,) fixed = False counter = 0 while not fixed: fixed = fix_executable(full_path) counter = counter + 1 print 'Fixed with '+str(counter)+' dummy lines.' else: print '### Executable found, but does not seem to be Python code: %s' % (full_path,) if __name__ == '__main__': fix_pylib(pylib_path1) fix_pylib(pylib_path2)```
Hi @sreyemnayr, just tried your script, but still getting an error on upload to app store. Any other ideas or refinements to your script?
I'm making a bit of progress:
- My original error related to the future.py file in pylib, after running the script the Xcode error changed.
- I noticed that after running the above script the specific file that I was getting the 'Invalid Signature' error on had change to pylib/compiler/init.py. I had a look at that file and it didn't have a #\input texinfo up the top so I added it manually.
- I then reran the script and the error changed to pylib/compiler/ast.py This did have lots of #\input texinfo, so I copy and pasted all of them to double the amount of #\input texinfo lines at the top of the file. This seemed to satisfy Xcode.
- I then reran the script and the error changed one of the files in pylib/ctypes/test. I just deleted the whole pylib/ctypes/test folder.
- I than reran the script and the error changed to pylib/dateutil/READEME. I deleted the README file and the NEWS file while I was at it.
- I than reran the script and the error changes to pylib/site-packages/dropbox/init.py. As I'm not using dropbox in my app I just deleted the dropbox folder.
- I then had errors on pylib/site-packages/twitter.py, webbrowser.py, xmltodict.py and ui.py. They all had just one #\input texinfo line so I inserted an extra 1000 #\input texinfo lines at the top of each.
- I then had remaining errors in the files in pylib_ext/ so I added about #\input texinfo lines at the top of each.
- Finally my app submitted successfully!!!!
I must confess I really don't understand all of this. Feels like there's got to be a better way....
Thanks to @sreyemnayr for posting the script as I would not have solved this without it.
@peterdougstuart any chance you would be willing to share your updated template?
@sreyemnayr could you please update your script to work in Python 3?
if extension == '.py' or extension == '.pym' # can be shortened to: if extension in ('.py', '.pym')