-
Notifications
You must be signed in to change notification settings - Fork 1
Add vws generate-vumark command #1968
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
Open
adamtheturtle
wants to merge
28
commits into
main
Choose a base branch
from
adamtheturtle/add-vumark-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9557e6d
Add VuMark instance generation CLI command
adamtheturtle c6e1cce
Update VuMark implementation to match vws-python#2858
adamtheturtle d878070
Parametrize format tests in test_vumark
adamtheturtle c0e55a9
Fix mypy errors for not-yet-available VWS method
adamtheturtle b78ce9d
Use VuMarkService instead of VWS for generate_vumark_instance
adamtheturtle 3d8c3f8
Fix pylint errors in test_vumark
adamtheturtle 26d1aef
Add VuMark-related words to spelling private dictionary
adamtheturtle d8f51fe
Make VuMark a standalone binary instead of a vws subcommand
adamtheturtle de61662
Mark VuMark tests as xfail where mock-vws lacks support
adamtheturtle 9a0645c
test: replace VuforiaDatabase usage with CloudDatabase
adamtheturtle 35c392e
Add vumark binary release support and fix vumark error handling
adamtheturtle 18fbed1
Fix mypy typing for vumark error message fallback
adamtheturtle a9d9199
Fix pyright issues in vumark error mapping and tests
adamtheturtle d990a76
test: refactor vumark tests to use monkeypatching instead of real API…
adamtheturtle 74b7463
fix: use VuMarkService from vws directly for monkeypatching in tests
adamtheturtle bd396f9
fix: handle InvalidTargetTypeError in vumark error message mapping
adamtheturtle 2f1b198
test: convert test_unknown_target to use monkeypatching instead of xfail
adamtheturtle d431ce1
test: simplify vumark tests to use mock-vws directly
adamtheturtle 2f90368
test: remove unused vumark_client fixture to restore 100% coverage
adamtheturtle a506270
fix: restore pytest ini_options and disable capture for Click compati…
adamtheturtle 4da5c7a
refactor: inline _get_vumark_error_message and test at integration level
adamtheturtle 6cefd3f
fix: suppress pylint no-member for exc.target_id after isinstance nar…
adamtheturtle f13f4ce
fix: rename _get_error_message to get_error_message to satisfy pyright
adamtheturtle 38c41cc
refactor: replace isinstance narrowing with two except clauses in vumark
adamtheturtle 112b0b0
test: assert on actual output in test_invalid_format
adamtheturtle 6d1bd9b
revert: reset pyproject.toml to match main
adamtheturtle fb97257
fix: remove unused imports from vumark.py
adamtheturtle a8c6497
test: replace xfail with monkeypatched tests and remove pragma no cover
adamtheturtle 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """Run VuMark generation CLI.""" | ||
|
|
||
| from vws_cli.vumark import generate_vumark | ||
|
|
||
| generate_vumark() |
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,151 @@ | ||
| """``click`` command for VuMark generation.""" | ||
|
|
||
| import contextlib | ||
| import sys | ||
| from collections.abc import Iterator | ||
| from enum import StrEnum, unique | ||
| from pathlib import Path | ||
|
|
||
| import click | ||
| from beartype import beartype | ||
| from vws import VuMarkService | ||
| from vws.exceptions.base_exceptions import VWSError | ||
| from vws.exceptions.custom_exceptions import ServerError | ||
| from vws.exceptions.vws_exceptions import ( | ||
| InvalidInstanceIdError, | ||
| TargetStatusNotSuccessError, | ||
| UnknownTargetError, | ||
| ) | ||
| from vws.vumark_accept import VuMarkAccept | ||
|
|
||
| from vws_cli import __version__ | ||
| from vws_cli._error_handling import get_error_message | ||
| from vws_cli.options.credentials import ( | ||
| server_access_key_option, | ||
| server_secret_key_option, | ||
| ) | ||
| from vws_cli.options.targets import target_id_option | ||
| from vws_cli.options.timeout import ( | ||
| connection_timeout_seconds_option, | ||
| read_timeout_seconds_option, | ||
| ) | ||
| from vws_cli.options.vws import base_vws_url_option | ||
|
|
||
|
|
||
| @beartype | ||
| @unique | ||
| class VuMarkFormatChoice(StrEnum): | ||
| """Choices for the VuMark output format.""" | ||
|
|
||
| PNG = "png" | ||
| SVG = "svg" | ||
| PDF = "pdf" | ||
|
|
||
|
|
||
| _FORMAT_CHOICE_TO_ACCEPT: dict[VuMarkFormatChoice, VuMarkAccept] = { | ||
| VuMarkFormatChoice.PNG: VuMarkAccept.PNG, | ||
| VuMarkFormatChoice.SVG: VuMarkAccept.SVG, | ||
| VuMarkFormatChoice.PDF: VuMarkAccept.PDF, | ||
| } | ||
|
|
||
|
|
||
| @beartype | ||
| @contextlib.contextmanager | ||
| def _handle_vumark_exceptions() -> Iterator[None]: | ||
| """Show error messages and catch exceptions from ``VWS-Python``.""" | ||
| error_message = "" | ||
|
|
||
| try: | ||
| yield | ||
| except (UnknownTargetError, TargetStatusNotSuccessError) as exc: | ||
| if isinstance(exc, UnknownTargetError): | ||
| error_message = f'Error: Target "{exc.target_id}" does not exist.' | ||
| else: | ||
| error_message = ( | ||
| f'Error: The target "{exc.target_id}" is not in the success ' | ||
| "state and cannot be used to generate a VuMark instance." | ||
| ) | ||
| except (VWSError, ServerError) as exc: | ||
| if isinstance(exc, InvalidInstanceIdError): | ||
| error_message = "Error: The given instance ID is invalid." | ||
| else: | ||
| error_message = get_error_message(exc=exc) | ||
| else: | ||
| return | ||
|
|
||
| click.echo(message=error_message, err=True) | ||
| sys.exit(1) | ||
|
|
||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @click.command(name="vumark") | ||
| @server_access_key_option | ||
| @server_secret_key_option | ||
| @target_id_option | ||
| @click.option( | ||
| "--instance-id", | ||
| type=str, | ||
| required=True, | ||
| help="The instance ID to encode in the VuMark.", | ||
| ) | ||
| @click.option( | ||
| "--format", | ||
| "format_choice", | ||
| type=click.Choice(choices=VuMarkFormatChoice, case_sensitive=False), | ||
| default=VuMarkFormatChoice.PNG.lower(), | ||
| help="The output format for the generated VuMark.", | ||
| show_default=True, | ||
| ) | ||
| @click.option( | ||
| "--output", | ||
| "output_file_path", | ||
| type=click.Path( | ||
| dir_okay=False, | ||
| writable=True, | ||
| path_type=Path, | ||
| ), | ||
| required=True, | ||
| help="The path to write the generated VuMark to.", | ||
| ) | ||
| @_handle_vumark_exceptions() | ||
| @base_vws_url_option | ||
| @connection_timeout_seconds_option | ||
| @read_timeout_seconds_option | ||
| @click.version_option(version=__version__) | ||
| @beartype | ||
| def generate_vumark( | ||
| *, | ||
| server_access_key: str, | ||
| server_secret_key: str, | ||
| target_id: str, | ||
| instance_id: str, | ||
| format_choice: VuMarkFormatChoice, | ||
| output_file_path: Path, | ||
| base_vws_url: str, | ||
| connection_timeout_seconds: float, | ||
| read_timeout_seconds: float, | ||
| ) -> None: | ||
| """Generate a VuMark instance. | ||
|
|
||
| \b | ||
| See | ||
| https://developer.vuforia.com/library/vuforia-engine/web-api/vumark-generation-web-api/ | ||
| """ | ||
| vumark_client = VuMarkService( | ||
| server_access_key=server_access_key, | ||
| server_secret_key=server_secret_key, | ||
| base_vws_url=base_vws_url, | ||
| request_timeout_seconds=( | ||
| connection_timeout_seconds, | ||
| read_timeout_seconds, | ||
| ), | ||
| ) | ||
|
|
||
| accept = _FORMAT_CHOICE_TO_ACCEPT[format_choice] | ||
|
|
||
| vumark_data = vumark_client.generate_vumark_instance( | ||
| target_id=target_id, | ||
| instance_id=instance_id, | ||
| accept=accept, | ||
| ) | ||
|
|
||
| output_file_path.write_bytes(data=vumark_data) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
scripts.vumarkentry inpyproject.tomlbreaks DockerHigh Severity
The documentation tells users to run
docker run --rm --entrypoint vumark ..., butpyproject.tomlis missing ascripts.vumarkentry (onlyscripts.vwsandscripts.vuforia-cloud-recoexist). The Docker image installs the package viauv pip install, which only creates console scripts declared inpyproject.toml. Withoutscripts.vumark = "vws_cli.vumark:generate_vumark", thevumarkcommand won't exist in the Docker image or any pip-based installation, making all the Docker documentation and pip usage broken.Additional Locations (1)
docs/source/install.rst#L63-L69