Skip to content

_collector

Collect code tags and output for review in a single location.

Attributes⚓︎

CODE_TAG_RE module-attribute ⚓︎

CODE_TAG_RE = '((^|\\s|\\(|"|\\\')(?P<tag>{tag})(:| -)([^\\r\\n]))(?P<text>.+)'

Default code tag regex with tag and text matching groups.

Requires formatting with list of tags: CODE_TAG_RE.format(tag='|'.join(tag_list))

Commonly, the tag_list could be COMMON_CODE_TAGS

COMMON_CODE_TAGS module-attribute ⚓︎

COMMON_CODE_TAGS = ['FIXME', 'TODO', 'PLANNED', 'HACK', 'REVIEW', 'TBD', 'DEBUG']

Most common code tags.

FYI and NOTE are excluded to not be tracked in the Code Summary.

SKIP_PHRASE module-attribute ⚓︎

SKIP_PHRASE = 'calcipy_skip_tags'

String that indicates the file should be excluded from the tag search.

Functions⚓︎

github_blame_url ⚓︎

github_blame_url(clone_uri)

Format the blame URL.

PARAMETER DESCRIPTION
clone_uri

git remote URI

TYPE: str

RETURNS DESCRIPTION
str

repo_url

TYPE: str

Source code in calcipy/code_tag_collector/_collector.py
@beartype
def github_blame_url(clone_uri: str) -> str:
    """Format the blame URL.

    Args:
        clone_uri: git remote URI

    Returns:
       str: `repo_url`

    """
    # Could be ssh or http (with or without .git)
    # > [email protected]:KyleKing/calcipy.git
    # > https://github.com/KyleKing/calcipy.git
    if matches := re.compile(_GITHUB_ORIGIN).match(clone_uri):
        github_url = 'https://github.com/'
        return f"{github_url}{matches['owner']}/{matches['repository']}"
    return ''

write_code_tag_file ⚓︎

write_code_tag_file(
    path_tag_summary, paths_source, base_dir, regex="", tags="", header="# Task Summary\n\nAuto-Generated by `calcipy`"
)

Create the code tag summary file.

PARAMETER DESCRIPTION
path_tag_summary

Path to the output file

TYPE: Path

paths_source

list of source files to parse

TYPE: List[Path]

base_dir

base directory relative to the searched files

TYPE: Path

regex

compiled regular expression. Expected to have matching groups (tag, text). Default is CODE_TAG_RE with tags from tag_order

TYPE: str DEFAULT: ''

tags

subset of all tags to include in the report and specified order. Default is COMMON_CODE_TAGS

TYPE: str DEFAULT: ''

header

header text

TYPE: str DEFAULT: '# Task Summary\n\nAuto-Generated by `calcipy`'

Source code in calcipy/code_tag_collector/_collector.py
@beartype
def write_code_tag_file(
    path_tag_summary: Path,
    paths_source: List[Path],
    base_dir: Path,
    regex: str = '',
    tags: str = '',
    header: str = '# Task Summary\n\nAuto-Generated by `calcipy`',
) -> None:
    """Create the code tag summary file.

    Args:
        path_tag_summary: Path to the output file
        paths_source: list of source files to parse
        base_dir: base directory relative to the searched files
        regex: compiled regular expression. Expected to have matching groups `(tag, text)`.
            Default is CODE_TAG_RE with tags from tag_order
        tags: subset of all tags to include in the report and specified order. Default is COMMON_CODE_TAGS
        header: header text

    """
    tag_order = [_t.strip() for _t in tags.split(',') if _t] or COMMON_CODE_TAGS
    matcher = (regex or CODE_TAG_RE).format(tag='|'.join(tag_order))

    matches = _search_files(paths_source, re.compile(matcher))
    if report := _format_report(
        base_dir, matches, tag_order=tag_order,
    ).strip():
        path_tag_summary.parent.mkdir(exist_ok=True, parents=True)
        path_tag_summary.write_text(f'{header}\n\n{report}\n\n<!-- {SKIP_PHRASE} -->\n')
        logger.text('Created Code Tag Summary', path_tag_summary=path_tag_summary)
    elif path_tag_summary.is_file():
        path_tag_summary.unlink()