File: conf.py

package info (click to toggle)
python-azure 20251014%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 766,472 kB
  • sloc: python: 6,314,744; ansic: 804; javascript: 287; makefile: 198; sh: 198; xml: 109
file content (60 lines) | stat: -rw-r--r-- 1,716 bytes parent folder | download
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
import logging
from pathlib import Path
from typing import Dict, Any

try:
    # py 311 adds this library natively
    import tomllib as toml
except:
    # otherwise fall back to pypi package tomli
    import tomli as toml
import tomli_w as tomlw

_LOGGER = logging.getLogger(__name__)

CONF_NAME = "pyproject.toml"
OLD_CONF_NAME = "sdk_packaging.toml"
_SECTION = "packaging"

# Default conf
_CONFIG = {
    "package_name": "packagename",
    "package_nspkg": "packagenspkg",
    "package_pprint_name": "MyService Management",
    "package_doc_id": "",
    "is_stable": False,
    "is_arm": True,
    "need_msrestazure": False,  # track2 does not need it anymore in setup.py
    "need_azuremgmtcore": True,
    "sample_link": "",
    "exclude_folders": "",
}


def read_conf(folder: Path) -> Dict[str, Any]:
    conf_path = folder / CONF_NAME
    if not conf_path.exists():
        return {}

    with open(conf_path, "rb") as fd:
        return toml.load(fd)[_SECTION]


def build_default_conf(folder: Path, package_name: str) -> None:
    conf_path = folder / CONF_NAME
    existing_conf = {_SECTION: {}}
    if conf_path.exists():
        with open(conf_path, "rb") as fd:
            existing_conf = toml.load(fd)
        if _SECTION not in existing_conf:
            existing_conf[_SECTION] = {}

    _LOGGER.info("Build default conf for %s", package_name)
    for k in _CONFIG:
        if k not in existing_conf[_SECTION]:
            existing_conf[_SECTION][k] = _CONFIG[k]
    existing_conf[_SECTION]["package_name"] = package_name
    existing_conf[_SECTION]["package_nspkg"] = package_name[: package_name.rindex("-")] + "-nspkg"

    with open(conf_path, "wb") as fd:
        tomlw.dump(existing_conf, fd)