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.


    Pythonista and Pycharm

    Pythonista
    4
    17
    12383
    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.
    • amdescombes
      amdescombes last edited by

      Hi Everyone,

      I have been using Pycharm to cleanup my pythonista code and DropboxSync to , the problem I have is it cannot resolve any of the imports like scene, sounds, etc... Is there any way to include them in Pycharm?
      Thanks in advance
      Cheers
      Andre

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

        You can use the PyCharm directive on the line before the import:

        # noinspection PyUnresolvedReferences
        import scene, sounds
        
        1 Reply Last reply Reply Quote 1
        • amdescombes
          amdescombes last edited by

          Thanks,

          I was familiar with that directive, but I was looking for lib skeletons or some such in order to get the benefits of code completion in PyCharm, etc..

          Cheers
          Andre

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

            import inspect, scene
            print(inspect.getsource(scene))
            
            amdescombes 1 Reply Last reply Reply Quote 1
            • mikashkin
              mikashkin last edited by

              Modules are available in XCode project template.

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

                Thanks @ccc! now I can get those into PyCharm :-)
                Andre

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

                  https://github.com/omz/PythonistaAppTemplate/tree/master/PythonistaAppTemplate/PythonistaKit.framework/pylib_ext Has Scene

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

                    Thanks @mikashkin, I didn't think to look for them there :)
                    Andre

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

                      i couldn't find sound.py though, it's not there and inspect tells me it's an internal module, I guess I'll have to build the skeleton myself or is there a way of getting the skeleton automatically ?
                      Cheers
                      Andre

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

                        import inspect, sound
                        fmt = '{} {}:\n    pass  #  {}\n'
                        for name, func in inspect.getmembers(sound):
                            if callable(func):
                                def_or_class = 'def' if 'function' in str(func) else 'class'
                                print(fmt.format(def_or_class, name, func))
                        
                        1 Reply Last reply Reply Quote 1
                        • amdescombes
                          amdescombes last edited by

                          Thanks @ccc !
                          Is there a way of getting the parameters? :-)
                          Cheers
                          Andre

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

                            No, it's not possible to get any information about the arguments for functions written in C. Under Python 3 some functions have limited argument information in their __text_signature__ attribute, but I don't think any of the Pythonista module functions support that.

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

                              ok, good enough for me!
                              Cheers
                              Andre

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

                                Hello everybody,

                                I wrote the following code based on @ccc's post using inspect, I managed to create python files for use with PyCharm. It has some shortcomings as it cannot get the arguments to the functions, and it doesn't group attributes or present the code alphabetically :)
                                I hope it's useful to someone, I am going to create a gist for it.

                                Cheers
                                Andre

                                import inspect
                                import sound
                                import _ui
                                import _scene2
                                
                                def_fmt = '\n\n%sdef %s():\n%s    pass\n'
                                method_fmt = '\n%sdef %s(self):\n%s    pass\n'
                                cls_method_fmt = '\n%sdef %s(cls):\n%s    pass\n'
                                class_fmt = '\n\n%sclass %s:%s\n'
                                doc_fmt = '%s"""%s"""\n'
                                
                                
                                def handle_attribute(name, func, indent):
                                    if isinstance(func, int) or isinstance(func, float):
                                        return '\n%s%s = %s\n' % (indent, name, func)
                                    else:
                                        return '\n%s%s = "%s"\n' % (indent, name, func)
                                
                                
                                def get_info(modul, indentlevel=0, inclass=False):
                                    _f = []
                                    indent = '    ' * indentlevel
                                    for name, func in inspect.getmembers(modul):
                                        if callable(func):
                                            if name == '__getattribute__':
                                                continue
                                            isfunc = 'function' in str(func)
                                            if name == '__new__':
                                                _f.append(cls_method_fmt % (indent, name, indent))
                                            else:
                                                _f.append((def_fmt if isfunc else method_fmt if inclass else class_fmt) % (indent, name, indent))
                                            if not isfunc and not inclass:
                                                get_info(func, indentlevel + 1, True)
                                        else:
                                            if inclass and name == '__doc__':  # insert docstring
                                                _f.insert(0, doc_fmt % (indent, func))
                                            else:
                                                _f.append(handle_attribute(name, func, indent))
                                    return _f
                                
                                
                                def create_func(modul, modname, indentlevel=0, inclass=False):
                                    print "processing %s" % modname
                                    _f = []
                                    indent = '    ' * indentlevel
                                    for name, func in inspect.getmembers(modul):
                                        if callable(func):
                                            if name == '__getattribute__':
                                                continue
                                            isfunc = 'function' in str(func)
                                            _f.append((def_fmt if isfunc else method_fmt if inclass else class_fmt) % (indent, name, indent))
                                            if not isfunc and not inclass:
                                                cls = get_info(func, indentlevel + 1, True)
                                                _f += cls
                                        else:
                                            if name == '__doc__':  # insert docstring
                                                _f.insert(0, doc_fmt % (indent, func))
                                            elif name not in ['__name__', '__package__']:
                                                _f.append(handle_attribute(name, func, indent))
                                    open(modname, 'w').write(''.join(_f))
                                    print "processed %s" % modname
                                
                                
                                if __name__ == "__main__":
                                    create_func(sound, 'sound.py')
                                    create_func(_ui, '_ui.py')
                                    create_func(_scene2, '_scene2.py')
                                    print "done"
                                
                                1 Reply Last reply Reply Quote 0
                                • amdescombes
                                  amdescombes last edited by

                                  Ok, here is the gist:

                                  https://gist.github.com/amdescombes/30839ae0280a5077b8669757e5efa75d

                                  Cheers
                                  Andre

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

                                    Supercool! If you make stub_builder a repo instead of a gist, then I will send you a pull request or two.

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

                                      Here you go:

                                      https://github.com/amdescombes/pythonista_stub_builder

                                      Enjoy
                                      Andre

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