Unverified Commit c5a1ff9e authored by Zach Nussbaum's avatar Zach Nussbaum Committed by GitHub
Browse files

feat: filter try/except when looking at custom code (#21914)



* feat: filter try/except

* Update src/transformers/dynamic_module_utils.py
Co-authored-by: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>

---------
Co-authored-by: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>
parent 02a77fa0
...@@ -116,6 +116,9 @@ def check_imports(filename): ...@@ -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`
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment