Skip to content

Commit

Permalink
More efficient listdir
Browse files Browse the repository at this point in the history
  • Loading branch information
LysandreJik committed Jul 26, 2024
1 parent 84b5e03 commit 5d76ab7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/transformers/models/speech_to_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,4 @@

else:
import sys
print(type(__spec__))

sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
14 changes: 10 additions & 4 deletions src/transformers/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,14 +1813,20 @@ def create_import_structure_from_path(module_path):
"""
import_structure = {}
if os.path.isdir(module_path):

directory = module_path
adjacent_modules = []

for f in os.listdir(module_path):
if f != "__pycache__" and os.path.isdir(os.path.join(module_path, f)):
import_structure[f] = define_import_structure(os.path.join(module_path, f))
directory = module_path
import_structure[f] = create_import_structure_from_path(os.path.join(module_path, f))

elif not os.path.isdir(os.path.join(directory, f)):
adjacent_modules.append(f)

else:
directory = os.path.dirname(module_path)

adjacent_modules = [f for f in os.listdir(directory) if not os.path.isdir(os.path.join(directory, f))]
adjacent_modules = [f for f in os.listdir(directory) if not os.path.isdir(os.path.join(directory, f))]

# We're only taking a look at files different from __init__.py
# We could theoretically export things directly from the __init__.py
Expand Down

0 comments on commit 5d76ab7

Please sign in to comment.