Skip to content

Commit 754ce31

Browse files
committed
feat: enhance migration settings module documentation with best practices and common mistakes
1 parent 3e23865 commit 754ce31

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

src/iop/migration/utils.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,19 @@ def _build_migration_manifest(
546546

547547

548548
def _load_settings(filename):
549-
"""Load settings module from file or default location.
549+
"""Load a migration settings module.
550+
551+
Purpose:
552+
Resolve settings.py as a file-based module and keep imports local to the
553+
settings file directory for this process.
554+
555+
Best practices:
556+
Keep modules imported by settings.py in the same project/package rooted
557+
near the settings file. Let IoP manage temporary import path setup.
558+
559+
Common mistakes:
560+
Do not require users to set PYTHONPATH. Do not mutate environment
561+
variables to force imports when module/package layout should be fixed.
550562
551563
Returns:
552564
tuple: (settings_module, path_added_to_sys)
@@ -723,6 +735,20 @@ def _cleanup_sys_path(path):
723735

724736

725737
def import_module_from_path(module_name, file_path):
738+
"""Import one module from an absolute file path.
739+
740+
Purpose:
741+
Execute a specific settings or component module by file location
742+
without relying on global PYTHONPATH configuration.
743+
744+
Best practices:
745+
Use absolute paths and stable module/package layout so imports resolve
746+
from the project directory containing settings.py.
747+
748+
Common mistakes:
749+
Do not patch PYTHONPATH or sys.path globally to make imports pass.
750+
Keep import fixes in project structure and import statements.
751+
"""
726752
if not os.path.isabs(file_path):
727753
raise ValueError("The file path must be absolute")
728754

0 commit comments

Comments
 (0)