Skip to content

Commit 0ef3710

Browse files
committed
feat: move set_pytho_path function from command.py
Signed-off-by: ImMin5 <[email protected]> (cherry picked from commit c8a58a0)
1 parent be92b5e commit 0ef3710

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/spaceone/core/utils.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import os
12
import re
23
import time
34
import random
45
import string
56
import secrets
7+
import sys
68
import datetime
7-
from urllib.parse import urlparse
89
import yaml
910
import json
1011
import hashlib
1112
import urllib
13+
import pkg_resources
14+
15+
from urllib.parse import urlparse
1216
from dateutil.parser import isoparse
1317
from typing import Tuple
1418
from pathlib import Path
@@ -494,5 +498,26 @@ def change_dict_with_dot_notation(dict_value: dict, key='', dots=None) -> dict:
494498
return dots
495499

496500

501+
def set_python_path(package, module_path):
502+
current_path = os.getcwd()
503+
504+
if current_path not in sys.path:
505+
sys.path.insert(0, current_path)
506+
507+
if isinstance(module_path, tuple):
508+
for path in module_path:
509+
if path not in sys.path:
510+
sys.path.insert(0, path)
511+
512+
if '.' in package:
513+
pkg_resources.declare_namespace(package)
514+
515+
try:
516+
__import__(package)
517+
except Exception:
518+
raise Exception(f'The package({package}) can not imported. '
519+
'Please check the module path.')
520+
521+
497522
if __name__ == '__main__':
498523
pass

0 commit comments

Comments
 (0)