-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
list: colorize output #3351
list: colorize output #3351
Conversation
ceafb40
to
5dcca67
Compare
@JIoJIaJIu Btw, we've been thinking about |
5dcca67
to
0874a8a
Compare
0874a8a
to
8d75fa2
Compare
cd07166
to
d4b0194
Compare
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.
Looks amazing! π₯
Just a few minor comments left.
bf4fe8a
to
c373811
Compare
c373811
to
abcb2af
Compare
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.
Looks good! One comment, more of a question, than a suggestion.
abcb2af
to
6a99580
Compare
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.
A couple of bugs, some small optimization and cosmetics.
from dvc.compat import fspath | ||
|
||
if out: | ||
isdir = out.is_dir_checksum if out.checksum else False |
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.
If there is no checksum it might still be dir, I would write a note here about this edge case. Now the code looks quirky for no apparent reason.
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.
As I got if out.checksum
is missed than out.is_dir_checksum
fails
Do you have thoughts how can it be improved?
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.
Yeah, it fails, we don't really know whether that is a dir. We may just say about this limitation in a comment.
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.
we don't really know whether that is a dir
In what case the out can be dir but doesn't have checksum
?
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.
Yes.
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.
@Suor it was an open question - could you please provide the case when it can happen?
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.
When a user edits a .dvc
file and deletes the output checksum there. This is not as weird as it might sound, people may want to do that to recalc the checksum from the actual dir they have.
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.
1b3ac41
to
5f8b409
Compare
5f8b409
to
f0a269c
Compare
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.
Looks good. π₯ Just a few suggestions.
def _prettify(entries, with_color=False): | ||
if with_color: | ||
ls_colors = LsColors() | ||
fmt = ls_colors.format | ||
else: | ||
|
||
def fmt(entry): | ||
return entry["path"] | ||
|
||
return [fmt(entry) for entry in entries] | ||
|
||
|
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.
def _prettify(entries, with_color=False): | |
if with_color: | |
ls_colors = LsColors() | |
fmt = ls_colors.format | |
else: | |
def fmt(entry): | |
return entry["path"] | |
return [fmt(entry) for entry in entries] | |
def _prettify(entries, with_color=False): | |
def fmt(entry): | |
return entry["path"] | |
if with_color: | |
ls_colors = LsColors() | |
fmt = ls_colors.format | |
return [fmt(entry) for entry in entries] |
Or, maybe, even use a lambda?
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've remembered why I did it as it is
with lambda there is an E371 style error
def _prettify(entries, with_color=False):
if with_color:
ls_colors = LsColors()
fmt = ls_colors.format
else:
fmt = lambda entry: entry["path"]
return [fmt(entry) for entry in entries]
dvc/command/ls/__init__.py:17:5: E731 do not assign a lambda expression, use a def
Unfortunately with you suggestion I am getting F811
def _prettify(entries, with_color=False):
def fmt(entry):
return entry["path"]
if with_color:
ls_colors = LsColors()
fmt = ls_colors.format
return [fmt(entry) for entry in entries]
dvc/command/ls/__init__.py:20:9: F811 redefinition of unused 'fmt' from line 15
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.
@JIoJIaJIu, It's fine to ignore redefinition warnings (it's what I suggested). But, I'm fine as-is, it's only a suggestion.
def colorize(ls_colors): | ||
def _colorize(f, spec=""): | ||
fs_path = { | ||
"path": f, | ||
"isexec": "e" in spec, | ||
"isdir": "d" in spec, | ||
"isout": "o" in spec, | ||
} | ||
return ls_colors.format(fs_path) | ||
|
||
return _colorize |
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'd be one less redirection if we just did following on all of the tests:
ls_colors.format({"path": f, "isexec": True})
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.
Thank you @skshetry for the point!
The changes came from the comment #3351 (comment) in terms of making tests more readable
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.
Are other keys mandatory? If they aren't, I don't really think there's any need for redirection.
If they are, you can just:
shape = {
"isexec": False,
"isdir": False,
"isout": False,
}
ls_colors.format({"path": f, **shape, "isexec": True})
But, I'm fine with it as well. But, one less redirection would be great.
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.
Are other keys mandatory?
Nope, there are not. In fact before the comment my tests were as you described
I don't see the problem with additional step here (redirection you mean). I think it makes sense not to add additional functionality related to tests only, but let it keep here cause it's thin enough
@JIoJIaJIu @skshetry So what about the changes/questions above? |
@efiop, I have already approved. It was just a few suggestions. I'm fine as-is. |
Close #3347
β Have you followed the guidelines in the Contributing to DVC list?
π Check this box if this PR does not require documentation updates, or if it does and you have created a separate PR in dvc.org with such updates (or at least opened an issue about it in that repo). Please link below to your PR (or issue) in the dvc.org repo.
β Have you checked DeepSource, CodeClimate, and other sanity checks below? We consider their findings recommendatory and don't expect everything to be addressed. Please review them carefully and fix those that actually improve code or fix bugs.
Thank you for the contribution - we'll try to review it as soon as possible. π