API Reference¶
This page documents the Python API for wcheck. You can use these functions programmatically in your own scripts.
Core Functions¶
check_workspace_status(workspace_directory, full=False, verbose=False, show_time=False, fetch=False, gui=False, tui=False)
¶
Check and display the status of all repositories in a workspace.
Scans the workspace for git repositories and displays their current branch, uncommitted changes, and remote sync status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_directory
|
Path
|
Path to the workspace directory containing repositories. |
required |
full
|
bool
|
If True, show all repositories. If False, only show those with changes. |
False
|
verbose
|
bool
|
If True, print additional information about each repository. |
False
|
show_time
|
bool
|
If True, include time since last commit in the output. |
False
|
fetch
|
bool
|
If True, fetch from remotes before checking status. |
False
|
gui
|
bool
|
If True, launch the GUI interface instead of console output. |
False
|
tui
|
bool
|
If True, launch the TUI interface instead of console output. |
False
|
Source code in src/wcheck/wcheck.py
compare_workspace_to_config(workspace_directory, config_filename, full=False, verbose=False, show_time=False, gui=False, tui=False)
¶
Compare workspace repository versions with a configuration file.
Displays a table comparing the current branch/version of each repository in the workspace with the version specified in the configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_directory
|
Path
|
Path to the workspace directory containing repositories. |
required |
config_filename
|
str
|
Path to the YAML configuration file specifying expected versions. |
required |
full
|
bool
|
If True, show all repositories. If False, only show mismatches. |
False
|
verbose
|
bool
|
If True, print additional information during processing. |
False
|
show_time
|
bool
|
If True, include time since last commit in the output. |
False
|
gui
|
bool
|
If True, launch the GUI interface instead of console output. |
False
|
tui
|
bool
|
If True, launch the TUI interface instead of console output. |
False
|
Source code in src/wcheck/wcheck.py
compare_config_files(*config_files, full=False, verbose=False, show_time=False, full_name=False)
¶
Compare repository versions across multiple configuration files.
Reads each configuration file and displays a table comparing the repository versions specified in each file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*config_files
|
str
|
Variable number of paths to configuration files. |
()
|
full
|
bool
|
If True, show all repositories. If False, only show differences. |
False
|
verbose
|
bool
|
If True, print additional information during processing. |
False
|
show_time
|
bool
|
If True, include modification time in the output. |
False
|
full_name
|
bool
|
If True, show full file paths. If False, show only filenames. |
False
|
Source code in src/wcheck/wcheck.py
compare_config_versions(config_filename, full=False, verbose=False, show_time=False, version_filter=None, stash=False)
¶
Compare versions of a config file across different git branches.
Checks out each branch in the config file's repository and compares the repository versions specified in the config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_filename
|
str
|
Path to the configuration file to compare. |
required |
full
|
bool
|
If True, show all repositories. If False, only show differences. |
False
|
verbose
|
bool
|
If True, print additional information during processing. |
False
|
show_time
|
bool
|
If True, include modification time in the output. |
False
|
version_filter
|
list[str] | None
|
List of regex patterns to filter which branches to compare. |
None
|
stash
|
bool
|
If True, stash uncommitted changes before switching branches. |
False
|
Source code in src/wcheck/wcheck.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | |
Utility Functions¶
get_workspace_repos(workspace_directory)
¶
Find all git repositories in a workspace directory.
Walks the workspace directory and identifies all subdirectories that are git repositories (contain a .git folder). Skips nested repositories for efficiency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_directory
|
Path
|
Path to the workspace directory to scan. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Repo]
|
Dictionary mapping repository directory names to Repo objects. |
dict[str, Repo]
|
Returns empty dictionary if workspace_directory is not a directory. |
Source code in src/wcheck/wcheck.py
get_status_repo(repo)
¶
Get a formatted status string for a repository.
Returns a rich-formatted string showing: - Number of untracked files (U) - Number of modified files (M) - Number of staged files (S) - Number of commits ahead/behind remote
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
Repo
|
Git repository object. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted status string with rich markup, or empty string if clean. |
Source code in src/wcheck/wcheck.py
get_repo_head_ref(repo, verbose_output=False)
¶
Get the current HEAD reference for a repository.
Returns the branch name, tag name, or commit SHA depending on the state: - If on a branch: returns branch name - If detached at a tag: returns tag name - If detached at a commit: returns commit SHA - If no commits: returns branch name with '(no commits)' suffix
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
Repo
|
Git repository object. |
required |
verbose_output
|
bool
|
If True, print additional information about detached HEAD states. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
String representing the current HEAD reference. |
Source code in src/wcheck/wcheck.py
get_remote_status(repo)
¶
Get the number of commits ahead and behind the remote tracking branch.
Compares the current local branch with its remote tracking branch to determine how many commits need to be pushed and pulled. Uses efficient iter_commits with range notation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
Repo
|
Git repository object. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Tuple of (commits_to_push, commits_to_pull). Returns (0, 0) if: |
int
|
|
tuple[int, int]
|
|
tuple[int, int]
|
|
tuple[int, int]
|
|
Source code in src/wcheck/wcheck.py
get_elapsed_time_repo(repo)
¶
Get a human-readable string of time since the last commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
Repo
|
Git repository object. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted time difference string (e.g., '2 days', '3 hours'), |
str
|
or 'no commits' if repository has no commits. |
Source code in src/wcheck/wcheck.py
show_repos_config_versions(repos_config_versions, full=False, gui=True)
¶
Display a table comparing repository versions across configurations.
Creates a rich table showing repository versions from different sources (e.g., workspace vs config file, or multiple config files). Highlights repositories that differ between versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repos_config_versions
|
dict[str, dict[str, str]]
|
Nested dictionary where outer keys are version/config names and inner dictionaries map repo names to their versions. |
required |
full
|
bool
|
If True, show all repositories. If False, only show repositories that differ between versions. |
False
|
gui
|
bool
|
Unused parameter (kept for API compatibility). |
True
|
Source code in src/wcheck/wcheck.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
matches_any(name, patternlist)
¶
Match any of the patterns in patternlist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
String to match against. |
required |
patternlist
|
list[str] | None
|
List of regular expressions or exact strings to match with. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if any of the patterns match the string, False otherwise. |
Source code in src/wcheck/wcheck.py
fetch_all(repos)
¶
Fetch all remotes for all repositories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repos
|
dict[str, Repo]
|
Dictionary mapping repository names to Repo objects. |
required |
Source code in src/wcheck/wcheck.py
GUI Module¶
show_gui(repos, config_file_path='', config_repo=None)
¶
Launch the GUI application for managing repositories.
Creates and displays the main WCheckGUI window. This function does not return as it enters the Qt event loop and exits the program when the window is closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repos
|
dict[str, Repo]
|
Dictionary mapping repository names to Repo objects. |
required |
config_file_path
|
str
|
Path to the configuration file (displayed in UI). |
''
|
config_repo
|
dict[str, str] | None
|
Dictionary mapping repository names to their configured versions. |
None
|
Source code in src/wcheck/gui.py
WCheckGUI
¶
Bases: QWidget
Main GUI window for wcheck application.
Displays a grid of repositories with their current branches and provides controls for switching branches and opening in editor.
Attributes:
| Name | Type | Description |
|---|---|---|
repo_objects |
Dictionary mapping repository names to RepoObject instances. |
Source code in src/wcheck/gui.py
__init__(repos, config_file_path='', config_repo=None)
¶
Initialize the WCheckGUI window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repos
|
dict[str, Repo]
|
Dictionary mapping repository names to Repo objects. |
required |
config_file_path
|
str
|
Path to the configuration file (displayed in UI). |
''
|
config_repo
|
dict[str, str] | None
|
Dictionary mapping repository names to their configured versions. |
None
|
Source code in src/wcheck/gui.py
initUI(repos, config_file_path='', config_repo=None)
¶
Initialize the user interface.
Creates the layout with repository controls including: - Repository name label - Branch selection combo box - Checkout button - Open in editor button - Config version label (if config_repo provided)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repos
|
dict[str, Repo]
|
Dictionary mapping repository names to Repo objects. |
required |
config_file_path
|
str
|
Path to the configuration file (displayed in UI). |
''
|
config_repo
|
dict[str, str] | None
|
Dictionary mapping repository names to their configured versions. |
None
|
Source code in src/wcheck/gui.py
RepoObject
¶
Represents a repository in the GUI with associated widgets and actions.
Manages the UI components for a single repository including: - Label showing repository name and status - Combo box for branch/tag selection - Checkout button to switch branches - Editor button to open in external editor
Attributes:
| Name | Type | Description |
|---|---|---|
repo |
The git repository object. |
|
repo_dirty |
Whether the repository has uncommitted changes. |
|
abs_path |
Absolute path to the repository. |
|
qlabel |
QLabel widget showing repository name. |
|
combo_box |
QComboBox widget for branch selection. |
|
checkout_button |
QPushButton to checkout selected branch. |
|
editor_button |
QPushButton to open repository in editor. |
|
active_branch |
Name of the currently active branch. |
Source code in src/wcheck/gui.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
__init__(repo, repo_name, ignore_remote=False)
¶
Initialize the RepoObject with repository and UI components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
Repo
|
Git repository object. |
required |
repo_name
|
str
|
Display name for the repository. |
required |
ignore_remote
|
bool
|
If True, exclude remote branches from the combo box. |
False
|
Source code in src/wcheck/gui.py
checkout_branch()
¶
Checkout the selected branch in the repository.
Handles both local and remote branch names, stripping the 'origin/' prefix from remote branches before checkout.
Source code in src/wcheck/gui.py
editor_button_pressed()
¶
Open the repository in an external editor.
Uses the EDITOR environment variable, defaulting to 'code' (VS Code).
Source code in src/wcheck/gui.py
selectionchange(index)
¶
Handle branch selection change in the combo box.
Enables the checkout button if a different branch is selected, disables it if the current branch is selected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index of the selected item in the combo box. |
required |