Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
bd91a175
"tests/vscode:/vscode.git/clone" did not exist on "c9ca5c40321345513a21e937ef38a1b0205db641"
Unverified
Commit
bd91a175
authored
May 27, 2025
by
ishandhanani
Committed by
GitHub
May 27, 2025
Browse files
chore: fix loading logs in dynamo serve (#1213)
parent
030ceadf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
22 deletions
+21
-22
deploy/sdk/src/dynamo/sdk/cli/serve.py
deploy/sdk/src/dynamo/sdk/cli/serve.py
+0
-1
deploy/sdk/src/dynamo/sdk/cli/utils.py
deploy/sdk/src/dynamo/sdk/cli/utils.py
+1
-1
deploy/sdk/src/dynamo/sdk/lib/loader.py
deploy/sdk/src/dynamo/sdk/lib/loader.py
+20
-20
No files found.
deploy/sdk/src/dynamo/sdk/cli/serve.py
View file @
bd91a175
...
@@ -129,7 +129,6 @@ def serve(
...
@@ -129,7 +129,6 @@ def serve(
configure_dynamo_logging
()
configure_dynamo_logging
()
if
service_configs
:
if
service_configs
:
logger
.
info
(
f
"Running dynamo serve with service configs
{
service_configs
}
"
)
os
.
environ
[
"DYNAMO_SERVICE_CONFIG"
]
=
json
.
dumps
(
service_configs
)
os
.
environ
[
"DYNAMO_SERVICE_CONFIG"
]
=
json
.
dumps
(
service_configs
)
if
working_dir
is
None
:
if
working_dir
is
None
:
...
...
deploy/sdk/src/dynamo/sdk/cli/utils.py
View file @
bd91a175
...
@@ -356,7 +356,7 @@ def resolve_service_config(
...
@@ -356,7 +356,7 @@ def resolve_service_config(
for
key
,
value
in
configs
.
items
():
for
key
,
value
in
configs
.
items
():
service_configs
[
service
][
key
]
=
value
service_configs
[
service
][
key
]
=
value
logger
.
debug
(
f
"Final resolved
config:
{
service_configs
}
"
)
logger
.
info
(
f
"Running dynamo serve with
config:
{
service_configs
}
"
)
return
service_configs
return
service_configs
...
...
deploy/sdk/src/dynamo/sdk/lib/loader.py
View file @
bd91a175
...
@@ -54,8 +54,8 @@ def find_and_load_service(
...
@@ -54,8 +54,8 @@ def find_and_load_service(
ImportError: If module cannot be imported
ImportError: If module cannot be imported
ValueError: If service cannot be found or multiple root services exist
ValueError: If service cannot be found or multiple root services exist
"""
"""
logger
.
info
(
f
"Loading service from import string:
{
import_str
}
"
)
logger
.
debug
(
f
"Loading service from import string:
{
import_str
}
"
)
logger
.
info
(
f
"Working directory:
{
working_dir
or
os
.
getcwd
()
}
"
)
logger
.
debug
(
f
"Working directory:
{
working_dir
or
os
.
getcwd
()
}
"
)
sys_path_modified
=
False
sys_path_modified
=
False
prev_cwd
=
None
prev_cwd
=
None
...
@@ -63,13 +63,13 @@ def find_and_load_service(
...
@@ -63,13 +63,13 @@ def find_and_load_service(
if
working_dir
is
not
None
:
if
working_dir
is
not
None
:
prev_cwd
=
os
.
getcwd
()
prev_cwd
=
os
.
getcwd
()
working_dir
=
os
.
path
.
realpath
(
os
.
path
.
expanduser
(
working_dir
))
working_dir
=
os
.
path
.
realpath
(
os
.
path
.
expanduser
(
working_dir
))
logger
.
info
(
f
"Changing working directory to:
{
working_dir
}
"
)
logger
.
debug
(
f
"Changing working directory to:
{
working_dir
}
"
)
os
.
chdir
(
working_dir
)
os
.
chdir
(
working_dir
)
else
:
else
:
working_dir
=
os
.
getcwd
()
working_dir
=
os
.
getcwd
()
if
working_dir
not
in
sys
.
path
:
if
working_dir
not
in
sys
.
path
:
logger
.
info
(
f
"Adding
{
working_dir
}
to sys.path"
)
logger
.
debug
(
f
"Adding
{
working_dir
}
to sys.path"
)
sys
.
path
.
insert
(
0
,
working_dir
)
sys
.
path
.
insert
(
0
,
working_dir
)
sys_path_modified
=
True
sys_path_modified
=
True
...
@@ -77,17 +77,17 @@ def find_and_load_service(
...
@@ -77,17 +77,17 @@ def find_and_load_service(
return
_do_import
(
import_str
,
working_dir
)
return
_do_import
(
import_str
,
working_dir
)
finally
:
finally
:
if
sys_path_modified
and
working_dir
:
if
sys_path_modified
and
working_dir
:
logger
.
info
(
f
"Removing
{
working_dir
}
from sys.path"
)
logger
.
debug
(
f
"Removing
{
working_dir
}
from sys.path"
)
sys
.
path
.
remove
(
working_dir
)
sys
.
path
.
remove
(
working_dir
)
if
prev_cwd
is
not
None
:
if
prev_cwd
is
not
None
:
logger
.
info
(
f
"Restoring working directory to:
{
prev_cwd
}
"
)
logger
.
debug
(
f
"Restoring working directory to:
{
prev_cwd
}
"
)
os
.
chdir
(
prev_cwd
)
os
.
chdir
(
prev_cwd
)
def
_do_import
(
import_str
:
str
,
working_dir
:
str
)
->
DynamoService
:
def
_do_import
(
import_str
:
str
,
working_dir
:
str
)
->
DynamoService
:
"""Internal function to handle the actual import logic"""
"""Internal function to handle the actual import logic"""
import_path
,
_
,
attrs_str
=
import_str
.
partition
(
":"
)
import_path
,
_
,
attrs_str
=
import_str
.
partition
(
":"
)
logger
.
info
(
f
"Parsed import string - path:
{
import_path
}
, attributes:
{
attrs_str
}
"
)
logger
.
debug
(
f
"Parsed import string - path:
{
import_path
}
, attributes:
{
attrs_str
}
"
)
if
not
import_path
:
if
not
import_path
:
raise
ValueError
(
raise
ValueError
(
...
@@ -97,7 +97,7 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
...
@@ -97,7 +97,7 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
# Handle file path vs module name imports
# Handle file path vs module name imports
if
os
.
path
.
isfile
(
import_path
):
if
os
.
path
.
isfile
(
import_path
):
logger
.
info
(
f
"Importing from file path:
{
import_path
}
"
)
logger
.
debug
(
f
"Importing from file path:
{
import_path
}
"
)
import_path
=
os
.
path
.
realpath
(
import_path
)
import_path
=
os
.
path
.
realpath
(
import_path
)
if
not
import_path
.
startswith
(
working_dir
):
if
not
import_path
.
startswith
(
working_dir
):
raise
ImportError
(
raise
ImportError
(
...
@@ -122,26 +122,26 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
...
@@ -122,26 +122,26 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
):
):
break
break
module_name
=
"."
.
join
(
module_parts
[::
-
1
])
module_name
=
"."
.
join
(
module_parts
[::
-
1
])
logger
.
info
(
f
"Constructed module name from path:
{
module_name
}
"
)
logger
.
debug
(
f
"Constructed module name from path:
{
module_name
}
"
)
else
:
else
:
logger
.
info
(
f
"Importing from module name:
{
import_path
}
"
)
logger
.
debug
(
f
"Importing from module name:
{
import_path
}
"
)
module_name
=
import_path
module_name
=
import_path
try
:
try
:
logger
.
info
(
f
"Attempting to import module:
{
module_name
}
"
)
logger
.
debug
(
f
"Attempting to import module:
{
module_name
}
"
)
module
=
importlib
.
import_module
(
module_name
)
module
=
importlib
.
import_module
(
module_name
)
except
ImportError
as
e
:
except
ImportError
as
e
:
raise
ImportError
(
f
'Failed to import module "
{
module_name
}
":
{
e
}
'
)
raise
ImportError
(
f
'Failed to import module "
{
module_name
}
":
{
e
}
'
)
# If no specific attribute given, find the root service
# If no specific attribute given, find the root service
if
not
attrs_str
:
if
not
attrs_str
:
logger
.
info
(
"No attributes specified, searching for root service"
)
logger
.
debug
(
"No attributes specified, searching for root service"
)
services
=
[
services
=
[
(
name
,
obj
)
(
name
,
obj
)
for
name
,
obj
in
module
.
__dict__
.
items
()
for
name
,
obj
in
module
.
__dict__
.
items
()
if
isinstance
(
obj
,
DynamoService
)
if
isinstance
(
obj
,
DynamoService
)
]
]
logger
.
info
(
f
"Found
{
len
(
services
)
}
DynamoService instances"
)
logger
.
debug
(
f
"Found
{
len
(
services
)
}
DynamoService instances"
)
if
not
services
:
if
not
services
:
raise
ValueError
(
raise
ValueError
(
...
@@ -156,7 +156,7 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
...
@@ -156,7 +156,7 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
dependents
.
add
(
dep
.
on
)
dependents
.
add
(
dep
.
on
)
root_services
=
[(
n
,
s
)
for
n
,
s
in
services
if
s
not
in
dependents
]
root_services
=
[(
n
,
s
)
for
n
,
s
in
services
if
s
not
in
dependents
]
logger
.
info
(
f
"Found
{
len
(
root_services
)
}
root services"
)
logger
.
debug
(
f
"Found
{
len
(
root_services
)
}
root services"
)
if
not
root_services
:
if
not
root_services
:
raise
ValueError
(
raise
ValueError
(
...
@@ -171,18 +171,18 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
...
@@ -171,18 +171,18 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
)
)
_
,
instance
=
root_services
[
0
]
_
,
instance
=
root_services
[
0
]
logger
.
info
(
f
"Selected root service:
{
instance
}
"
)
logger
.
debug
(
f
"Selected root service:
{
instance
}
"
)
else
:
else
:
# Navigate through dot-separated attributes
# Navigate through dot-separated attributes
logger
.
info
(
f
"Navigating attributes:
{
attrs_str
}
"
)
logger
.
debug
(
f
"Navigating attributes:
{
attrs_str
}
"
)
instance
=
module
instance
=
module
for
attr
in
attrs_str
.
split
(
"."
):
for
attr
in
attrs_str
.
split
(
"."
):
try
:
try
:
if
isinstance
(
instance
,
DynamoService
):
if
isinstance
(
instance
,
DynamoService
):
logger
.
info
(
f
"Following dependency link:
{
attr
}
"
)
logger
.
debug
(
f
"Following dependency link:
{
attr
}
"
)
instance
=
instance
.
dependencies
[
attr
].
on
instance
=
instance
.
dependencies
[
attr
].
on
else
:
else
:
logger
.
info
(
f
"Getting attribute:
{
attr
}
"
)
logger
.
debug
(
f
"Getting attribute:
{
attr
}
"
)
instance
=
getattr
(
instance
,
attr
)
instance
=
getattr
(
instance
,
attr
)
except
(
AttributeError
,
KeyError
):
except
(
AttributeError
,
KeyError
):
raise
ValueError
(
f
'Attribute "
{
attr
}
" not found in "
{
module_name
}
"'
)
raise
ValueError
(
f
'Attribute "
{
attr
}
" not found in "
{
module_name
}
"'
)
...
@@ -190,7 +190,7 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
...
@@ -190,7 +190,7 @@ def _do_import(import_str: str, working_dir: str) -> DynamoService:
# Set import string for debugging/logging
# Set import string for debugging/logging
if
not
hasattr
(
instance
,
"_import_str"
):
if
not
hasattr
(
instance
,
"_import_str"
):
import_str_val
=
f
"
{
module_name
}
:
{
attrs_str
}
"
if
attrs_str
else
module_name
import_str_val
=
f
"
{
module_name
}
:
{
attrs_str
}
"
if
attrs_str
else
module_name
logger
.
info
(
f
"Setting _import_str to:
{
import_str_val
}
"
)
logger
.
debug
(
f
"Setting _import_str to:
{
import_str_val
}
"
)
object
.
__setattr__
(
instance
,
"_import_str"
,
import_str_val
)
object
.
__setattr__
(
instance
,
"_import_str"
,
import_str_val
)
return
instance
return
instance
...
@@ -203,7 +203,7 @@ def _get_dir_size(path: str) -> int:
...
@@ -203,7 +203,7 @@ def _get_dir_size(path: str) -> int:
fp
=
os
.
path
.
join
(
dirpath
,
f
)
fp
=
os
.
path
.
join
(
dirpath
,
f
)
if
os
.
path
.
isfile
(
fp
):
if
os
.
path
.
isfile
(
fp
):
total
+=
os
.
path
.
getsize
(
fp
)
total
+=
os
.
path
.
getsize
(
fp
)
logger
.
info
(
f
"Total size of
{
path
}
:
{
total
}
bytes"
)
logger
.
debug
(
f
"Total size of
{
path
}
:
{
total
}
bytes"
)
return
total
return
total
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment