LaunchServices imports not all working as expected

Issue #133 new
Jeremy Chiu
created an issue

I think this may be related to Issue #126. When using the latest from the repo I can import LaunchServices but I can't import everything I'd expect from it. For instance I can import: kLSSharedFileListDoNotMountVolumes, kLSSharedFileListItemBeforeFirst, and kLSSharedFileListNoUserInteraction. But I cannot import: LSSharedFileListCopySnapshot, LSSharedFileListCreate,LSSharedFileListInsertItemURL, LSSharedFileListItemResolve, or LSSharedFileListItemRemove.

I noted that the 'k' prefix is different so I tried adding that but it didn't seem to fix the issue. I also tried dir(LaunchServices) and I got an odd error

  File "<stdin>", line 1, in <module>
  File "/Users/jchiu/pyobjc/pyobjc-core/Lib/objc/_lazyimport.py", line 115, in __dir__
    return self.__all__
  File "/Users/jchiu/pyobjc/pyobjc-core/Lib/objc/_lazyimport.py", line 120, in __getattr__
    value = self.__calc_all()
  File "/Users/jchiu/pyobjc/pyobjc-core/Lib/objc/_lazyimport.py", line 205, in __calc_all
    self.__dict__[nm] = objc._loadConstant(nm, tp, True)
ValueError: Don't know CF type for typestr '^{OpaqueLSSharedFileListItemRef=}', cannot create special wrapper

Doing dir on other packages like Cocoa worked fine.

Steps I used to repro the issue

  • Get a machine with OSX 10.11 beta.

  • Install latest pyobjc-core, pyobjc-framework-Cocoa, pyobjc-framework-LaunchServices. I did this by cloning the repo & using "pip install -e [path for each of those packages]"

  • Launch python and do

  1. "from LaunchServices import LSSharedFileListCreate" (gets a no name error)

  2. "import LaunchServices"

  3. "dir(LaunchServices)" (gets the error I listed above)

Comments (5)

  1. Jeremy Chiu reporter

    I haven't used Python c-api stuff before but the key (typestr), '^{OpaqueLSSharedFileListItemRef=}', looks odd to me. And clearly it isn't finding that in PyObjC_TypeStr2CFTypeID (not sure where that'd defined yet).

  2. Jeremy Chiu reporter

    perhaps pyobjc-framework-LaunchServices/Lib/LaunchServices/_metadata.py needs to be updated? Looking in there I see the functions I want listed in the 'functions' dict and I see references to the '^{OpaqueLSSharedFileListItemRef=}' type.

  3. Jeremy Chiu reporter

    Nope, I don't get it. _metadata has the type listed in cftypes list which is pulled during the init of LaunchServices. Lazy import does seem to try to load the right cftypes. I'm not sure exactly what's going on in the objc code. I don't see any reason why 10.11 would act differently from 10.10 tho. So it seems that something is going on in the registerCFSignature flow or possibly the LoadConstant flow (but that looks less error prone to me).

  4. Log in to comment