Skip to content

Commit 92a69ad

Browse files
authored
[onert/python] Normalize file paths in setup.py (#15881)
This commit uses absolute path for DEFAULT_PRODUCT_DIR and uses `os.path.normpath()` for a more consistent path resolution. It includes finding correct library path - lib/, lib32/, lib64/. ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
1 parent 2d9458c commit 92a69ad

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

runtime/infra/python/setup.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
package_directory = 'onert'
99
packaging_directory = ['build', package_directory + '.egg-info']
1010
THIS_FILE_DIR = os.path.dirname(os.path.abspath(__file__))
11-
DEFAULT_PRODUCT_DIR = "../../../Product"
11+
DEFAULT_PRODUCT_DIR = os.path.normpath(os.path.join(THIS_FILE_DIR, "../../../Product"))
1212
so_list = []
1313
so_files = []
1414
target_arch = 'none'
@@ -51,7 +51,8 @@
5151
print(f"Created directory '{package_directory}'...")
5252

5353
# copy *py files to package_directory
54-
PY_DIR = os.path.join(THIS_FILE_DIR, '../../../runtime/onert/api/python/package')
54+
PY_DIR = os.path.normpath(
55+
os.path.join(THIS_FILE_DIR, '../../../runtime/onert/api/python/package'))
5556
for root, dirs, files in os.walk(PY_DIR):
5657
# Calculate the relative path from the source directory
5758
rel_path = os.path.relpath(root, PY_DIR)
@@ -85,12 +86,20 @@
8586
def get_directories():
8687
# If the environment variable is not set, get default one.
8788
product_dir = os.environ.get("PRODUCT_DIR", DEFAULT_PRODUCT_DIR)
88-
return os.path.join(THIS_FILE_DIR, product_dir), os.path.join(
89-
product_dir,
90-
"lib/" if product_dir != DEFAULT_PRODUCT_DIR else target_arch +
91-
'-linux.release/out/lib')
89+
base_dir = product_dir if product_dir != DEFAULT_PRODUCT_DIR else os.path.join(
90+
product_dir, target_arch + '-linux.release/out')
91+
92+
if os.path.exists(os.path.join(base_dir, "lib64")):
93+
return os.path.join(base_dir, "lib64")
94+
elif os.path.exists(os.path.join(base_dir, "lib32")):
95+
return os.path.join(base_dir, "lib32")
96+
elif os.path.exists(os.path.join(base_dir, "lib")):
97+
return os.path.join(base_dir, "lib")
98+
else:
99+
raise FileNotFoundError(f"No lib directory found in {base_dir}")
92100

93-
product_dir, so_base_dir = get_directories()
101+
so_base_dir = get_directories()
102+
print(f"so_base_dir '{so_base_dir}'")
94103

95104
for so in os.listdir(so_base_dir):
96105
if so.endswith(".so"):

0 commit comments

Comments
 (0)