You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
prepend_sys_path does not work with absolute paths on windows #1330
If you put an absolute path in prepend_sys_path in your alembic.ini on windows (which will happen if you use %(here)s), the path will get split on the ':' character that separates the drive letter.
Expected behavior
Absolute paths to not get broken.
To Reproduce
Use an absolute path in prepend_sys_path like C:/something or %(here)s/something
Then print out sys.path, e.g. for path in sys.path: print(path) you get:
C
\something
C
\path\to\here\something
# Insert code here
Error ModuleNotFoundError: No module named ...
because env.py can't import my modules.
Proposed in #1331 we add a new config value with legacy fallback behavior as follows:
# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory. for multiple paths, the path separator
# is defined by prepend_sys_path_separator
prepend_sys_path = .
# prepend sys path separator; As mentioned above, this is the character used to split
# sys_path paths. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for prepend_sys_path_separator are:
#
# prepend_sys_path_separator = :
# prepend_sys_path_separator = ;
# prepend_sys_path_separator = space
prepend_sys_path_separator = os # Use os.pathsep. Default configuration used for new projects.
Activity
zzzeek commentedon Oct 19, 2023
@CaselIT is this also #1284 ?
zzzeek commentedon Oct 19, 2023
PRs with tests welcome here
Improve handling of prepend_sys_path
CaselIT commentedon Oct 19, 2023
it should not, since that depend on the value of
version_path_separatorzzzeek commentedon Oct 19, 2023
Proposed in #1331 we add a new config value with legacy fallback behavior as follows:
CaselIT commentedon Oct 19, 2023
it's probably the most sensible option. it makes little sense to have the two paths in the config handled in a different way
zzzeek commentedon Oct 19, 2023
I guess if we were on pyproject.toml this whole thing would be a non issue since it supports lists :)
CaselIT commentedon Oct 19, 2023
does not support
%(here)sthoughImprove handling of prepend_sys_path
sqla-tester commentedon Apr 26, 2025
Mike Werezak has proposed a fix for this issue in the main branch:
Improve handling of prepend_sys_path, fixes #1330 https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5873
Add file_path_separator to apply to all path splitting