|
|
import os |
|
|
import importlib.util |
|
|
import sys |
|
|
|
|
|
def test_imports(directories): |
|
|
""" |
|
|
Test importing all Python files in the specified directories. |
|
|
|
|
|
Parameters: |
|
|
- directories: List of directory paths to test. |
|
|
""" |
|
|
print("Testing Conda environment...") |
|
|
|
|
|
for directory in directories: |
|
|
print(f"\nChecking directory: {directory}") |
|
|
|
|
|
|
|
|
if not os.path.isdir(directory): |
|
|
print(f"Directory not found: {directory}") |
|
|
continue |
|
|
|
|
|
|
|
|
for filename in os.listdir(directory): |
|
|
|
|
|
if filename.endswith(".py"): |
|
|
filepath = os.path.join(directory, filename) |
|
|
module_name = os.path.splitext(filename)[0] |
|
|
|
|
|
try: |
|
|
|
|
|
spec = importlib.util.spec_from_file_location(module_name, filepath) |
|
|
module = importlib.util.module_from_spec(spec) |
|
|
spec.loader.exec_module(module) |
|
|
print(f"Successfully imported: {filepath}") |
|
|
except Exception as e: |
|
|
|
|
|
print(f"Failed to import: {filepath}") |
|
|
print(f"Error: {e}") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
current_directory = os.getcwd() |
|
|
sys.path.append(current_directory) |
|
|
print(f"Current directory added to sys.path: {current_directory}") |
|
|
|
|
|
|
|
|
directories = ["scripts", "root_gnn_base", "models"] |
|
|
test_imports(directories) |