-
Notifications
You must be signed in to change notification settings - Fork 452
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
cli: add inspect subcommand #2184
cli: add inspect subcommand #2184
Conversation
There are three features that would be useful to snapcraft CLI developers that are not supported today: 1. A quick-look summary of the current project state. 2. A way to determine which lifecycle step of which part was most recently completed. 3. A way to determine which part provided a specific file within the staging or priming area. Add support for all three of these use-cases by introducing a new, hidden subcommand called `inspect`. 1. `snapcraft inspect` will print a quick summary of the current project state. 2. `snapcraft inspect --latest-step` will print the part, step, and timestamp of the latest step that was run. 3. `snapcraft inspect --provides <path>` will print the part that provided the path. Default to human-readable output, but also support a `--json` to print json for programmatic consumption. LP: #1759700 Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
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.
Code looks clean and readable, nice.
There seems to be a problem when running on a not yet run project
(snapcraft) ubuntu@snapcraft-xenial-dev:~/source/make-hello$ snapcraft inspect --latest-step
Sorry, Snapcraft ran into an error when trying to running through its
lifecycle that generated the following traceback:
Traceback (most recent call last):
File "/home/ubuntu/venv/snapcraft/bin/snapcraft", line 9, in <module>
load_entry_point('snapcraft', 'console_scripts', 'snapcraft')()
File "/home/ubuntu/venv/snapcraft/lib/python3.5/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/ubuntu/venv/snapcraft/lib/python3.5/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/ubuntu/venv/snapcraft/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/ubuntu/venv/snapcraft/lib/python3.5/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/ubuntu/venv/snapcraft/lib/python3.5/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/ubuntu/source/snapcraft/snapcraft/cli/parts.py", line 157, in inspect
step.name,
AttributeError: 'NoneType' object has no attribute 'name'
(snapcraft) ubuntu@snapcraft-xenial-dev:~/source/make-hello$ ls
Makefile make-hello_0.1_amd64.snap snapcraft.yaml test.c
(snapcraft) ubuntu@snapcraft-xenial-dev:~/source/make-hello$ snapcraft pull
Pulling make-project
(snapcraft) ubuntu@snapcraft-xenial-dev:~/source/make-hello$ snapcraft inspect --latest-step
The latest step that was run is the 'pull' step of the 'make-project' part, which ran at Mon Jul 30 23:02:34 2018
(snapcraft) ubuntu@snapcraft-xenial-dev:~/source/make-hello$ snapcraft inspect --latest-step --json
{
"part": "make-project",
"step": "pull",
"timestamp": 1532991754.221821
}
For the json output at least we would need to get the working directory for that step too.
Great work so far
snapcraft/cli/parts.py
Outdated
if option: | ||
count += 1 | ||
|
||
if count > 1: |
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.
I wonder if it is worth expanding click like in this last comment on this issue pallets/click#257
Totally not a requirement for this PR, just a thought.
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.
I think this is simple enough not to warrant more code, but if we find we need this functionality elsewhere, it may be worth doing.
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
Whoops, sorry, that was silly. Fixed.
Sure, also fixed. |
Codecov Report
@@ Coverage Diff @@
## master #2184 +/- ##
==========================================
+ Coverage 91.19% 91.21% +0.02%
==========================================
Files 202 208 +6
Lines 12992 13160 +168
Branches 1922 1957 +35
==========================================
+ Hits 11848 12004 +156
- Misses 776 788 +12
Partials 368 368
Continue to review full report at Codecov.
|
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
…_inspect_subcommand
snapcraft/internal/errors.py
Outdated
@@ -185,6 +185,18 @@ class SnapcraftPartMissingError(SnapcraftError): | |||
) | |||
|
|||
|
|||
class NoSuchFileError(SnapcraftError): |
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.
the error message seems to specific for this class' name. How about NoSuchFileInPartError
.
These messages as with ToolError are getting a bit too un-namespaced btw. We should fix that.
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.
sorry, but I just have to https://twitter.com/JenMsft/status/1027018324037623810
snapcraft/internal/errors.py
Outdated
super().__init__(path=path) | ||
|
||
|
||
class UntrackedFileError(SnapcraftInspectError): |
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.
this is specific to parts too
snapcraft/internal/errors.py
Outdated
super().__init__(path=path) | ||
|
||
|
||
class NoStepsRunError(SnapcraftInspectError): |
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.
ok, I see the pattern, we should prepend SnapcraftInspect to the class names (or put them in their own inspect package with most of the logic in the cli
@@ -126,24 +126,27 @@ def __init__( | |||
|
|||
def get_pull_state(self) -> states.PullState: | |||
if not self._pull_state: | |||
self._pull_state = states.get_state(self.plugin.statedir, steps.PULL) | |||
self._pull_state = cast(states.PullState, self.get_state(steps.PULL)) |
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.
why is this necessary?
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.
Because this PR adds static checks to the return type of get_state
. This now means casting if it's a child class.
snapcraft/cli/parts.py
Outdated
return (latest_part, latest_step, latest_timestamp) | ||
|
||
|
||
def _lifecycle_status(config): |
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.
Move to package in project_loader and get rid of config.
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.
Done.
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
58385a5
to
34a15c7
Compare
…_inspect_subcommand Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
c178e4d
to
ce88a59
Compare
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
…_inspect_subcommand
./runtests.sh static
?./runtests.sh unit
?There are three features that would be useful to snapcraft CLI developers that are not supported today:
This PR resolves LP: #1759700 by adding support for all three of these use-cases by introducing a new, hidden subcommand called
inspect
.snapcraft inspect
will print a quick summary of the current project state.snapcraft inspect --latest-step
will print the part, step, and timestamp of the latest step that was run.snapcraft inspect --provides <path>
will print the part that provided the path.Default to human-readable output, but also support a
--json
to print json for programmatic consumption.