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
-
You can use the PyCharm directive on the line before the import:
# noinspection PyUnresolvedReferences import scene, sounds
-
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 -
import inspect, scene print(inspect.getsource(scene))
-
Modules are available in XCode project template.
-
Thanks @ccc! now I can get those into PyCharm :-)
Andre -
-
Thanks @mikashkin, I didn't think to look for them there :)
Andre -
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 -
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))
-
Thanks @ccc !
Is there a way of getting the parameters? :-)
Cheers
Andre -
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. -
ok, good enough for me!
Cheers
Andre -
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
Andreimport 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"
-
Ok, here is the gist:
https://gist.github.com/amdescombes/30839ae0280a5077b8669757e5efa75d
Cheers
Andre -
Supercool! If you make
stub_builder
a repo instead of a gist, then I will send you a pull request or two. -