Forum Archive

Pydia: A package installer for Pythonista

ProfSpaceCadet

Pydia Installer.py: https://gist.github.com/bmw1821/d9883042b95a818e6429

Source Code: https://gist.github.com/bmw1821/bc2ccf257d60804be010

JonB

your installer is a bit broken (missing imports, site-packages is nit a valid far name)

also, PLEASE PLEASE do not import UIKit and import Foundation.
First, you did not include these in your installer.
Second, these are neither past nor future proof, as not everything steven aliased is available in older ios versions, or may be available in future versions. no try/except makes this very fragile code.

If you really don't want to alias only the classes you need, at least use this, as it will work with every ios version that pythonista works on or will work on.

 from objc_util import *

c= ObjCClass.get_names(prefix='UI')+ObjCClass.get_names(prefix='NS')
for cls in c:
   if not cls.startswith('_'):
      try:
         globals()[cls]=ObjCClass(cls)
      except ValueError:
         pass
JonB

it also seems as if the main script is not quite complete, at least as installed from the installer. Several imports don't work ( i think the direcotry structure was changed)..

I can't wait to try this, the ui built from almost pure objc should be pretty interesting

omz

Here's a shorter method of loading all UI... classes into the global namespace, if you really want to do that (I find it a bit wasteful):

from objc_util import ObjCClass
globals().update({n: ObjCClass(n) for n in ObjCClass.get_names('UI')})

@JonB The startswith('_') check seems unnecessary, given that the class names are already filtered by prefix. Also, a ValueError shouldn't really happen because get_names only returns names of classes that actually exist.