feat: filter try/except when looking at custom code (#21914)
* feat: filter try/except * Update src/transformers/dynamic_module_utils.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> --------- Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
This commit is contained in:
@@ -116,6 +116,9 @@ def check_imports(filename):
|
|||||||
with open(filename, "r", encoding="utf-8") as f:
|
with open(filename, "r", encoding="utf-8") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
|
# filter out try/except block so in custom code we can have try/except imports
|
||||||
|
content = re.sub(r"\s*try\s*:\s*.*?\s*except\s*:", "", content, flags=re.MULTILINE)
|
||||||
|
|
||||||
# Imports of the form `import xxx`
|
# Imports of the form `import xxx`
|
||||||
imports = re.findall(r"^\s*import\s+(\S+)\s*$", content, flags=re.MULTILINE)
|
imports = re.findall(r"^\s*import\s+(\S+)\s*$", content, flags=re.MULTILINE)
|
||||||
# Imports of the form `from xxx import yyy`
|
# Imports of the form `from xxx import yyy`
|
||||||
|
|||||||
Reference in New Issue
Block a user