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
efiop
left a comment
There was a problem hiding this comment.
Looks amazing! 🔥
Just a few minor comments left.
bf4fe8a to
c373811
Compare
c373811 to
abcb2af
Compare
pared
left a comment
There was a problem hiding this comment.
Looks good! One comment, more of a question, than a suggestion.
abcb2af to
6a99580
Compare
Suor
left a comment
There was a problem hiding this comment.
A couple of bugs, some small optimization and cosmetics.
There was a problem hiding this comment.
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.
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.
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.
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.
@Suor it was an open question - could you please provide the case when it can happen?
There was a problem hiding this comment.
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.
1b3ac41 to
5f8b409
Compare
5f8b409 to
f0a269c
Compare
skshetry
left a comment
There was a problem hiding this comment.
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.
| 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.
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.
@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.
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.
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.
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.
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. 🙏