2018-09-02 21:48:12 +02:00
|
|
|
# This file is part of the pycalver project
|
|
|
|
|
# https://github.com/mbarkhau/pycalver
|
|
|
|
|
#
|
2018-11-06 21:45:33 +01:00
|
|
|
# Copyright (c) 2018 Manuel Barkhau (@mbarkhau) - MIT License
|
2018-09-02 21:48:12 +02:00
|
|
|
# SPDX-License-Identifier: MIT
|
2018-11-15 22:16:16 +01:00
|
|
|
"""Parse setup.cfg or pycalver.cfg files."""
|
2018-09-02 21:48:12 +02:00
|
|
|
|
|
|
|
|
import io
|
|
|
|
|
import os
|
2018-12-09 15:57:04 +01:00
|
|
|
import six
|
2018-12-05 09:38:27 +01:00
|
|
|
import toml
|
2018-09-02 21:48:12 +02:00
|
|
|
import configparser
|
|
|
|
|
import typing as typ
|
2018-12-05 09:38:27 +01:00
|
|
|
import pathlib2 as pl
|
2018-09-02 21:48:12 +02:00
|
|
|
import datetime as dt
|
|
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
from . import version
|
2018-09-02 21:48:12 +02:00
|
|
|
|
|
|
|
|
log = logging.getLogger("pycalver.config")
|
|
|
|
|
|
2018-11-15 22:16:16 +01:00
|
|
|
PatternsByFilePath = typ.Dict[str, typ.List[str]]
|
|
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
SUPPORTED_CONFIGS = ["setup.cfg", "pyproject.toml", "pycalver.toml"]
|
|
|
|
|
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
class ProjectContext(typ.NamedTuple):
|
|
|
|
|
"""Container class for project info."""
|
|
|
|
|
|
|
|
|
|
path : pl.Path
|
|
|
|
|
config_filepath: pl.Path
|
|
|
|
|
config_format : str
|
|
|
|
|
vcs_type : typ.Optional[str]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_project_ctx(project_path: typ.Union[str, pl.Path, None] = ".") -> ProjectContext:
|
|
|
|
|
"""Initialize ProjectContext from a path."""
|
2018-12-09 15:57:04 +01:00
|
|
|
if isinstance(project_path, pl.Path):
|
2018-12-05 09:38:27 +01:00
|
|
|
path = project_path
|
2018-12-09 15:57:04 +01:00
|
|
|
elif project_path is None:
|
|
|
|
|
path = pl.Path(".")
|
|
|
|
|
else:
|
|
|
|
|
# assume it's a str/unicode
|
|
|
|
|
path = pl.Path(project_path)
|
2018-12-05 09:38:27 +01:00
|
|
|
|
|
|
|
|
if (path / "pyproject.toml").exists():
|
|
|
|
|
config_filepath = path / "pyproject.toml"
|
|
|
|
|
config_format = 'toml'
|
|
|
|
|
if (path / "setup.cfg").exists():
|
|
|
|
|
config_filepath = path / "setup.cfg"
|
|
|
|
|
config_format = 'cfg'
|
|
|
|
|
else:
|
|
|
|
|
config_filepath = path / "pycalver.toml"
|
|
|
|
|
config_format = 'toml'
|
|
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
vcs_type: typ.Optional[str]
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
if (path / ".git").exists():
|
|
|
|
|
vcs_type = 'git'
|
|
|
|
|
elif (path / ".hg").exists():
|
|
|
|
|
vcs_type = 'hg'
|
|
|
|
|
else:
|
|
|
|
|
vcs_type = None
|
|
|
|
|
|
|
|
|
|
return ProjectContext(path, config_filepath, config_format, vcs_type)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RawConfig = typ.Dict[str, typ.Any]
|
|
|
|
|
|
|
|
|
|
|
2018-09-03 22:23:51 +02:00
|
|
|
class Config(typ.NamedTuple):
|
2018-12-05 09:38:27 +01:00
|
|
|
"""Container for parameters parsed from a config file."""
|
2018-09-03 22:23:51 +02:00
|
|
|
|
2018-11-04 21:11:42 +01:00
|
|
|
current_version: str
|
2018-12-05 09:38:27 +01:00
|
|
|
pep440_version : str
|
2018-09-03 22:23:51 +02:00
|
|
|
|
2018-11-04 21:11:42 +01:00
|
|
|
tag : bool
|
|
|
|
|
commit: bool
|
2018-12-08 19:18:47 +01:00
|
|
|
push : bool
|
2018-09-03 22:23:51 +02:00
|
|
|
|
2018-11-15 22:16:16 +01:00
|
|
|
file_patterns: PatternsByFilePath
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-09-03 22:23:51 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
def _debug_str(cfg: Config) -> str:
|
|
|
|
|
cfg_str_parts = [
|
|
|
|
|
f"Config Parsed: Config(",
|
|
|
|
|
f"current_version='{cfg.current_version}'",
|
|
|
|
|
f"pep440_version='{cfg.pep440_version}'",
|
|
|
|
|
f"tag={cfg.tag}",
|
|
|
|
|
f"commit={cfg.commit}",
|
|
|
|
|
f"push={cfg.push}",
|
2018-12-09 15:57:04 +01:00
|
|
|
"file_patterns={",
|
2018-12-05 09:38:27 +01:00
|
|
|
]
|
2018-09-03 22:23:51 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
for filepath, patterns in cfg.file_patterns.items():
|
|
|
|
|
for pattern in patterns:
|
|
|
|
|
cfg_str_parts.append(f"\n '{filepath}': '{pattern}'")
|
2018-09-03 22:23:51 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
cfg_str_parts += ["\n})"]
|
|
|
|
|
return ", ".join(cfg_str_parts)
|
2018-09-02 21:48:12 +02:00
|
|
|
|
|
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
MaybeConfig = typ.Optional[Config]
|
|
|
|
|
MaybeRawConfig = typ.Optional[RawConfig]
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-11-11 15:08:46 +01:00
|
|
|
FilePatterns = typ.Dict[str, typ.List[str]]
|
2018-09-02 21:48:12 +02:00
|
|
|
|
|
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
def _parse_cfg_file_patterns(cfg_parser: configparser.RawConfigParser,) -> FilePatterns:
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-11-11 15:08:46 +01:00
|
|
|
file_patterns: FilePatterns = {}
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
for filepath, patterns_str in cfg_parser.items("pycalver:file_patterns"):
|
|
|
|
|
patterns: typ.List[str] = []
|
|
|
|
|
for line in patterns_str.splitlines():
|
|
|
|
|
pattern = line.strip()
|
|
|
|
|
if pattern:
|
|
|
|
|
patterns.append(pattern)
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
file_patterns[filepath] = patterns
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
return file_patterns
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
class _ConfigParser(configparser.RawConfigParser):
|
|
|
|
|
"""Custom parser, simply to override optionxform behaviour."""
|
|
|
|
|
|
|
|
|
|
def optionxform(self, optionstr: str) -> str:
|
|
|
|
|
"""Non-xforming (ie. uppercase preserving) override.
|
|
|
|
|
|
|
|
|
|
This is important because our option names are actually
|
|
|
|
|
filenames, so case sensitivity is relevant. The default
|
|
|
|
|
behaviour is to do optionstr.lower()
|
|
|
|
|
"""
|
|
|
|
|
return optionstr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OptionVal = typ.Union[str, bool, None]
|
|
|
|
|
|
|
|
|
|
BOOL_OPTIONS: typ.Mapping[str, OptionVal] = {'commit': False, 'tag': None, 'push': None}
|
2018-11-11 15:08:46 +01:00
|
|
|
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
def _parse_cfg(cfg_buffer: typ.TextIO) -> RawConfig:
|
2018-12-08 19:18:47 +01:00
|
|
|
cfg_parser = _ConfigParser()
|
2018-11-11 15:08:46 +01:00
|
|
|
|
|
|
|
|
if hasattr(cfg_parser, 'read_file'):
|
|
|
|
|
cfg_parser.read_file(cfg_buffer)
|
|
|
|
|
else:
|
2018-12-05 09:38:27 +01:00
|
|
|
cfg_parser.readfp(cfg_buffer) # python2 compat
|
2018-11-11 15:08:46 +01:00
|
|
|
|
|
|
|
|
if not cfg_parser.has_section("pycalver"):
|
2018-12-08 19:18:47 +01:00
|
|
|
raise ValueError("Missing [pycalver] section.")
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
raw_cfg: RawConfig = dict(cfg_parser.items("pycalver"))
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
for option, default_val in BOOL_OPTIONS.items():
|
|
|
|
|
val: OptionVal = raw_cfg.get(option, default_val)
|
2018-12-09 15:57:04 +01:00
|
|
|
if isinstance(val, six.text_type):
|
2018-12-08 19:18:47 +01:00
|
|
|
val = val.lower() in ("yes", "true", "1", "on")
|
|
|
|
|
raw_cfg[option] = val
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
raw_cfg['file_patterns'] = _parse_cfg_file_patterns(cfg_parser)
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
return raw_cfg
|
2018-11-11 15:08:46 +01:00
|
|
|
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
def _parse_toml(cfg_buffer: typ.TextIO) -> RawConfig:
|
|
|
|
|
raw_full_cfg = toml.load(cfg_buffer)
|
2018-12-08 19:18:47 +01:00
|
|
|
raw_cfg = raw_full_cfg.get('pycalver', {})
|
2018-12-05 09:38:27 +01:00
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
for option, default_val in BOOL_OPTIONS.items():
|
|
|
|
|
raw_cfg[option] = raw_cfg.get(option, default_val)
|
2018-12-05 09:38:27 +01:00
|
|
|
|
|
|
|
|
return raw_cfg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _parse_config(raw_cfg: RawConfig) -> Config:
|
|
|
|
|
if 'current_version' not in raw_cfg:
|
|
|
|
|
raise ValueError("Missing 'pycalver.current_version'")
|
|
|
|
|
|
|
|
|
|
version_str = raw_cfg['current_version']
|
|
|
|
|
version_str = raw_cfg['current_version'] = version_str.strip("'\" ")
|
|
|
|
|
|
2018-12-09 14:49:13 +01:00
|
|
|
if version.PYCALVER_RE.match(version_str) is None:
|
2018-12-05 09:38:27 +01:00
|
|
|
raise ValueError(f"Invalid current_version = {version_str}")
|
|
|
|
|
|
|
|
|
|
pep440_version = version.pycalver_to_pep440(version_str)
|
|
|
|
|
|
|
|
|
|
commit = raw_cfg['commit']
|
|
|
|
|
tag = raw_cfg['tag']
|
|
|
|
|
push = raw_cfg['push']
|
|
|
|
|
|
|
|
|
|
if tag is None:
|
|
|
|
|
tag = raw_cfg['tag'] = False
|
|
|
|
|
if push is None:
|
|
|
|
|
push = raw_cfg['push'] = False
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-11-11 15:15:14 +01:00
|
|
|
if tag and not commit:
|
2018-12-05 09:38:27 +01:00
|
|
|
raise ValueError("pycalver.commit = true required if pycalver.tag = true")
|
2018-11-11 15:15:14 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
if push and not commit:
|
|
|
|
|
raise ValueError("pycalver.commit = true required if pycalver.push = true")
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
file_patterns = raw_cfg['file_patterns']
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
for filepath in file_patterns.keys():
|
|
|
|
|
if not os.path.exists(filepath):
|
|
|
|
|
log.warning(f"Invalid configuration, no such file: {filepath}")
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
cfg = Config(version_str, pep440_version, tag, commit, push, file_patterns)
|
|
|
|
|
log.debug(_debug_str(cfg))
|
|
|
|
|
return cfg
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
def parse(ctx: ProjectContext) -> MaybeConfig:
|
|
|
|
|
"""Parse config file if available."""
|
|
|
|
|
if not ctx.config_filepath.exists():
|
|
|
|
|
log.error(f"File not found: {ctx.config_filepath}")
|
2018-09-03 22:23:51 +02:00
|
|
|
return None
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
try:
|
|
|
|
|
with ctx.config_filepath.open(mode="rt", encoding="utf-8") as fh:
|
|
|
|
|
if ctx.config_format == 'toml':
|
|
|
|
|
raw_cfg = _parse_toml(fh)
|
|
|
|
|
elif ctx.config_format == 'cfg':
|
|
|
|
|
raw_cfg = _parse_cfg(fh)
|
|
|
|
|
else:
|
|
|
|
|
return None
|
2018-09-03 22:23:51 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
return _parse_config(raw_cfg)
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
log.error(f"Error parsing {ctx.config_filepath}: {str(ex)}")
|
|
|
|
|
return None
|
2018-11-11 15:08:46 +01:00
|
|
|
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
DEFAULT_CONFIGPARSER_BASE_STR = """
|
2018-11-11 15:08:46 +01:00
|
|
|
[pycalver]
|
2018-12-05 09:38:27 +01:00
|
|
|
current_version = "{initial_version}"
|
2018-11-11 15:08:46 +01:00
|
|
|
commit = True
|
|
|
|
|
tag = True
|
2018-12-05 09:38:27 +01:00
|
|
|
push = True
|
2018-12-08 19:18:47 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
[pycalver:file_patterns]
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_CONFIGPARSER_SETUP_CFG_STR = """
|
|
|
|
|
setup.cfg =
|
|
|
|
|
current_version = "{{version}}"
|
|
|
|
|
"""
|
|
|
|
|
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
DEFAULT_CONFIGPARSER_SETUP_PY_STR = """
|
|
|
|
|
setup.py =
|
|
|
|
|
"{version}"
|
|
|
|
|
"{pep440_version}"
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_CONFIGPARSER_README_RST_STR = """
|
|
|
|
|
README.rst =
|
|
|
|
|
"{version}"
|
|
|
|
|
"{pep440_version}"
|
2018-11-11 15:08:46 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
DEFAULT_CONFIGPARSER_README_MD_STR = """
|
|
|
|
|
README.md =
|
2018-11-11 15:08:46 +01:00
|
|
|
"{version}"
|
|
|
|
|
"{pep440_version}"
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
DEFAULT_TOML_BASE_STR = """
|
|
|
|
|
[pycalver]
|
|
|
|
|
current_version = "{initial_version}"
|
|
|
|
|
commit = true
|
|
|
|
|
tag = true
|
|
|
|
|
push = true
|
2018-12-08 19:18:47 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
[pycalver.file_patterns]
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_TOML_PYCALVER_STR = """
|
|
|
|
|
"pycalver.toml" = [
|
|
|
|
|
'current_version = "{{version}}"',
|
|
|
|
|
]
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_TOML_PYPROJECT_STR = """
|
|
|
|
|
"pyproject.toml" = [
|
|
|
|
|
'current_version = "{{version}}"',
|
|
|
|
|
]
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_TOML_SETUP_PY_STR = """
|
|
|
|
|
"setup.py" = [
|
|
|
|
|
"{version}",
|
|
|
|
|
"{pep440_version}",
|
|
|
|
|
]
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_TOML_README_RST_STR = """
|
|
|
|
|
"README.rst" = [
|
|
|
|
|
"{version}",
|
|
|
|
|
"{pep440_version}",
|
|
|
|
|
]
|
2018-11-11 15:08:46 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
DEFAULT_TOML_README_MD_STR = """
|
|
|
|
|
"README.md" = [
|
|
|
|
|
"{version}",
|
|
|
|
|
"{pep440_version}",
|
|
|
|
|
]
|
2018-11-11 15:08:46 +01:00
|
|
|
"""
|
2018-09-03 22:23:51 +02:00
|
|
|
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
def default_config(ctx: ProjectContext) -> str:
|
|
|
|
|
"""Generate initial default config."""
|
2018-12-08 19:18:47 +01:00
|
|
|
fmt = ctx.config_format
|
|
|
|
|
if fmt == 'cfg':
|
2018-12-05 09:38:27 +01:00
|
|
|
base_str = DEFAULT_CONFIGPARSER_BASE_STR
|
|
|
|
|
|
|
|
|
|
default_pattern_strs_by_filename = {
|
|
|
|
|
"setup.cfg" : DEFAULT_CONFIGPARSER_SETUP_CFG_STR,
|
|
|
|
|
"setup.py" : DEFAULT_CONFIGPARSER_SETUP_PY_STR,
|
|
|
|
|
"README.rst": DEFAULT_CONFIGPARSER_README_RST_STR,
|
|
|
|
|
"README.md" : DEFAULT_CONFIGPARSER_README_MD_STR,
|
|
|
|
|
}
|
2018-12-08 19:18:47 +01:00
|
|
|
elif fmt == 'toml':
|
2018-12-05 09:38:27 +01:00
|
|
|
base_str = DEFAULT_TOML_BASE_STR
|
|
|
|
|
|
|
|
|
|
default_pattern_strs_by_filename = {
|
|
|
|
|
"pyproject.toml": DEFAULT_TOML_PYPROJECT_STR,
|
|
|
|
|
"pycalver.toml" : DEFAULT_TOML_PYCALVER_STR,
|
|
|
|
|
"setup.py" : DEFAULT_TOML_SETUP_PY_STR,
|
|
|
|
|
"README.rst" : DEFAULT_TOML_README_RST_STR,
|
|
|
|
|
"README.md" : DEFAULT_TOML_README_MD_STR,
|
|
|
|
|
}
|
|
|
|
|
else:
|
2018-12-08 19:18:47 +01:00
|
|
|
raise ValueError(f"Invalid config_format='{fmt}', must be either 'toml' or 'cfg'.")
|
2018-12-05 09:38:27 +01:00
|
|
|
|
2018-09-02 21:48:12 +02:00
|
|
|
initial_version = dt.datetime.now().strftime("v%Y%m.0001-dev")
|
|
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
cfg_str = base_str.format(initial_version=initial_version)
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
for filename, default_str in default_pattern_strs_by_filename.items():
|
|
|
|
|
if (ctx.path / filename).exists():
|
|
|
|
|
cfg_str += default_str
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
has_config_file = any((ctx.path / fn).exists() for fn in SUPPORTED_CONFIGS)
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
if not has_config_file:
|
|
|
|
|
if ctx.config_format == 'cfg':
|
|
|
|
|
cfg_str += DEFAULT_CONFIGPARSER_SETUP_CFG_STR
|
|
|
|
|
if ctx.config_format == 'toml':
|
|
|
|
|
cfg_str += DEFAULT_TOML_PYCALVER_STR
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
cfg_str += "\n"
|
2018-11-11 15:08:46 +01:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
return cfg_str
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-12-05 09:38:27 +01:00
|
|
|
|
2018-12-08 19:18:47 +01:00
|
|
|
def write_content(ctx: ProjectContext) -> None:
|
|
|
|
|
"""Update project config file with initial default config."""
|
|
|
|
|
# path : pl.Path
|
|
|
|
|
# config_filepath: pl.Path
|
|
|
|
|
# config_format : str
|
|
|
|
|
# vcs_type : typ.Optional[str]
|
|
|
|
|
|
|
|
|
|
cfg_lines = default_config(ctx)
|
2018-12-05 09:38:27 +01:00
|
|
|
cfg_content = "\n" + "\n".join(cfg_lines)
|
|
|
|
|
if os.path.exists("pyproject.toml"):
|
|
|
|
|
with io.open("pyproject.toml", mode="at", encoding="utf-8") as fh:
|
|
|
|
|
fh.write(cfg_content)
|
|
|
|
|
print("Updated pyproject.toml")
|
|
|
|
|
elif os.path.exists("setup.cfg"):
|
|
|
|
|
with io.open("setup.cfg", mode="at", encoding="utf-8") as fh:
|
|
|
|
|
fh.write(cfg_content)
|
|
|
|
|
print("Updated setup.cfg")
|
|
|
|
|
else:
|
|
|
|
|
cfg_content = "\n".join(cfg_lines)
|
|
|
|
|
with io.open("pycalver.toml", mode="at", encoding="utf-8") as fh:
|
|
|
|
|
fh.write(cfg_content)
|
|
|
|
|
print("Created pycalver.toml")
|