Skip to content

Commit

Permalink
Improve dependency import
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTitu committed Mar 12, 2024
1 parent 41a2892 commit ca6759b
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 19 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion op_uniffi_core_linux_amd64/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

setup(
name='op_uniffi_lib_mac_arm64',
name='sdk-core-linux-amd64',
version='0.1.0',
packages=find_packages(),
author='1Password',
Expand Down
2 changes: 1 addition & 1 deletion op_uniffi_core_mac_arm64/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


setup(
name='op_uniffi_lib_mac_arm64',
name='sdk_core_mac_arm64',
version='0.1.0',
packages=find_packages(),
author='1Password',
Expand Down
36 changes: 21 additions & 15 deletions sdk/onepassword/core.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import json
import sys
import importlib.util
#import op_uniffi_lib_mac_arm64.op_uniffi_core as core

if (spec := importlib.util.find_spec("op_uniffi_lib_mac_arm64.op_uniffi_core")) is not None:
module = importlib.util.module_from_spec(spec)
print(module)
sys.modules["core"] = module
spec.loader.exec_module(module)
print(f"op_uniffi_lib_mac_arm64 has been imported")
elif (spec := importlib.util.find_spec("op_uniffi_lib_linux_amd64")) is not None:
module = importlib.util.module_from_spec(spec)
sys.modules["core"] = module
spec.loader.exec_module(module)

core = sys.modules["core"]


def try_import_core(platform_specific_package):
if (spec := importlib.util.find_spec(platform_specific_package)) is not None:
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
return None

potential_dependencies = [
"sdk_core_linux_amd64.op_uniffi_core",
"sdk_core_mac_arm64.op_uniffi_core"
]

core = None
for dep in potential_dependencies:
core = try_import_core(dep)
# Stop at the first succesful import
if core is not None:
break


# InitClient creates a client instance in the current core module and returns its unique ID.
async def _init_client(client_config):
Expand Down
4 changes: 2 additions & 2 deletions sdk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
description="The 1Password Python SDK offers programmatic read access to your secrets in 1Password in an interface native to Python.",
url='https://github.com/1Password/onepassword-sdk-python',
install_requires=[
"op_uniffi_lib_mac_arm64; platform_system=='Darwin' and platform_machine=='arm64'",
"op_uniffi_lib_mac_x86_64; platform_system=='Linux' and platform_machine=='x86_64'",
"sdk_core_mac_arm64; platform_system=='Darwin' and platform_machine=='arm64'",
"sdk_core_linux_x86_64; platform_system=='Linux' and platform_machine=='x86_64'",
],
)

0 comments on commit ca6759b

Please sign in to comment.