-
Notifications
You must be signed in to change notification settings - Fork 0
/
importer.py
34 lines (28 loc) · 1.38 KB
/
importer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
This code was generated by OpenAI's GPT-3 model.
The code dynamically retrieves the directory of the currently running script,
uses that as the root folder, and iterates over each subdirectory in the root folder.
For each subdirectory, it checks if it contains a subdirectory that has an '__init__.py' file (a Python package).
If it does, the parent directory is added to sys.path, allowing Python to find and import modules from these packages.
"""
print(__file__)
import os
import sys
# Get the directory of the currently running script
root_folder = os.path.dirname(os.path.abspath(__file__))
# Iterate over all items in the root folder
for folder in os.listdir(root_folder):
folder_path = os.path.join(root_folder, folder)
# Check if the item is a directory
if os.path.isdir(folder_path):
# Iterate over all items in the subdirectory
for subfolder in os.listdir(folder_path):
subfolder_path = os.path.join(folder_path, subfolder)
# Check if the item is a directory and contains '__init__.py'
if os.path.isdir(subfolder_path) and "__init__.py" in os.listdir(
subfolder_path
):
# Add the parent directory (folder_path) to sys.path
sys.path.append(folder_path)
# We've found a valid package, no need to check the rest of this directory
break