File: update_pyproject_toml.py

package info (click to toggle)
colmap 3.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,192 kB
  • sloc: cpp: 106,194; ansic: 17,774; python: 4,564; sh: 393; makefile: 159
file content (41 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download | duplicates (2)
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
import argparse
from pathlib import Path

import tomlkit

# Set up command-line argument parser
parser = argparse.ArgumentParser(
    description="Modify pyproject.toml for a custom build."
)
parser.add_argument(
    "--name", required=True, help="The new package name for the wheel."
)
parser.add_argument(
    "--add-deps",
    nargs="+",
    default=[],
    help="Space-separated list of Python dependencies to add.",
)
args = parser.parse_args()

# Modify the pyproject.toml file
pyproject_path = Path("pyproject.toml")
if not pyproject_path.exists():
    raise FileNotFoundError(pyproject_path)

with open(pyproject_path, encoding="utf-8") as f:
    config = tomlkit.load(f)

config["project"]["name"] = args.name

if args.add_deps:
    if "dependencies" not in config["project"]:
        config["project"]["dependencies"] = []

    existing_deps = config["project"]["dependencies"]
    for req in args.add_deps:
        if req not in existing_deps:
            existing_deps.append(req)

with open(pyproject_path, "w", encoding="utf-8") as f:
    tomlkit.dump(config, f)