box-python-sdk icon indicating copy to clipboard operation
box-python-sdk copied to clipboard

Not all module statically reachable from package root

Open jmoldow opened this issue 8 years ago • 8 comments

By that I mean, if you run certain static analyzers on boxsdk, they might tell you that some modules are never used.

For example, import boxsdk will run from .object import *, and boxsdk.object has folder in its __all__. So at runtime, import boxsdk should import boxsdk.object.folder and include it in sys.modules.

However, some static analyzers aren't smart enough to realize that folder is imported this way, and may assume that folder is not used somewhere. We've found that py2app and pyinstaller both make this assumption, and will optimize boxsdk.object.folder out of the build, along with some other modules.

We should:

  • Make sure that all modules are included at least once in a very explicit way.
  • Write a test to assert this.

I've started working on this.

jmoldow avatar Aug 24 '16 22:08 jmoldow

Hi, I am working with the boxsdk and pyinstaller modules to create a stand alone application, but I am getting the following error:

File "/usr/local/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.dict) File "boxsdk/init.py", line 8, in AttributeError: module 'boxsdk.object' has no attribute 'collaboration'

Is this still being worked on now?

eliasyishak avatar Apr 14 '19 16:04 eliasyishak

this issue is blocking deployment of my project, what can we do to resolve this. does anyone know the broken hidden imports!

sam2332 avatar Apr 22 '20 20:04 sam2332

added to spec file

         hiddenimports=['box[jwt]','boxsdk.object'],

im still getting the following error.

File "site-packages\boxsdk_init_.py", line 8, in AttributeError: module 'boxsdk.object' has no attribute 'collaboration_whitelist_entry' [98048] Failed to execute script generate

sam2332 avatar Apr 22 '20 20:04 sam2332

Hi, I had to specifically import each module for it to work, ie. collaboration_whitelist_entry is a specific import line for me.

         hiddenimports=[
            'boxsdk.object.collaboration',
            'boxsdk.object.collaboration_whitelist',
            'boxsdk.object.collaboration_whitelist_entry',
            'boxsdk.object.collaboration_whitelist_exempt_target',
            'boxsdk.object.collection',
            'boxsdk.object.comment',
            'boxsdk.object.device_pinner',
            'boxsdk.object.enterprise',
            'boxsdk.object.events',
            'boxsdk.object.event',
            'boxsdk.object.file',
            'boxsdk.object.file_version',
            'boxsdk.object.file_version_retention',
            'boxsdk.object.folder',
            'boxsdk.object.group',
            'boxsdk.object.group_membership',
            'boxsdk.object.legal_hold',
            'boxsdk.object.legal_hold_policy',
            'boxsdk.object.legal_hold_policy_assignment',
            'boxsdk.object.metadata_cascade_policy',
            'boxsdk.object.metadata_template',
            'boxsdk.object.recent_item',
            'boxsdk.object.retention_policy',
            'boxsdk.object.retention_policy_assignment',
            'boxsdk.object.search',
            'boxsdk.object.storage_policy',
            'boxsdk.object.storage_policy_assignment',
            'boxsdk.object.terms_of_service',
            'boxsdk.object.terms_of_service_user_status',
            'boxsdk.object.trash',
            'boxsdk.object.task',
            'boxsdk.object.task_assignment',
            'boxsdk.object.user',
            'boxsdk.object.upload_session',
            'boxsdk.object.webhook',
            'boxsdk.object.watermark',
            'boxsdk.object.web_link']

eliasyishak avatar Apr 22 '20 20:04 eliasyishak

YOU ARE AWESOME! thank you so much

sam2332 avatar Apr 22 '20 20:04 sam2332

i've been there before! glad to help

eliasyishak avatar Apr 22 '20 20:04 eliasyishak

Nice one @eliasIBM Thank you

jerkmuffin avatar Aug 11 '20 22:08 jerkmuffin

I suggest a different method. In .spec file I added:

import boxsdk.object

boxsdk_objects = [f"boxsdk.object.{i}" for i in dir(boxsdk.object) if not i.startswith("__")]

...
hiddenimports=boxsdk_objects,
...

In my project it works.

fedelemantuano avatar Aug 12 '22 11:08 fedelemantuano

This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.

stale[bot] avatar Dec 19 '22 20:12 stale[bot]

This issue has been automatically closed due to maximum period of being stale. Thank you for your contribution to Box Python SDK and feel free to open another PR/issue at any time.

stale[bot] avatar Dec 27 '22 06:12 stale[bot]