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.


    Preparation for Xcode ? Delete files in PythonistaAppTemplate?

    Pythonista
    4
    13
    8076
    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.
    • tlinnet
      tlinnet last edited by

      @tlinnet said:

      PythonistaAppTemplate/PythonistaKit.framework/Media
      PythonistaAppTemplate/PythonistaKit.framework/pylib_ext

      Hi!

      I deleted:
      PythonistaAppTemplate/PythonistaKit.framework/Media
      PythonistaAppTemplate/PythonistaKit.framework/pylib_ext

      And the app still work. :)
      The compilation was a little more smooth, when the compiler didnt seem to copy over all the
      media files.

      For your suggestion, it almost calls for a small snippet of code to analyse what could be deleted. ;)
      But for now I am happy, and I will come back to this issue later.

      Thanks again!

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

        You must not have had any modules in the pylib_ext folder. But still, remember that you use more modules than your main program imports. Also, remember that apple has a maximum app size. It is in the documentation, I forget the actual number.

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

          @NoBetterName maximum app size shouldn't be a problem. iOS apps can be up to 4GB in size, and the app executable can be up to 60MB.

          Source: http://stackoverflow.com/a/4753253/2513803

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

            I made it through to TestFlight. :)

            Deleting:
            PythonistaAppTemplate/PythonistaKit.framework/Media
            PythonistaAppTemplate/PythonistaKit.framework/pylib_ext

            And just a main.py file, gave an app size og 60 MB.
            Which is within the 100 Mb, "over the air" download limit.

            So I dont want to hassle around to get lower app size. :)
            Cool!

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

              A lot of the stuff in the regular pylib folder is taking up space. A lot of those modules you don't need. Your main.py will barely take up any space. You might be able to get your app size under 10mB.

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

                May I ask the community and @omz in particular if there is yet a an equivalent template available for Pythonista v2.0? If there is, please provide a link to it. If there is not, is there an action plan to provide one?

                It is my understanding that given there is no template for Pythonista v2.0 it is NOT currently possible to produce apps for the Apple App store. Is my understanding correct?

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

                  Depends on which Python you are using. Pythonista 2.0 carries 2 Python levels: Python 2.7 and Python 3.5. The current template supports Python 2.7. To my knowledge, there is no template for Xcode and Python 3.5.

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

                    @NoBetterName that was my understanding as well, and you help to format my request more clearly: I mean where is there a template for Pythonista 2.0, Python level 3.x code?

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

                      I got this started.

                      Running this snippet on the phone, give me the file paths.

                      import inspect
                      import importlib
                      
                      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:
                              module_obj  = importlib.import_module(imods)
                              filepath = inspect.getfile(module_obj).split("PythonistaKit.framework")[1]
                              keep_list.append(filepath)
                      
                          except TypeError as e:
                              print(e)
                      
                      for filep in keep_list:
                          print(filep)```
                      1 Reply Last reply Reply Quote 0
                      • tlinnet
                        tlinnet last edited by

                        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()
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors