示例#1
0
def test_update_docs(config, version):
    str_path = config.get("docs", "path")
    assert str_path is not None
    path = Path(str_path)

    version_pattern = config.get("docs", "version_pattern", fallback=helpers.DOCS_VERSION_PATTERN)
    version_format = config.get("docs", "version_format", fallback=helpers.DOCS_VERSION_FORMAT)

    release_pattern = config.get("docs", "release_pattern", fallback=helpers.DOCS_RELEASE_PATTERN)
    release_format = config.get("docs", "release_format", fallback=helpers.DOCS_RELEASE_FORMAT)

    new_row = helpers.update_file(
        path=path,
        pattern=release_pattern,
        template=release_format,
        version=version,
        dry_run=True,
    )
    assert new_row.strip() == 'release = "0.0.2"', "DOCS: Versions does not match"

    new_row = helpers.update_file(
        path=path,
        pattern=version_pattern,
        template=version_format,
        version=version,
        dry_run=True,
    )
    assert new_row.strip() == 'version = "0.0"', "DOCS: Versions does not match"
示例#2
0
def test_update_sonar_properties(config, version):
    str_path = config["sonar"].get("path")
    assert str_path is not None
    path = Path(str_path)
    new_row = helpers.update_file(
        path=path,
        pattern=helpers.SONAR_PATTERN,
        template=helpers.SONAR_TEMPLATE,
        version=version,
        dry_run=True,
    )
    assert new_row.strip() == "sonar.projectVersion=0.0", "SONAR: Versions does not match"
示例#3
0
def test_update_main_project(config, version):
    str_path = config["main_project"].get("path")
    assert str_path is not None
    path = Path(str_path)
    assert path.exists(), f"MAIN_PROJECT: Path does not exist: {path}"
    new_row = helpers.update_file(
        path=path,
        pattern=helpers.MAIN_PROJECT_PATTERN,
        template=helpers.MAIN_PROJECT_TEMPLATE,
        version=version,
        dry_run=True,
    )
    assert new_row.strip() == '__version__ = VERSION = "0.0.2"', "MAIN: Versions does not match"
示例#4
0
def update_docs_conf(version: Tuple[str, str, str], dry_run: bool = False) -> Optional[str]:
    """
    Updates the Sphinx conf.py file with the new release number

    :param version: Release number tuple (major, minor, release)
    :param dry_run: If `True`, no operation performed
    :return: changed string
    """
    assert RELEASE_CONFIG is not None
    if not RELEASE_CONFIG.has_section("docs"):
        raise helpers.NothingToDoException("No `docs` section in release.ini file")

    try:
        _path = RELEASE_CONFIG["docs"].get("path")
        path = Path(_path)

        pattern_release = RELEASE_CONFIG["docs"].get("pattern_release", "").strip('"') or helpers.DOCS_RELEASE_PATTERN
        template_release = RELEASE_CONFIG["docs"].get("template_release", "").strip('"') or helpers.DOCS_RELEASE_FORMAT
        pattern_version = RELEASE_CONFIG["docs"].get("pattern_version", "").strip('"') or helpers.DOCS_VERSION_PATTERN
        template_version = RELEASE_CONFIG["docs"].get("template_version", "").strip('"') or helpers.DOCS_VERSION_FORMAT

    except configparser.Error as e:
        raise helpers.NothingToDoException("No action to perform for docs file", e)

    update_release = helpers.update_file(
        path=path,
        pattern=pattern_release,
        template=template_release,
        version=version,
        dry_run=dry_run,
    )
    update_version = helpers.update_file(
        path=path,
        pattern=pattern_version,
        template=template_version,
        version=version,
        dry_run=dry_run,
    )
    return str(update_release) + str(update_version)
示例#5
0
def update_release_ini(path: Path, version: Tuple[str, str, str], dry_run: bool = False) -> Optional[str]:
    """
    Updates the release.ini file with the new release number

    :param path: Release file path
    :param version: release number, as (<major>, <minor>, <release>)
    :param dry_run: If `True`, the operation WILL NOT be performed
    :return: Updated lines
    """
    return helpers.update_file(
        path=path,
        pattern=helpers.RELEASE_INI_PATTERN,
        template=helpers.RELEASE_INI_TEMPLATE,
        version=version,
        dry_run=dry_run,
    )
示例#6
0
def update_sonar_properties(version: Tuple[str, str, str], dry_run: bool = False) -> Optional[str]:
    """
    Updates the sonar-project.properties file with the new release number

    :param version: Release number tuple (major, minor, release)
    :param dry_run: If `True`, no operation performed
    :return: changed string
    """
    assert RELEASE_CONFIG is not None
    if not RELEASE_CONFIG.has_section("sonar"):
        raise helpers.NothingToDoException("No `sonar` section in release.ini file")

    try:
        _path = RELEASE_CONFIG["sonar"].get("path")
        path = Path(_path)
        pattern = RELEASE_CONFIG["sonar"].get("pattern", "").strip('"') or helpers.SONAR_PATTERN
        template = RELEASE_CONFIG["sonar"].get("template", "").strip('"') or helpers.SONAR_TEMPLATE
    except configparser.Error as e:
        raise helpers.NothingToDoException("No action to perform for sonar file", e)
    return helpers.update_file(path=path, pattern=pattern, template=template, version=version, dry_run=dry_run)
示例#7
0
def update_main_file(version: Tuple[str, str, str], dry_run: bool = True) -> Optional[str]:
    """
    Updates the main django settings file, or a python script with a __init__.py file.

    :param version: Release number tuple (major, minor, release)
    :param dry_run: If `True`, no operation performed
    :return: changed string
    """
    assert RELEASE_CONFIG is not None
    if not RELEASE_CONFIG.has_section("main_project"):
        raise helpers.NothingToDoException("No `main_project` section in release.ini file")

    try:
        _path = RELEASE_CONFIG["main_project"].get("path")
        if _path is None:
            raise helpers.NothingToDoException("No action to perform for main project: No path provided.")
        path = Path(_path)
        pattern = RELEASE_CONFIG["main_project"].get("pattern", "").strip('"') or helpers.MAIN_PROJECT_PATTERN
        template = RELEASE_CONFIG["main_project"].get("template", "").strip('"') or helpers.MAIN_PROJECT_TEMPLATE
    except configparser.Error as e:
        raise helpers.NothingToDoException("Unable to update main project file", e)
    return helpers.update_file(path=path, pattern=pattern, template=template, version=version, dry_run=dry_run)