Uh oh!
There was an error while loading. Please reload this page.
output generator - #13
Conversation
4371c7a to
1da434bCompareCodecov Report
@@ Coverage Diff @@## master #13 +/- ##
=====================================
Coverage 100% 100% =====================================
Files 10 10 Lines 268 276 +8 =====================================
+ Hits 268 276 +8
Continue to review full report at Codecov.
|
tsroten
commented
Jun 19, 2017
@meeuw 👍 I like this! I'm going to look at the format number updates that Irina made and then I'll take a look at this. |
| output.append('\n') | ||
| return ''.join(output) | ||
| yield _get_separator(i, sep_title, sep_character, sep_length) + result + '\n' |
There was a problem hiding this comment.
@meeuw I don't think we need the newline character any longer since we're returning each record separately. It's now the client code's job to insert a newline between each record. Then you can remove the extra blank line you had to add to the tests.
tsroten
commented
Jun 19, 2017
@meeuw Other than that comment I made, this looks good to me. Great job! So, what about the tabulate and delimited output adapters? Since this is a breaking change (mycli doesn't work without a change to support this), we're going to need to bump the version of CLI Helpers to 1.0. Plus, we need to consider pgcli as well, which will soon depend on CLI Helpers. I'm thinking we'll release v0.2 of CLI Helpers with the format_numbers and style_output change. Along with updating mycli to depend on |
1da434b to
48b816fComparemeeuw
commented
Jun 19, 2017
Hmm the changes I've made in mycli are made so it doesn't break with the current version of cli_helpers (but supports the changes in this branch). But maybe it's indeed better to only return generators/iterators from cli_helpers. I'm all in for doing this for the 1.0 release, that will give us some time to update the other output adapters to return generators. |
tsroten
commented
Jun 19, 2017
@meeuw Ok, that sounds good. So, we can push the mycli change out with the next release so it will be ready whenever cli_helpers 1.0 is released. |
tsroten
commented
Jun 19, 2017
@meeuw I do think we should return a consistent format from CLI Helpers. |
48b816f to
9824a19Compare9824a19 to
1bfd86bCompare9312a28 to
61800c7Compare| l.reset() | ||
| writer.writerow(headers) | ||
| for line in l.lines: | ||
| yield line[:-1] |
There was a problem hiding this comment.
Rather than stripping the newline by index, we can tell the csv module not to add newlines at all.
On line 32:
ckwargs= {'delimiter': delimiter, 'lineterminator': ''}There was a problem hiding this comment.
Also, lineterminator needs to be removed from line 23 since client code should not be able to specify a line ending (since we return a generator with no newlines).
| writer = csv.writer(l, **ckwargs) | ||
| l.reset() | ||
| writer.writerow(headers) | ||
| for line in l.lines: |
There was a problem hiding this comment.
What about putting the loop and yield in a linewriter.readlines() function?
There was a problem hiding this comment.
I don't think that's possible without leaving a loop in adapter (yield is bound to the function/method as far as I know). I've removed the loop; I assume every writerow directly calls our write function (with all the data we've supplied).
| class linewriter(): | ||
| def reset(self): | ||
| self.lines = [] |
There was a problem hiding this comment.
Since linewriter requires the lines attribute to work, it should create that attribute on instantiation. reset() can be used to clear the lines.
Also, in Python 3, classes are always new-style. Just to be safe we should probably make this a new-style class in Python 2: class linewriter(object):
tsroten
commented
Aug 9, 2017
@meeuw I'm thinking we should make all the adapters return generators instead of just lists (for tabulate/terminaltable). What do you think? |
5248c36 to
4578e32Comparemeeuw
commented
Aug 10, 2017
Hmm it doesn't add anything but I think you're right that it's better to have consistent output. pgcli also needs changes before it can use cli_helpers, I'll try to create a PR for pgcli as well. |
meeuw
commented
Aug 10, 2017
| l = linewriter() | ||
| writer = csv.writer(l, **ckwargs) | ||
| writer.writerow(headers) | ||
| yield l.line |
| t.padding_left, | ||
| t.padding_right)[:3] | ||
| for row in t.gen_table(*dimensions): | ||
| yield ''.join(''.join(row)) |
There was a problem hiding this comment.
Is there an extra join here? From what I can tell, it looks like a single join is all that's needed.
There was a problem hiding this comment.
Yes, "row" is a bit confusing because it's not a row; I've copied this from:
https://github.com/Robpol86/terminaltables/blob/master/terminaltables/build.py#L151
It is called by https://github.com/Robpol86/terminaltables/blob/master/terminaltables/base_table.py#L217
I'll have a look if I can replace this by itertools.chain.from_iterable
There was a problem hiding this comment.
I think they are using two joins because they join the pieces of the row together, then they join all the rows together.
We only need to join the pieces of the row together. If you put logging in you should see that the first join is returning a string, not a list. At least that's what I was seeing yesterday when I was testing it.
There was a problem hiding this comment.
ah, you're right, thanks!
tsroten
commented
Aug 10, 2017
@meeuw Ok, this looks good other than that last comment I left about the |
4578e32 to
782a79dCompare782a79d to
310088eComparemeeuw
commented
Aug 19, 2017
pgcli is ready! |
Description
output generator
Checklist
CHANGELOG.