Skip to content

Commit b8c5e74

Browse files
authored
Merge pull request #35 from ajyey/feature/refactor
Improves machine and platform checks and fixes deprecated ruff command in Github validation workflow
2 parents d8400ae + fdc2493 commit b8c5e74

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

.github/workflows/validate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ jobs:
4747
- name: Lint with Ruff
4848
run: |
4949
pip install ruff
50-
ruff --output-format=github --exclude=src/onepassword/lib/ .
50+
ruff check --output-format=github --exclude=src/onepassword/lib/ .
5151
continue-on-error: true

setup.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@ def finalize_options(self):
2020
def get_shared_library_data_to_include():
2121
# Return the correct uniffi C shared library extension for the given platform
2222
include_path = "lib"
23-
if platform.machine().lower() == "x86_64" or platform.machine().lower() == "amd64":
23+
machine_type = platform.machine().lower()
24+
if machine_type in ["x86_64", "amd64"]:
2425
include_path = os.path.join(include_path, "x86_64")
25-
elif (
26-
platform.machine().lower() == "aarch64" or platform.machine().lower() == "arm64"
27-
):
26+
elif machine_type in ["aarch64", "arm64"]:
2827
include_path = os.path.join(include_path, "aarch64")
2928

30-
c_shared_library_file_name = ""
31-
if platform.system() == "Darwin":
32-
c_shared_library_file_name = "libop_uniffi_core.dylib"
33-
elif platform.system() == "Linux":
34-
c_shared_library_file_name = "libop_uniffi_core.so"
35-
elif platform.system() == "Windows":
36-
c_shared_library_file_name = "op_uniffi_core.dll"
37-
29+
# Map current platform to the correct shared library file name
30+
platform_to_lib = {
31+
"Darwin": "libop_uniffi_core.dylib",
32+
"Linux": "libop_uniffi_core.so",
33+
"Windows": "op_uniffi_core.dll"
34+
}
35+
c_shared_library_file_name = platform_to_lib.get(platform.system(), "")
3836
c_shared_library_file_name = os.path.join(include_path, c_shared_library_file_name)
3937

4038
uniffi_bindings_file_name = "op_uniffi_core.py"

src/onepassword/core.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
import platform
33

44

5-
if platform.machine().lower() == "x86_64" or platform.machine().lower() == "amd64":
5+
machine_arch = platform.machine().lower()
6+
7+
if machine_arch in ["x86_64", "amd64"]:
68
import onepassword.lib.x86_64.op_uniffi_core as core
7-
elif platform.machine().lower() == "aarch64" or platform.machine().lower() == "arm64":
9+
elif machine_arch in ["aarch64", "arm64"]:
810
import onepassword.lib.aarch64.op_uniffi_core as core
911
else:
10-
raise ImportError(
11-
"your machine's architecture is not currently supported: {}".format(
12-
platform.machine()
13-
)
14-
)
12+
raise ImportError(f"Your machine's architecture is not currently supported: {machine_arch}")
1513

1614

1715
# InitClient creates a client instance in the current core module and returns its unique ID.

0 commit comments

Comments
 (0)