omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Xcode Template for Pythonista

    Pythonista
    29
    68
    68795
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sreyemnayr
      sreyemnayr last edited by sreyemnayr

      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)[1].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)```
      1 Reply Last reply Reply Quote 0
      • peterdougstuart
        peterdougstuart last edited by

        Hi @sreyemnayr, just tried your script, but still getting an error on upload to app store. Any other ideas or refinements to your script?

        1 Reply Last reply Reply Quote 0
        • peterdougstuart
          peterdougstuart last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • RomSpy
            RomSpy last edited by

            @peterdougstuart any chance you would be willing to share your updated template?

            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by

              @sreyemnayr could you please update your script to work in Python 3?

              1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by

                if extension == '.py' or extension == '.pym'
                # can be shortened to:
                if extension in ('.py', '.pym')
                
                1 Reply Last reply Reply Quote 0
                • peterdougstuart
                  peterdougstuart last edited by

                  Sorry for delay responding....

                  Happy to share @RomSpy, but please note that my templates have been minimized to my project i.e. deleted lots of modules I'm not using. Therefore it may not work for your project. You might be better off following the principles of steps I outlined above.

                  If you are still interested in my templates can you send me a PM on twitter (same handle as here) and I'll send you a zip or something. Alternatively point me to somewhere I can upload the files and I'll do so.

                  xino386 1 Reply Last reply Reply Quote 0
                  • RomSpy
                    RomSpy last edited by

                    @peterdougstuart thank you for the offer. I ended up doing what you did and removing everything I wasn't using and then running the script above. I was able to successfully update my app in the store using that method in addition to your added steps. Thanks again.

                    1 Reply Last reply Reply Quote 0
                    • xino386
                      xino386 @peterdougstuart last edited by

                      @peterdougstuart
                      Hi, i am interested in your templates which is submitted to itunesConnect successfully, can you send me a zip ?

                      1 Reply Last reply Reply Quote 0
                      • peterdougstuart
                        peterdougstuart last edited by

                        Hi @xino386 can you PM on twitter and I’ll send you a zip of my scripts (same handle as here). Note that my scripts have been trimmed down to match the subset of the libraries used in my app so you might be better off following the steps above to get it to work.

                        1 Reply Last reply Reply Quote 1
                        • stepper
                          stepper @omz last edited by stepper

                          @omz
                          I have a succes storey with your fix script (June 19/18). Here’s what I did. Pasted approx 400 #\input texinfo ‘s into a text file. Pasted the contents (all one line, no line breaks) into your script as a string (replacing the existing ‘#\input texinfo’. Changed the folder permissions for the two lib folders to read/write (temporarily).ran your script. It fixed all but a half dozen of the files. Went into the folders manually. The unchanged files stood out cause they didn’t have today’s date of modification. Manually pasted in the approx 400 from the original text file into those few.
                          Successfully uploaded to app connect where my app is now in Beta on test flight.
                          Thank You very much!

                          1 Reply Last reply Reply Quote 1
                          • omz
                            omz last edited by

                            @stepper That's interesting, though I've found a better solution recently: You can add something like #import pythonista as the first line, and it'll be recognized as Objective-C source code (which isn't directly executable, so it doesn't cause issues with code signing).

                            1 Reply Last reply Reply Quote 1
                            • RomSpy
                              RomSpy last edited by

                              @omz
                              Any chance we will see an updated template that uses all the great new features in version 3?

                              1 Reply Last reply Reply Quote 1
                              • omz
                                omz last edited by

                                @RomSpy Yes, that's something I'd really like to do soon, and I've already done some of the work required, but it's still kind of a mess.

                                1 Reply Last reply Reply Quote 2
                                • bg2b
                                  bg2b last edited by

                                  Is there an up-to-date summary of the idea for packaging up a Pythonista project to make an app? I see that the template linked from

                                  https://forum.omz-software.com/topic/1911/new-xcode-template-beta

                                  doesn't exist anymore, and I'm not sure where to begin learning.

                                  1 Reply Last reply Reply Quote 0
                                  • yueqiw
                                    yueqiw last edited by

                                    @sreyemnayr I tried your re-worked script and it worked well.
                                    I used #import pythonista\n rather than #\input texinfo\n
                                    To make it run faster I prepend 10 strings in each iteration, e.g.f.write("#import pythonista\n" * 10 + source) and set counter to increment by 10.

                                    1 Reply Last reply Reply Quote 0
                                    • amdescombes
                                      amdescombes last edited by

                                      Hello everyone,

                                      Here is a reworked script that adds the comments at the top but preservers coding= comments.
                                      It is not perfect, but it helped me succesfully submit an app to the Appstore, I hope it is of help to every one.

                                      #import pythonista
                                      # Change the ********** to point to the directory containing the Pythonista framework :
                                      project_path = '**********/PythonistaAppTemplate'
                                      pylib_path1 = '%s/PythonistaKit.framework/pylib' % project_path
                                      pylib_path2 = '%s/PythonistaKit.framework/pylib_ext' % project_path
                                      MAX_REPEATS = 10
                                      
                                      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, dry_run=False):
                                          with open(file_path, 'r') as f:
                                              source = f.readlines()
                                              if 'coding:' in source[0].lower():
                                                  firstline = source[0]
                                                  start = 1
                                              else:
                                                  firstline = ''
                                                  start = 0
                                          if dry_run:
                                              if firstline:
                                                  print(firstline)
                                          else:
                                              with open(file_path, 'w') as f:
                                                  f.write(firstline + '#import pythonista\n' * MAX_REPEATS + ''.join(source[start:]))
                                          is_executable, out = check_is_executable(file_path)
                                          return not is_executable
                                      
                                      def fix_pylib(pylib_path, dry_run=False):
                                          print ("fixing", pylib_path)
                                          for path, dirs, files in os.walk(pylib_path):
                                              print(path, dirs, files)
                                              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)[1].lower()
                                                      if extension in ['.py', '.pym'] or filename == 'command_template':
                                                          if dry_run:
                                                              print '### Executable found: %s' % (filename,)
                                                              fixed = fix_executable(full_path, dry_run)
                                                          else:
                                                              print 'Fixing %s...' % (filename,)
                                                              fixed = False
                                                              counter = 0
                                                              while not fixed:
                                                                  fixed = fix_executable(full_path)
                                                                  counter += MAX_REPEATS
                                      
                                                              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, False)
                                          fix_pylib(pylib_path2, False)
                                      
                                      

                                      Cheers
                                      Andre

                                      1 Reply Last reply Reply Quote 1
                                      • JonB
                                        JonB last edited by JonB

                                        so, this may be a stupid question, but my understanding of this problem is that file is running locally, and is getting rejected locally.

                                        so, why not just edit /usr/share/file/magic (or copy it, edit it, then file -C to compile it to a new .mgc), or create an alias to file with a -m argument pointing to your custom magic file. It should be possible to edit the entry for pythonm or add custom search for the shebang or coding lines, to simply output a safe mimetype,

                                        1 Reply Last reply Reply Quote 1
                                        • amdescombes
                                          amdescombes last edited by

                                          Hi Jon,

                                          I think that is a very good question and a very interesting option to explore as it would avoid modifying the framework. I'll look into it as soon as I get a chance and report my findings back.

                                          Cheers
                                          Andre

                                          1 Reply Last reply Reply Quote 0
                                          • TheRealBret
                                            TheRealBret last edited by

                                            I really want to have a new Xcode template for Pythonista 3. I realize that I've already bought Pythonista so I'm not generating new income for @omz.... so I hereby pledge to send money via Paypal/Zelle (or any other method) to @omz to help support his time for the production of a new Xcode template. I'd gladly pay $25 for a new template. I'd even pay this annually if it would be updated regularly.

                                            Thoughts anyone? @omz?? How can we help get a new Xcode template made?

                                            vignesh 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors