Repository navigation
Update built action to include new field: EntityUsage, Add mp self update, add mp --version #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4d99370
Update built action to include new field: EntityUsage
TalShafir1 cb812f7
Add '--version' and '-V' options to mp to display the current version
TalShafir1 d878bdb
improve action attr naming (EntitiesTypes -> EntityType)
TalShafir1 564af2d
Update ruff issues
TalShafir1 9aa233c
Merge branch 'main' into mp/add-entity-types-to-actiondef
TalShafir1 4b662d9
remove mistake added in the last commit
TalShafir1 ff34c36
Fix build to add the entity types to actiondef and enhance entity sel…
TalShafir1 173673f
Add message for checking mp is up to date
TalShafir1 9b8d53c
Add mp self update
TalShafir1 460891f
Merge branch 'main' into mp/add-entity-types-to-actiondef
TalShafir1 2b47c16
Fix gemini comments
TalShafir1 238c86a
Add 'self_update' command to constants
TalShafir1 48168d5
Refactor main function by removing app initialization
TalShafir1 5c54a58
Enhance main function docstring for clarity
TalShafir1 af4ce5b
Simplify raise statement in typer_app.py
TalShafir1 7e73f83
Add telemetry on the 'self-update' command
TalShafir1 5944f6d
Fix comments
TalShafir1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import dataclasses | ||
| import importlib.metadata | ||
| import threading | ||
| import tomllib | ||
| from contextlib import suppress | ||
| from typing import Any | ||
|
|
||
| import requests | ||
| import rich | ||
| import typer | ||
| from packaging.version import InvalidVersion | ||
| from packaging.version import parse as parse_version | ||
|
|
||
| PYPROJECT_URL: str = ( | ||
| "https://raw.githubusercontent.com/chronicle/content-hub/main/packages/mp/pyproject.toml" | ||
| ) | ||
| TIMEOUT_SECONDS: float = 2.0 | ||
|
|
||
|
|
||
| class UpdateChecker: | ||
| __slots__ = ("_check_thread", "_new_version") | ||
|
|
||
| def __init__(self) -> None: | ||
| self._new_version: str | None = None | ||
| self._check_thread: threading.Thread | None = None | ||
|
|
||
| def start_background_check(self, current_version: str) -> None: | ||
| """Start a background thread to check for updates.""" | ||
| if current_version == "unknown": | ||
| return | ||
|
|
||
| self._check_thread = threading.Thread( | ||
| target=self._check_update_worker, | ||
| args=(current_version,), | ||
| ) | ||
| self._check_thread.daemon = True | ||
| self._check_thread.start() | ||
|
|
||
| def print_warning_if_needed(self) -> None: | ||
| """Print a warning if a newer version is available.""" | ||
| if self._check_thread and self._check_thread.is_alive(): | ||
| self._check_thread.join(timeout=0.5) | ||
|
|
||
| if self._new_version: | ||
| _print_version_warning(self._new_version) | ||
|
|
||
| def _check_update_worker(self, current_version: str) -> None: | ||
| with suppress( | ||
| requests.RequestException, | ||
| requests.HTTPError, | ||
| tomllib.TOMLDecodeError, | ||
| KeyError, | ||
| InvalidVersion, | ||
| ): | ||
| response: requests.Response = requests.get(PYPROJECT_URL, timeout=TIMEOUT_SECONDS) | ||
| response.raise_for_status() | ||
| data: dict[str, Any] = tomllib.loads(response.text) | ||
| remote_version: str | None = data.get("project", {}).get("version") | ||
|
|
||
| if remote_version and parse_version(remote_version) > parse_version(current_version): | ||
| self._new_version = remote_version | ||
|
|
||
|
|
||
| def _print_version_warning(remote_version: str) -> None: | ||
| current_version: str = get_mp_version() | ||
| message: str = ( | ||
| f"\n[bold yellow]WARNING:[/bold yellow] A newer version of mp " | ||
| f"({current_version} -> {remote_version}) is available.\n" | ||
| f"Run 'mp self update' to update.\n" | ||
| ) | ||
| rich.print(message) | ||
|
|
||
|
|
||
| def print_mp_version(*, value: bool) -> None: | ||
| """Print the current version of the mp tool. | ||
|
|
||
| Raises: | ||
| typer.Exit: If the version is printed. | ||
|
|
||
| """ | ||
| if value: | ||
| version: str = get_mp_version() | ||
| rich.print(f"mp {version}") | ||
| raise typer.Exit | ||
|
|
||
|
|
||
| def get_mp_version() -> str: | ||
| """Get the current version of mp. | ||
|
|
||
| Returns: | ||
| str: The current version of mp. | ||
|
|
||
| """ | ||
| try: | ||
| return importlib.metadata.version("mp") | ||
| except importlib.metadata.PackageNotFoundError: | ||
| return "unknown" | ||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True, slots=True) | ||
| class AppState: | ||
| update_checker: UpdateChecker = dataclasses.field(default_factory=UpdateChecker) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.