From afb98a5feacd690485ddf2e06b064f3702850a16 Mon Sep 17 00:00:00 2001 From: Patrick Elmer Date: Sun, 10 Mar 2024 09:39:44 +0100 Subject: [PATCH] Add simple implementation for writing pyproject.toml --- magicli/magicli.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/magicli/magicli.py b/magicli/magicli.py index 9669ee5..2dfef82 100644 --- a/magicli/magicli.py +++ b/magicli/magicli.py @@ -317,6 +317,41 @@ def load_pyproject_toml(dirname, maxdepth=3, filename='pyproject.toml'): return {} +def write_pyproject_toml(path): + + config = { + 'Module name': '', + 'Author': '', + 'Author email': '', + 'CLI command': '', + 'CLI path': '', + } + + for key in config.keys(): + config[key] = input(f"{key}: ") + + author_and_email = '{name = "' + config['Author'] + '", email = "' + config['Author email'] + '"}' + + with open(path, 'w') as f: + f.write(f"""\ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "{config['Module name']}" +authors = [{author_and_email}] +dynamic = ["version", "description"] +dependencies = ["magicli"] + +[project.scripts] +{config['CLI command']} = "{config['CLI path']}" + +[tool.magicli] +test = "test" +""") + + def first_calling_frame(): for s in reversed(inspect.stack()): if s.code_context == None: