-
Notifications
You must be signed in to change notification settings - Fork 39
Draft: Feature: Add support for generating json from bst show command #2030
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,14 +14,15 @@ | |
| import os | ||
| import re | ||
| import sys | ||
| import json | ||
| from functools import partial | ||
|
|
||
| import shutil | ||
| import click | ||
| from .. import _yaml | ||
| from .._exceptions import BstError, LoadError, AppError, RemoteError | ||
| from .complete import main_bashcomplete, complete_path, CompleteUnhandled | ||
| from ..types import _CacheBuildTrees, _SchedulerErrorAction, _PipelineSelection, _HostMount, _Scope | ||
| from ..types import _CacheBuildTrees, _ElementKind, _SchedulerErrorAction, _PipelineSelection, _HostMount, _Scope | ||
| from .._remotespec import RemoteSpec, RemoteSpecPurpose | ||
| from ..utils import UtilError | ||
|
|
||
|
|
@@ -74,6 +75,7 @@ def __repr__(self): | |
| # Override of click's main entry point # | ||
| ################################################################## | ||
|
|
||
|
|
||
| # search_command() | ||
| # | ||
| # Helper function to get a command and context object | ||
|
|
@@ -538,6 +540,7 @@ def build( | |
| @click.option( | ||
| "--except", "except_", multiple=True, type=click.Path(readable=False), help="Except certain dependencies" | ||
| ) | ||
| @click.option("--json", "as_json", is_flag=True, help="Output the information as machine readable JSON") | ||
| @click.option( | ||
| "--deps", | ||
| "-d", | ||
|
|
@@ -552,7 +555,29 @@ def build( | |
| _PipelineSelection.ALL, | ||
| ], | ||
| ), | ||
| help="The dependencies to show", | ||
| help="Types of Elements to Show", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep the old description. "Types of elements" doesn't make sense here. |
||
| ) | ||
| @click.option( | ||
| "--kind", | ||
| "-k", | ||
| default=[], | ||
| show_default=True, | ||
| multiple=True, | ||
| type=FastEnumType( | ||
| _ElementKind, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Element Kind" is definitely not how you should name this. The element kind is already a concept in buildstream, and it's not this. I don't know what would be the best way to name this option though. info? keys? Let's wait for other maintainer's opinions, they might have a better idea. |
||
| [ | ||
| _ElementKind.ALL, | ||
| _ElementKind.KEY, | ||
| _ElementKind.KEY_FULL, | ||
| _ElementKind.STATE, | ||
| _ElementKind.SOURCES, | ||
| _ElementKind.DEPENDENCIES, | ||
| _ElementKind.BUILD_DEPENDENCIES, | ||
| _ElementKind.RUNTIME_DEPENDENCIES, | ||
| _ElementKind.CAS_ARTIFACTS, | ||
| ], | ||
| ), | ||
| help="Kinds of element information to display in JSON", | ||
| ) | ||
| @click.option( | ||
| "--order", | ||
|
|
@@ -572,7 +597,7 @@ def build( | |
| ) | ||
| @click.argument("elements", nargs=-1, type=click.Path(readable=False)) | ||
| @click.pass_obj | ||
| def show(app, elements, deps, except_, order, format_): | ||
| def show(app, elements, deps, as_json, except_, order, kind, format_): | ||
| """Show elements in the pipeline | ||
|
|
||
| Specifying no elements will result in showing the default targets | ||
|
|
@@ -629,19 +654,44 @@ def show(app, elements, deps, except_, order, format_): | |
| \b | ||
| bst show target.bst --format \\ | ||
| $'---------- %{name} ----------\\n%{vars}' | ||
|
|
||
| **JSON OUTPUT** | ||
|
|
||
| The ``--json`` flag will cause bst to output information in machine readable | ||
| JSON. When using this flag you may also specify ``--kind`` to control the | ||
| type of information that is output. | ||
|
|
||
| To dump everything: | ||
| \b | ||
| bst show --json --kind all | ||
| """ | ||
| with app.initialized(): | ||
|
|
||
| if as_json and format_: | ||
| raise AppError("--format and --json are mutually exclusive") | ||
|
|
||
| if format_ and kind: | ||
| raise AppError("--format does not support --kind") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I like this error message, as I see Maybe we could change it such that Let's wait for other opinions. |
||
|
|
||
| if not format_: | ||
| format_ = app.context.log_element_format | ||
|
|
||
| # First determine whether we need to go about querying the local cache | ||
| # and spending time setting up remotes. | ||
| state_match = re.search(r"%(\{(state)[^%]*?\})", format_) | ||
| key_match = re.search(r"%(\{(key)[^%]*?\})", format_) | ||
| full_key_match = re.search(r"%(\{(full-key)[^%]*?\})", format_) | ||
| artifact_cas_digest_match = re.search(r"%(\{(artifact-cas-digest)[^%]*?\})", format_) | ||
| need_state = bool(state_match or key_match or full_key_match or artifact_cas_digest_match) | ||
| need_state = False | ||
| if not as_json: | ||
| state_match = re.search(r"%(\{(state)[^%]*?\})", format_) | ||
| key_match = re.search(r"%(\{(key)[^%]*?\})", format_) | ||
| full_key_match = re.search(r"%(\{(full-key)[^%]*?\})", format_) | ||
| artifact_cas_digest_match = re.search(r"%(\{(artifact-cas-digest)[^%]*?\})", format_) | ||
| need_state = bool(state_match or key_match or full_key_match or artifact_cas_digest_match) | ||
| else: | ||
| need_state = bool( | ||
| _ElementKind.STATE in kind | ||
| or _ElementKind.KEY in kind | ||
| or _ElementKind.KEY_FULL in kind | ||
| or _ElementKind.CAS_ARTIFACTS in kind | ||
| ) | ||
|
|
||
| if not elements: | ||
| elements = app.project.get_default_targets() | ||
|
|
@@ -657,8 +707,12 @@ def show(app, elements, deps, except_, order, format_): | |
| if order == "alpha": | ||
| dependencies = sorted(dependencies) | ||
|
|
||
| report = app.logger.show_pipeline(dependencies, format_) | ||
| click.echo(report) | ||
| if as_json: | ||
| serialized = app.logger.dump_pipeline(dependencies, kind) | ||
| print(json.dumps(serialized)) | ||
| else: | ||
| report = app.logger.show_pipeline(dependencies, format_) | ||
| click.echo(report) | ||
|
|
||
|
|
||
| ################################################################## | ||
|
|
||
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.
It would be nice to have a similar option that outputs YAML, as that's what buildstream uses.