-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Added --format #23
Added --format #23
Conversation
Codecov Report
@@ Coverage Diff @@
## master #23 +/- ##
=========================================
+ Coverage 78.97% 82.5% +3.52%
=========================================
Files 3 3
Lines 195 200 +5
=========================================
+ Hits 154 165 +11
+ Misses 41 35 -6
Continue to review full report at Codecov.
|
Wow, that's too much.
I think I have to find a way to test cli. Do not merge.
…On Mon, Oct 29, 2018, 11:14 codecov[bot] ***@***.*** wrote:
Codecov <https://codecov.io/gh/hugovk/pypistats/pull/23?src=pr&el=h1>
Report
Merging #23
<https://codecov.io/gh/hugovk/pypistats/pull/23?src=pr&el=desc> into
master
<https://codecov.io/gh/hugovk/pypistats/commit/b11a8c7ba05e2e8979f5a98a88537ca04bc87a12?src=pr&el=desc>
will *decrease* coverage by 11.87%.
The diff coverage is 2.7%.
[image: Impacted file tree graph]
<https://codecov.io/gh/hugovk/pypistats/pull/23?src=pr&el=tree>
@@ Coverage Diff @@## master #23 +/- ##
===========================================- Coverage 78.97% 67.09% -11.88%
===========================================
Files 3 3
Lines 195 231 +36
===========================================+ Hits 154 155 +1 - Misses 41 76 +35
Impacted Files
<https://codecov.io/gh/hugovk/pypistats/pull/23?src=pr&el=tree> Coverage Δ
pypistats/cli.py
<https://codecov.io/gh/hugovk/pypistats/pull/23/diff?src=pr&el=tree#diff-cHlwaXN0YXRzL2NsaS5weQ==> 49.03%
<0%> (-24.88%) ⬇️
pypistats/__init__.py
<https://codecov.io/gh/hugovk/pypistats/pull/23/diff?src=pr&el=tree#diff-cHlwaXN0YXRzL19faW5pdF9fLnB5> 81.74%
<100%> (+0.14%) ⬆️
------------------------------
Continue to review full report at Codecov
<https://codecov.io/gh/hugovk/pypistats/pull/23?src=pr&el=continue>.
*Legend* - Click here to learn more
<https://docs.codecov.io/docs/codecov-delta>
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov
<https://codecov.io/gh/hugovk/pypistats/pull/23?src=pr&el=footer>. Last
update b11a8c7...b98dbf3
<https://codecov.io/gh/hugovk/pypistats/pull/23?src=pr&el=lastupdated>.
Read the comment docs <https://docs.codecov.io/docs/pull-request-comments>
.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#23 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACSbbCGhXyltLId_6zOBKSHq71c8sIDPks5uprjMgaJpZM4X-pYn>
.
|
This block is repeated five times, and could go into a function which would reduce the coverage drop, and would be more easily tested: if args.json or args.format == "json":
output = "json"
elif args.format == "markdown":
output = "table"
else:
import warnings
warnings.warn(f'Unknown format: {args.format}. Using "markdown".')
output = "table" That may sort the coverage drop, otherwise some options for testing is using |
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 few other notes :)
pypistats/cli.py
Outdated
elif args.format == "markdown": | ||
output = "table" | ||
else: | ||
import warnings |
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.
Let's move the import to the top and use isort
to put them in order.
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.
Alright.
.travis.yml
Outdated
- flake8 --statistics --count | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then black --check --diff .; fi | ||
- flake8 --statistics --count --verbose pypistats/ tests/ | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then black --check --diff --verbose pypistats/ tests/; fi |
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.
Is there a reason to specify these dirs and not run in .
? We miss setup.py
like this.
Also, let's leave out --verbose
so the output is a cleaner.
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 didn't think about setup.py
, sorry.
I put --verbose
in case of referring Travis build logs via URL if anyone wants to contribute to show contributors what the problem is.
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, just read your PR message fully now, and it's done for speed.
The CI took 3.13s to run Black with this PR:
https://travis-ci.org/hugovk/pypistats/jobs/447664623#L640
and 4.54s with master:
https://travis-ci.org/hugovk/pypistats/jobs/447539626#L580
I think that's fine.
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's a flake8 error, it lists them in the logs wihout --verbose
.
And if Black errors, --diff
shows what should be have been done.
I think the verbose stuff is probably a bit distracting.
pypistats/__init__.py
Outdated
@@ -15,6 +15,8 @@ | |||
|
|||
BASE_URL = "https://pypistats.org/api/" | |||
|
|||
FORMATS = ("json", "markdown") # only used for printing to terminal |
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.
Would this be better kept internal to cli.py
?
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'll do it.
Yes, that's a good idea.
I was just trying Method 1: Using SubprocessI can test via
Method 2: Testing Functions under
|
Pros | Cons |
---|---|
Simple enough | Testing print is not possible. |
What I'm Going to Do
Overall, I think, as you've said, I will move those repeating if-else
parts to a protected/underscore function and see the coverage myself. Then choose a way to solve the problem.
And, also, will look into the problems you've mentioned above. :)
Phew, finally. Properly tested, covered. Dealt with minor issues you have mentioned. |
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.
Looking good, a few more notes :)
pypistats/cli.py
Outdated
default="markdown", | ||
choices=FORMATS, | ||
help="The format of output.", | ||
), |
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.
Let's put all these repeated argument(...)
s in an arg_format
variable, like arg_start_date
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.
👍 will do
pypistats/cli.py
Outdated
"--format", | ||
default="markdown", | ||
choices=FORMATS, | ||
help="The format of output.", |
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.
Remove fullstop for single sentence:
help="The format of output.", | |
help="The format of output", |
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.
👍 will do
pypistats/cli.py
Outdated
if args.mirrors in ["with", "without"]: | ||
args.mirrors = args.mirrors == "with" | ||
|
||
_format = _define_format(args) |
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 can actually move all these calls down to a single args.format = _define_format(args)
down in the else
block at the end of the file, and then use output=_format
here.
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.
👍 will check
One more thing, one of the two hardest things in computer science, and it's not cache invalidation. :) First, we're still at version 0.y.z so I'm not too worried about backwards compatibility at this point, if it means getting it right. So on the programmatic side, we have print(pypistats.recent("pillow")) # output="table"
print(pypistats.recent("pillow", output="table"))
print(pypistats.recent("pillow", output="json")) Previously on the CLI side we had $ pypistats recent pillow # output="table"
$ pypistats recent pillow --json # output="json" Now on the CLI side, we have $ pypistats recent pillow # output="table"
$ pypistats recent pillow --format markdown # output="table"
$ pypistats recent pillow --json # output="json"
$ pypistats recent pillow --format json # output="json" What do you think, shall we unify the terms? It would probably clearer if this tool isn't using different terms in its two interfaces (CLI and programmatic). For example, use either $ pypistats recent pillow # output="markdown"
$ pypistats recent pillow --output markdown # output="markdown"
$ pypistats recent pillow --json # output="json"
$ pypistats recent pillow --output json # output="json"
Thoughts? (This could go in a separate PR.) |
TL;DR
format vs. outputShadowing Issue
On the programmatic side, *insert developer here* provides
TermsYes, I do not know if it makes sense, but Is semantics or terminology worth the hassle though? This is the issue. I think we should use the term On markdown vs. table and Backwards Compability
I actually wished to change it, but, you know, hesitated it since you might want to be comfortable in your terms. If backwards compatibility is not a huge deal now, I can deal with that. My two cents are on |
pypistats/cli.py
Outdated
arg_daily = argument("-d", "--daily", action="store_true", help="Show daily downloads") | ||
arg_format = argument( | ||
"-f", "--format", default="markdown", choices=FORMATS, help="The format of output." |
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.
"-f", "--format", default="markdown", choices=FORMATS, help="The format of output." | |
"-f", "--format", default="markdown", choices=FORMATS, help="The format of output" |
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.
lol I was dead sure I have deleted it, seems like I didn't.
Yes, let's go for If this pypistats/pypistats/__init__.py Lines 19 to 27 in 1ee8418
pypistats/pypistats/__init__.py Lines 48 to 49 in 1ee8418
|
It shadows If shadowing |
Let's go with |
Thank you very much! |
Related to #20
Added
--format
flag (for short,-f
) to cli args.--json
is kept for convenience.The default is
markdown
. The cli tool also provides aUserWarning
if given format is not supported and will inform user that it will fallback to default, which is, again,markdown
. An example below:Other Minor Changes
pypistats/
andtests/
directory instead of whole project which makes it a little bit faster (especially black).tests_require
tosetup.py
.The only problem is that the code I provided was not tested by
pytest
since it is not quite possible to both mock HTTP requests and test cli at the same time. The codebase was tested by hand 😢. This will probably drop code coverage by ~5%. If you are strict about testing, I can find a way around (then inform me, don't merge this PR).If you'd like to test for yourself by hand, you can clone forked copy and checkout feat/format-arg branch.