Skip to content

Commit 57b673c

Browse files
authored
Fix CLI import_submodules to work with pyenv (#788)
Add sys.path.insert(0, os.getcwd()) to import_submodules() so that modules can be found when using pyenv or similar tools where Python binaries are stored outside the project directory. Fixes #682
1 parent d7e67e1 commit 57b673c

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

aredis_om/model/migrations/schema/legacy_migrator.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import redis
2020

21-
2221
log = logging.getLogger(__name__)
2322

2423

@@ -29,7 +28,21 @@ class MigrationError(Exception):
2928

3029

3130
def import_submodules(root_module_name: str):
32-
"""Import all submodules of a module, recursively."""
31+
"""Import all submodules of a module, recursively.
32+
33+
This function adds the current working directory to sys.path to ensure
34+
that modules can be imported when using tools like pyenv where the Python
35+
binaries are stored outside the project directory.
36+
"""
37+
import os
38+
import sys
39+
40+
# Add cwd to sys.path so modules can be found when using pyenv or similar
41+
# tools where Python binaries are stored outside the project directory.
42+
cwd = os.getcwd()
43+
if cwd not in sys.path:
44+
sys.path.insert(0, cwd)
45+
3346
root_module = importlib.import_module(root_module_name)
3447

3548
if not hasattr(root_module, "__path__"):

0 commit comments

Comments
 (0)