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