Exemplo n.º 1
0
def _render_log():
    """Totally tap into Towncrier internals to get an in-memory result.
    """
    config = load_config(ROOT)
    definitions = config["types"]
    fragments, fragment_filenames = find_fragments(
        pathlib.Path(config["directory"]).absolute(),
        config["sections"],
        None,
        definitions,
    )
    project_options = {
        "name": config["package"],
        "version": _read_text_version(),
        "date": datetime.date.today().isoformat(),
    }
    rendered = render_fragments(
        pathlib.Path(config["template"]).read_text(encoding="utf-8"),
        config["issue_format"],
        split_fragments(fragments, definitions),
        definitions,
        config["underlines"][1:],
        False,  # Don't add newlines to wrapped text.
        project_options,
    )
    return rendered
Exemplo n.º 2
0
def get_tag_content(ctx):
    config = load_config(ctx.directory.as_posix())
    definitions = config["types"]

    (fragments, fragment_filenames) = find_fragments(
        pathlib.Path(config["directory"]).absolute(),
        config["sections"],
        None,
        definitions,
    )

    return render_fragments(
        pathlib.Path(config["template"]).read_text(encoding="utf-8"),
        config["issue_format"],
        split_fragments(fragments, definitions),
        definitions,
        config["underlines"][1:],
        False,  # don't add newlines to wrapped text
    )
Exemplo n.º 3
0
def _render_log():
    """Totally tap into Towncrier internals to get an in-memory result.
    """
    config = load_config(ROOT)
    definitions = config['types']
    fragments, fragment_filenames = find_fragments(
        pathlib.Path(config['directory']).absolute(),
        config['sections'],
        None,
        definitions,
    )
    rendered = render_fragments(
        pathlib.Path(config['template']).read_text(encoding='utf-8'),
        config['issue_format'],
        split_fragments(fragments, definitions),
        definitions,
        config['underlines'][1:],
    )
    return rendered
Exemplo n.º 4
0
def render_changelog(
        fragment_path: str,
        output_type: OutputType,
        sections: Iterable[str],
        fragment_types: Iterable[str],
        underlines: List[str],
        project_version: str,
        project_date: str):
    """
    Render change fragments into a new partial changelog.

    This changelog can be merged into an existing changelog with
    `merge_with_existing_changelog`.
    """
    fragments, fragment_filenames = find_fragments(
        fragment_path,
        sections,
        None,
        fragment_types)
    fragments = split_fragments(fragments, fragment_types)
    template_name = (
        'templates/towncrier_markdown.tmpl' if output_type == 'markdown' else
        'templates/towncrier_rest.tmpl')
    template = pkgutil.get_data(__name__, template_name).decode('utf-8')
    issue_format = ''
    top_line = ''
    wrap = False
    return render_fragments(
        template,
        issue_format,
        top_line,
        fragments,
        fragment_types,
        underlines,
        wrap,
        {'name': '',
         'version': project_version,
         'date': project_date},
        top_underline=underlines[0])
Exemplo n.º 5
0
def _render_log():
    """Totally tap into Towncrier internals to get an in-memory result."""
    config = load_config(ROOT)
    definitions = config["types"]
    fragments, fragment_filenames = find_fragments(
        pathlib.Path(config["directory"]).absolute(),
        config["sections"],
        None,
        definitions,
    )
    rendered = render_fragments(
        pathlib.Path(config["template"]).read_text(encoding="utf-8"),
        config["issue_format"],
        split_fragments(fragments, definitions),
        definitions,
        config["underlines"][1:],
        False,  # Don't add newlines to wrapped text.
        {
            "name": "requirementslib",
            "version": "1.6.7",
            "date": "2022-7-7",
        },  # towncrier==19.9.0
    )
    return rendered
Exemplo n.º 6
0
def generate_changelog_for_docs(directory, skip_if_empty=True):
    """
    The main entry point.
    """
    directory = os.path.abspath(directory)
    config = load_config(directory)
    if config is None:
        raise ValueError(
            f"No vaild towncrier configuration could be found in the directory {directory}"
        )

    curdir = os.getcwd()
    os.chdir(directory)

    print("Loading template...")
    if config["template"] is None:
        template = pkg_resources.resource_string(
            "towncrier", "templates/template.rst").decode("utf8")
    else:
        with open(config["template"], "rb") as tmpl:
            template = tmpl.read().decode("utf8")

    print("Finding news fragments...")

    definitions = config["types"]

    if config.get("directory"):
        base_directory = os.path.abspath(config["directory"])
        fragment_directory = None
    else:
        base_directory = os.path.abspath(
            os.path.join(directory, config["package_dir"], config["package"]))
        fragment_directory = "newsfragments"

    fragments, fragment_filenames = find_fragments(base_directory,
                                                   config["sections"],
                                                   fragment_directory,
                                                   definitions)

    if skip_if_empty and not fragment_filenames:
        return ""

    print("Rendering news fragments...")
    fragments = split_fragments(fragments, definitions)
    rendered = render_fragments(
        # The 0th underline is used for the top line
        template,
        config["issue_format"],
        fragments,
        definitions,
        config["underlines"][1:],
        config["wrap"],
    )

    project_version = get_version(
        os.path.join(directory, config["package_dir"]), config["package"])

    package = config.get("package")
    if package:
        project_name = get_project_name(
            os.path.abspath(os.path.join(directory, config["package_dir"])),
            package)
    else:
        # Can't determine a project_name, but maybe it is not needed.
        project_name = ""

    project_date = _get_date()

    top_line = config["title_format"].format(name=project_name,
                                             version=project_version,
                                             project_date=project_date)
    top_line += u"\n" + (config["underlines"][0] * len(top_line)) + u"\n"

    os.chdir(curdir)
    return top_line + rendered
Exemplo n.º 7
0
def generate_changelog_for_docs(directory, skip_if_empty=True, underline=1):
    """
    Generate a string which is the rendered changelog.

    Parameters
    ----------
    skip_if_empty : `bool`
        Return nothing if no entries are found.
    underline : `int`
        Controls the first underline to be used. The underline characters are
        configurable in the towncrier settings they default to ``["=", "-", "~"]``.
        This int sets the first number, so set to ``1`` to use ``-`` for the
        title and subsequent characters for subsections.
    """
    directory = os.path.abspath(directory)
    base_directory, config = load_config_from_options(directory, None)

    curdir = os.getcwd()
    os.chdir(base_directory)

    print("Loading template...")
    if config["template"] is None:
        template = pkg_resources.resource_string(
            "towncrier", "templates/default.rst").decode("utf8")
    else:
        with open(config["template"], "rb") as tmpl:
            template = tmpl.read().decode("utf8")

    print("Finding news fragments...")

    definitions = config["types"]

    if config.get("directory"):
        base_directory = os.path.abspath(config["directory"])
        fragment_directory = None
    else:
        base_directory = os.path.abspath(
            os.path.join(directory, config["package_dir"], config["package"]))
        fragment_directory = "newsfragments"

    fragments, fragment_filenames = find_fragments(base_directory,
                                                   config["sections"],
                                                   fragment_directory,
                                                   definitions)

    # Empty fragments now are an OrderedDict([('', {})])
    if skip_if_empty and not fragments.get('', True):
        return ""

    fragments = split_fragments(fragments,
                                definitions,
                                all_bullets=config["all_bullets"])

    project_version = config.get('version')
    if project_version is None:
        project_version = get_version(
            os.path.join(base_directory, config["package_dir"]),
            config["package"]).strip()

    project_name = config.get('name')
    if not project_name:
        package = config.get("package")
        if package:
            project_name = get_project_name(
                os.path.abspath(
                    os.path.join(base_directory, config["package_dir"])),
                package,
            )
        else:
            # Can't determine a project_name, but maybe it is not needed.
            project_name = ""

    project_date = _get_date().strip()

    title_format = config["title_format"] or "{name} {version} ({project_date})"
    top_line = title_format.format(name=project_name,
                                   version=project_version,
                                   project_date=project_date)

    rendered = render_fragments(
        template,
        config["issue_format"],
        top_line,
        fragments,
        definitions,
        config["underlines"][underline + 1:],
        config["wrap"],
        {
            "name": project_name,
            "version": project_version,
            "date": project_date
        },
        top_underline=config["underlines"][underline],
        all_bullets=config["all_bullets"],
    )

    os.chdir(curdir)
    return rendered