-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoml.py
More file actions
68 lines (54 loc) · 2.02 KB
/
Copy pathtoml.py
File metadata and controls
68 lines (54 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""The module is used to update the 'pyproject.toml' file with the provided command line arguments."""
import argparse
import sys
import tomlkit
def get_dict() -> dict | None:
"""Get the 'pyproject.toml' file as a dictionary."""
with open("pyproject.toml", "r") as file:
data = tomlkit.loads(file.read())
try:
return data
except KeyError:
return None
def update_toml(
name: str, version: str, description: str, repository: str, license: str
) -> None:
"""Update the 'pyproject.toml' file with the provided parameters.
Args:
----
name (str): The name of the project
version (str): The version of the project
description (str): A short description of the project
repository (str): The URL of the project's repository
license (str): The license of the project
Returns:
-------
None
"""
with open("pyproject.toml", "r") as file:
data = tomlkit.loads(file.read())
if name:
data["tool"]["poetry"]["name"] = name
if version:
data["tool"]["poetry"]["version"] = version
if description:
data["tool"]["poetry"]["description"] = description
if repository:
data["tool"]["poetry"]["repository"] = repository
if license:
data["tool"]["poetry"]["license"] = license
with open("pyproject.toml", "w") as file:
file.write(tomlkit.dumps(data))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--name", help="The name of project")
parser.add_argument("--ver", help="The version of the project")
parser.add_argument("--desc", help="A short description of the project")
parser.add_argument("--repo", help="The URL of the project's repository")
parser.add_argument("--lic", help="The license of the project")
args = parser.parse_args()
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
else:
update_toml(args.name, args.ver, args.desc, args.repo, args.lic)