Debian Codegraph @

python/ci/update_pyproject_toml.py

raw
1 import argparse
2 from pathlib import Path
3
4 import tomlkit
5
6 # Set up command-line argument parser
7 parser = argparse.ArgumentParser(
8 description="Modify pyproject.toml for a custom build."
9 )
10 parser.add_argument(
11 "--name", required=True, help="The new package name for the wheel."
12 )
13 parser.add_argument(
14 "--add-deps",
15 nargs="+",
16 default=[],
17 help="Space-separated list of Python dependencies to add.",
18 )
19 args = parser.parse_args()
20
21 # Modify the pyproject.toml file
22 pyproject_path = Path("pyproject.toml")
23 if not pyproject_path.exists():
24 raise FileNotFoundError(pyproject_path)
25
26 with open(pyproject_path, encoding="utf-8") as f:
27 config = tomlkit.load(f)
28
29 config["project"]["name"] = args.name
30
31 if args.add_deps:
32 if "dependencies" not in config["project"]:
33 config["project"]["dependencies"] = []
34
35 existing_deps = config["project"]["dependencies"]
36 for req in args.add_deps:
37 if req not in existing_deps:
38 existing_deps.append(req)
39
40 with open(pyproject_path, "w", encoding="utf-8") as f:
41 tomlkit.dump(config, f)