Sources¶
sources
¶
Local project metadata extraction helpers.
| FUNCTION | DESCRIPTION |
|---|---|
get_version |
Resolve project version using a 5-step chain; first non-empty wins. |
get_license |
Resolve project license using a 2-step chain; first non-empty wins. |
get_python_requires |
Resolve python_requires using a 2-step chain; first non-empty wins. |
get_git_branch |
Return the current git branch name, or 'unknown' on failure. |
get_git_tag |
Return the most recent git tag, or 'untagged' if none exist. |
get_git_commit_count |
Return total number of commits as a string, or 'unknown' on failure. |
get_lines_of_code |
Count non-blank lines across source files matching extensions. |
get_git_status |
Return 'clean' or 'dirty' based on working tree state, or 'unknown' on failure. |
get_test_results |
Parse a JUnit XML report and return a results summary string. |
get_coverage |
Return line coverage percentage string e.g. '82%'. |
get_version(search_path: Path = Path('.')) -> str
¶
Resolve project version using a 5-step chain; first non-empty wins.
- pyproject.toml → project.version
- setup.py → literal version= string
- _version.py / version.py (also src//_version.py, src//version.py)
- git describe --tags --abbrev=0
- "unknown"
Source code in src/badgeshield/sources.py
get_license(search_path: Path = Path('.')) -> str
¶
Resolve project license using a 2-step chain; first non-empty wins.
- pyproject.toml → project.license (string or dict with text/file key)
- setup.py → literal license= string
Source code in src/badgeshield/sources.py
get_python_requires(search_path: Path = Path('.')) -> str
¶
Resolve python_requires using a 2-step chain; first non-empty wins.
- pyproject.toml → project.requires-python
- setup.py → literal python_requires= string
Source code in src/badgeshield/sources.py
get_git_branch(search_path: Path = Path('.')) -> str
¶
Return the current git branch name, or 'unknown' on failure.
get_git_tag(search_path: Path = Path('.')) -> str
¶
Return the most recent git tag, or 'untagged' if none exist.
get_git_commit_count(search_path: Path = Path('.')) -> str
¶
Return total number of commits as a string, or 'unknown' on failure.
get_lines_of_code(search_path: Path = Path('.'), extensions: tuple = ('.py',)) -> str
¶
Count non-blank lines across source files matching extensions.
Never raises. Returns '0' if no files match. Returns comma-formatted integer string. Excludes directories in _EXCLUDED_DIRS and any directory ending with .egg-info.
Source code in src/badgeshield/sources.py
get_git_status(search_path: Path = Path('.')) -> str
¶
Return 'clean' or 'dirty' based on working tree state, or 'unknown' on failure.
IMPORTANT: Uses direct subprocess.run (not _run_git) to distinguish non-zero exit (not a git repo) from zero exit with empty output (clean). Never returns 'clean' on failure — that would be a false positive.
Source code in src/badgeshield/sources.py
get_test_results(junit_xml: Path) -> str
¶
Parse a JUnit XML report and return a results summary string.
Returns e.g. '47 passed' or '2 failed / 49'.
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If junit_xml does not exist. |
ParseError
|
If the XML is malformed. |
ValueError
|
If the root element is not a recognisable JUnit structure. |
Source code in src/badgeshield/sources.py
get_coverage(coverage_xml: Path) -> str
¶
Return line coverage percentage string e.g. '82%'.
Raises FileNotFoundError or ValueError on bad input (delegates to parse_coverage_xml).