修复 database_config 加载环境变量路径错误问题 (target: learn_version)#101
Open
Zi-Lan-Cui wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
当前的修复版本依赖每次用户手动在文件最开始手动加载
这种方式不太方便。实际上
dotenv提供了修改默认env位置的方法find_dotenv( ),该方法在load_dotenv注释中被官方提及只需要设置
usecwd=True即可实现自动加载工作目录同级的.env文件。该方案更加优雅且通用。修复
使用
dotenv官方推荐的find_dotenv(usecwd=True)从当前工作目录向上查找.env文件,替代无参load_dotenv()。该方案:额外说明
该改动增强了现有的保底策略。如果想要用户完全不需手动加载。可以将
semantic.py中的get_database_config导入提升到模块级。该方案我已经在本地多次测试,运行无误。希望意见能被采纳