-
Notifications
You must be signed in to change notification settings - Fork 7
♻️ harmonize V2 CLI with other SDKs, add tests #432
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
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| name: Test Command Line Interface | ||
|
|
||
| on: | ||
| workflow_call: | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }} | ||
| MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }} | ||
| MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }} | ||
| MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }} | ||
| MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }} | ||
| MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }} | ||
| MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }} | ||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Run CLI tests | ||
| timeout-minutes: 30 | ||
| strategy: | ||
| max-parallel: 4 | ||
| matrix: | ||
| os: | ||
| - "ubuntu-22.04" | ||
| - "macos-latest" | ||
| - "windows-2022" | ||
| python-version: | ||
| - "3.10" | ||
| - "3.14" | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| submodules: recursive | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Cache dependencies | ||
| uses: actions/cache@v5 | ||
| with: | ||
| path: ~/.cache/pip | ||
| key: ${{ runner.os }}-cli-${{ hashFiles('**/pyproject.toml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-cli- | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install pip | ||
| pip install -e '.' | ||
|
|
||
| - name: Test V1 CLI | ||
| shell: sh | ||
| run: | | ||
| ./tests/test_v1_cli.sh ./tests/data/file_types/pdf/blank_1.pdf python | ||
|
|
||
| - name: Test V2 CLI | ||
| shell: sh | ||
| run: | | ||
| ./tests/test_v2_cli.sh ./tests/data/file_types/pdf/blank_1.pdf python | ||
|
|
||
| - name: Notify Slack Action on Failure | ||
| uses: ravsamhq/notify-slack-action@2.5.0 | ||
| if: ${{ always() && github.ref_name == 'main' }} | ||
| with: | ||
| status: ${{ job.status }} | ||
| notify_when: "failure" | ||
| notification_title: "[Python] CLI test '{workflow}' is failing" | ||
| env: | ||
| SLACK_WEBHOOK_URL: ${{ secrets.PRODUCTION_ISSUES_SLACK_HOOK_URL }} | ||
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 |
|---|---|---|
| @@ -1,7 +1,75 @@ | ||
| from mindee.v1.commands.cli_parser import MindeeParser | ||
| import logging | ||
| import sys | ||
|
|
||
| from mindee.v2.commands.cli_parser import MindeeParser | ||
|
|
||
| _V1_DASHV_PRODUCTS = ("custom", "generated") | ||
|
|
||
|
|
||
| def _find_v1_dashv_boundary(argv: list[str]) -> int | None: | ||
| """Locate the position after which ``-v`` belongs to V1 ``custom`` / | ||
| ``generated``. | ||
|
|
||
| These two V1 products register ``-v/--version``; tokens at or beyond | ||
| the returned index must be left alone by the verbose pre-scan. | ||
| """ | ||
| for i, token in enumerate(argv): | ||
| if token == "v1" and i + 1 < len(argv) and argv[i + 1] in _V1_DASHV_PRODUCTS: | ||
| return i + 2 | ||
| return None | ||
|
|
||
|
|
||
| def _extract_verbose_level(argv: list[str]) -> tuple[int, list[str]]: | ||
| """Pre-scan ``argv`` for ``--verbose`` / ``-v`` flags. | ||
|
|
||
| Mirrors ``mindee-api-dotnet``'s ``args.Contains("--verbose")`` check: | ||
| the flag is consumed before argparse runs so it can appear anywhere | ||
| on the command line. | ||
|
|
||
| * ``--verbose`` is consumed at any position (no conflict). | ||
| * ``-v`` is consumed at any position *except* after a ``v1 custom`` | ||
| or ``v1 generated`` invocation, where it is the V1 product's own | ||
| ``--version`` option. | ||
|
|
||
| :returns: ``(level, remaining_argv)`` where ``level`` counts the number | ||
| of recognized verbose-flag occurrences. | ||
| """ | ||
| level = 0 | ||
| remaining: list[str] = [] | ||
| v1_dashv_start = _find_v1_dashv_boundary(argv) | ||
| for i, token in enumerate(argv): | ||
| if token == "--verbose": | ||
| level += 1 | ||
| continue | ||
| if token == "-v" and (v1_dashv_start is None or i < v1_dashv_start): | ||
| level += 1 | ||
| continue | ||
| remaining.append(token) | ||
| return level, remaining | ||
|
|
||
|
|
||
| def _configure_logging(verbose_level: int) -> None: | ||
| """Set the ``mindee`` logger level based on the verbose count.""" | ||
| if verbose_level <= 0: | ||
| return | ||
| target = logging.INFO if verbose_level == 1 else logging.DEBUG | ||
| logging.getLogger("mindee").setLevel(target) | ||
| logging.getLogger().setLevel(target) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """Run the Command Line Interface.""" | ||
| """Run the Command Line Interface. | ||
|
|
||
| The unified ``mindee`` binary exposes V2 inference commands and the | ||
| ``search-models`` utility at the root, with all V1 product commands | ||
| wrapped under a ``v1`` subcommand — mirroring the canonical | ||
| ``mindee-api-dotnet`` CLI. | ||
|
|
||
| Pass ``--verbose`` (or ``-v``) to enable diagnostic logging; repeat | ||
| the flag (``--verbose --verbose``) for debug-level output. | ||
| """ | ||
| verbose_level, argv = _extract_verbose_level(sys.argv[1:]) | ||
| _configure_logging(verbose_level) | ||
| sys.argv = [sys.argv[0], *argv] | ||
| parser = MindeeParser() | ||
| parser.call_parse() | ||
| sys.exit(parser.call_parse() or 0) |
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 |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| from mindee.v1.commands.cli_parser import MindeeArgumentParser, MindeeParser | ||
| from mindee.v1.commands.cli_parser import ( | ||
| MindeeArgumentParser, | ||
| MindeeParser, | ||
| register_v1_product_subparsers, | ||
| ) | ||
| from mindee.v1.commands.cli_products import PRODUCTS, CommandConfig | ||
|
|
||
| __all__ = [ | ||
| "PRODUCTS", | ||
| "CommandConfig", | ||
| "MindeeArgumentParser", | ||
| "MindeeParser", | ||
| "register_v1_product_subparsers", | ||
| ] |
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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
| from mindee.v2.commands.base_inference_command import BaseInferenceCommand | ||
| from mindee.v2.commands.classification_command import ClassificationCommand | ||
| from mindee.v2.commands.cli_parser import MindeeArgumentParser, MindeeParser | ||
| from mindee.v2.commands.crop_command import CropCommand | ||
| from mindee.v2.commands.extraction_command import ExtractionCommand | ||
| from mindee.v2.commands.ocr_command import OcrCommand | ||
| from mindee.v2.commands.output_type import OutputType | ||
| from mindee.v2.commands.search_models_command import SearchModelsCommand | ||
| from mindee.v2.commands.split_command import SplitCommand | ||
|
|
||
| __all__ = [ | ||
| "BaseInferenceCommand", | ||
| "ClassificationCommand", | ||
| "CropCommand", | ||
| "ExtractionCommand", | ||
| "MindeeArgumentParser", | ||
| "MindeeParser", | ||
| "OcrCommand", | ||
| "OutputType", | ||
| "SearchModelsCommand", | ||
| "SplitCommand", | ||
| ] |
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.