Add library for writing toml files
This commit is contained in:
parent
afb98a5fea
commit
60d428e388
@ -7,6 +7,7 @@ try:
|
|||||||
import tomllib
|
import tomllib
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
import tomli as tomllib
|
import tomli as tomllib
|
||||||
|
import tomli_w
|
||||||
|
|
||||||
|
|
||||||
__version__ = '0.3.0'
|
__version__ = '0.3.0'
|
||||||
@ -317,39 +318,77 @@ def load_pyproject_toml(dirname, maxdepth=3, filename='pyproject.toml'):
|
|||||||
return {}
|
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 write_pyproject_toml(path):
|
def write_pyproject_toml(path):
|
||||||
|
if os.path.exists(path):
|
||||||
|
with open(path, "rb") as f:
|
||||||
|
config = tomli.load(f)
|
||||||
|
else:
|
||||||
|
config = {
|
||||||
|
"build-system": {
|
||||||
|
"requires": ["flit_core >=3.2,<4"],
|
||||||
|
"build-backend": "flit_core.buildapi",
|
||||||
|
},
|
||||||
|
"project": {
|
||||||
|
"name": "",
|
||||||
|
"authors": [],
|
||||||
|
"dynamic": ["version", "description"],
|
||||||
|
"dependencies": ["magicli"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
config = {
|
if not 'name' in config['project'] or not config['project']['name']:
|
||||||
'Module name': '',
|
config['project']['name'] = input('Module name: ')
|
||||||
'Author': '',
|
|
||||||
'Author email': '',
|
|
||||||
'CLI command': '',
|
|
||||||
'CLI path': '',
|
|
||||||
}
|
|
||||||
|
|
||||||
for key in config.keys():
|
if not 'authors' in config['project'] or not config['project']['authors']:
|
||||||
config[key] = input(f"{key}: ")
|
author = input('Author: ')
|
||||||
|
email = input('Author email: ')
|
||||||
|
config['project']['authors'] = [{"author": author, "email": email}]
|
||||||
|
|
||||||
|
if not 'scripts' in config['project']:
|
||||||
|
config['project']['scripts'] = {}
|
||||||
|
|
||||||
author_and_email = '{name = "' + config['Author'] + '", email = "' + config['Author email'] + '"}'
|
if not config['project']['scripts']:
|
||||||
|
cli_name = input('CLI name: ')
|
||||||
|
cli_path = input('CLI path: ')
|
||||||
|
config['project']['scripts'][cli_name] = cli_path
|
||||||
|
|
||||||
with open(path, 'w') as f:
|
with open(path, 'wb') as f:
|
||||||
f.write(f"""\
|
tomli_w.dump(config, 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():
|
def first_calling_frame():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user