Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICV-mmengine_basecode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Schiffel
ICV-mmengine_basecode
Commits
9868131c
Unverified
Commit
9868131c
authored
1 year ago
by
Mashiro
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
[Enhance] Enhance error message during custom import (#1102)
parent
1c01594c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mmengine/config/config.py
+10
-1
10 additions, 1 deletion
mmengine/config/config.py
tests/test_config/test_config.py
+6
-0
6 additions, 0 deletions
tests/test_config/test_config.py
with
16 additions
and
1 deletion
mmengine/config/config.py
+
10
−
1
View file @
9868131c
...
@@ -5,6 +5,7 @@ import os
...
@@ -5,6 +5,7 @@ import os
import
os.path
as
osp
import
os.path
as
osp
import
platform
import
platform
import
shutil
import
shutil
import
sys
import
tempfile
import
tempfile
import
types
import
types
import
uuid
import
uuid
...
@@ -180,7 +181,15 @@ class Config:
...
@@ -180,7 +181,15 @@ class Config:
try
:
try
:
import_modules_from_strings
(
**
cfg_dict
[
'
custom_imports
'
])
import_modules_from_strings
(
**
cfg_dict
[
'
custom_imports
'
])
except
ImportError
as
e
:
except
ImportError
as
e
:
raise
ImportError
(
'
Failed to custom import!
'
)
from
e
err_msg
=
(
'
Failed to import custom modules from
'
f
"
{
cfg_dict
[
'
custom_imports
'
]
}
, the current sys.path is:
"
)
for
p
in
sys
.
path
:
err_msg
+=
f
'
\n
{
p
}
'
err_msg
+=
(
'
\n
You should set `PYTHONPATH` to make `sys.path` include
'
'
the directory which contains your custom module
'
)
raise
ImportError
(
err_msg
)
from
e
return
Config
(
return
Config
(
cfg_dict
,
cfg_dict
,
cfg_text
=
cfg_text
,
cfg_text
=
cfg_text
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_config/test_config.py
+
6
−
0
View file @
9868131c
...
@@ -65,8 +65,14 @@ class TestConfig:
...
@@ -65,8 +65,14 @@ class TestConfig:
# If import successfully, os.environ[''TEST_VALUE''] will be
# If import successfully, os.environ[''TEST_VALUE''] will be
# set to 'test'
# set to 'test'
assert
os
.
environ
.
pop
(
'
TEST_VALUE
'
)
==
'
test
'
assert
os
.
environ
.
pop
(
'
TEST_VALUE
'
)
==
'
test
'
sys
.
path
.
pop
()
Config
.
fromfile
(
cfg_file
,
import_custom_modules
=
False
)
Config
.
fromfile
(
cfg_file
,
import_custom_modules
=
False
)
assert
'
TEST_VALUE
'
not
in
os
.
environ
assert
'
TEST_VALUE
'
not
in
os
.
environ
sys
.
modules
.
pop
(
'
test_custom_import_module
'
)
with
pytest
.
raises
(
ImportError
,
match
=
'
Failed to import custom modules from
'
):
Config
.
fromfile
(
cfg_file
,
import_custom_modules
=
True
)
@pytest.mark.parametrize
(
'
file_format
'
,
[
'
py
'
,
'
json
'
,
'
yaml
'
])
@pytest.mark.parametrize
(
'
file_format
'
,
[
'
py
'
,
'
json
'
,
'
yaml
'
])
def
test_fromstring
(
self
,
file_format
):
def
test_fromstring
(
self
,
file_format
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment