Add loader for pyproject.toml

This commit is contained in:
Patrick Elmer 2024-03-10 09:02:49 +01:00
parent 68bbefea52
commit 3f1ff5404f

View File

@ -298,6 +298,21 @@ def break_lines(lines, width):
return result
def load_pyproject_toml(dirname, maxdepth=3, filename='pyproject.toml'):
"""Find and load pyproject.toml of current project."""
for _ in range(maxdepth):
if filename in os.listdir(dirname):
with open(os.path.join(dirname, filename), 'rb') as f:
config = tomllib.load(f)
return config.get('tool', {}).get('magicli', {})
# Go to parent directory
dirname = os.path.abspath(os.path.join(dirname, os.pardir))
return {}
def first_calling_frame():
for s in reversed(inspect.stack()):
if s.code_context == None: