Return the installed specify-cli distribution version or 'unknown'. Uses importlib.metadata so the value reflects what was actually installed by pip/uv/pipx — not a value read from pyproject.toml. This is intentional for `specify self check`, which should reason about the installed
()
| 51 | |
| 52 | |
| 53 | def _get_installed_version() -> str: |
| 54 | """Return the installed specify-cli distribution version or 'unknown'. |
| 55 | |
| 56 | Uses importlib.metadata so the value reflects what was actually installed |
| 57 | by pip/uv/pipx — not a value read from pyproject.toml. This is |
| 58 | intentional for `specify self check`, which should reason about the |
| 59 | installed distribution rather than a source-tree fallback. Callers must |
| 60 | treat the sentinel string 'unknown' as an indeterminate value (see FR-020). |
| 61 | """ |
| 62 | import importlib.metadata |
| 63 | |
| 64 | metadata_errors = [importlib.metadata.PackageNotFoundError] |
| 65 | invalid_metadata_error = getattr(importlib.metadata, "InvalidMetadataError", None) |
| 66 | if invalid_metadata_error is not None: |
| 67 | metadata_errors.append(invalid_metadata_error) |
| 68 | |
| 69 | try: |
| 70 | return importlib.metadata.version("specify-cli") |
| 71 | except tuple(metadata_errors): |
| 72 | return "unknown" |
| 73 | |
| 74 | |
| 75 | def _normalize_tag(tag: str) -> str: |