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
Add --base-dir
option
#287
Changes from 6 commits
5b1cd92
f6993bc
77b8c4d
a8a6b53
e0811ab
4e65569
e71c7e4
d7a384b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,7 +19,9 @@ | |||||||||
Global options: | ||||||||||
--service=<name> Provide an alternative service name to submit. | ||||||||||
--rcfile=<file> Specify configuration file. [default: .coveragerc] | ||||||||||
--base_dir=<dir> Base directory that is removed from reported paths. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename to:
Suggested change
I was going to think through a convention for hyphens vs underscores for this, only to realize that was a silly level of overkill when we can just side-step any future consistency issues. |
||||||||||
--output=<file> Write report to file. Doesn't send anything. | ||||||||||
--submit=<file> Upload a previously generated file. | ||||||||||
--merge=<file> Merge report from file when submitting. | ||||||||||
--finish Finish parallel jobs. | ||||||||||
-h --help Display this help. | ||||||||||
|
@@ -60,7 +62,8 @@ def main(argv=None): | |||||||||
try: | ||||||||||
coverallz = Coveralls(token_required, | ||||||||||
config_file=options['--rcfile'], | ||||||||||
service_name=options['--service']) | ||||||||||
service_name=options['--service'], | ||||||||||
base_dir=options.get('--base_dir', None)) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To keep up with the below null vs string comments:
Suggested change
|
||||||||||
|
||||||||||
if options['--merge']: | ||||||||||
coverallz.merge(options['--merge']) | ||||||||||
|
@@ -75,6 +78,11 @@ def main(argv=None): | |||||||||
coverallz.save_report(options['--output']) | ||||||||||
return | ||||||||||
|
||||||||||
if options['--submit']: | ||||||||||
with open(options['--submit']) as report_file: | ||||||||||
coverallz.submit_report(report_file.read()) | ||||||||||
return | ||||||||||
|
||||||||||
if options['--finish']: | ||||||||||
log.info('Finishing parallel jobs...') | ||||||||||
coverallz.parallel_finish() | ||||||||||
|
@@ -86,8 +94,9 @@ def main(argv=None): | |||||||||
|
||||||||||
log.info('Coverage submitted!') | ||||||||||
log.debug(result) | ||||||||||
log.info(result['message']) | ||||||||||
log.info(result['url']) | ||||||||||
if result: | ||||||||||
log.info(result.get('message', None)) | ||||||||||
log.info(result.get('url', None)) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||
except KeyboardInterrupt: # pragma: no cover | ||||||||||
log.info('Aborted') | ||||||||||
except CoverallsException as e: | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,8 +12,14 @@ | |||||||||||||||||||||||||||
class CoverallReporter: | ||||||||||||||||||||||||||||
"""Custom coverage.py reporter for coveralls.io.""" | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def __init__(self, cov, conf): | ||||||||||||||||||||||||||||
def __init__(self, cov, conf, base_dir=None): | ||||||||||||||||||||||||||||
self.coverage = [] | ||||||||||||||||||||||||||||
if base_dir: | ||||||||||||||||||||||||||||
self.base_dir = base_dir.replace(os.path.sep, '/') | ||||||||||||||||||||||||||||
if self.base_dir[-1] != '/': | ||||||||||||||||||||||||||||
self.base_dir += '/' | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
self.base_dir = None | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
Keeping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good call, makes sense to leave as you have it (though the above example could be replaced with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya that's a good point.. I guess I thought checking that single last char was more direct than using a string func, but I see the advantage thanks for the thorough review There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW you are correct and the direct indexing is faster:
...however at least personally I find that it's not always worth picking this most performant code for a block like this if another option would be more readable etc. Given this app tends to run once on CI with no real latency concerns, a couple hundred nanoseconds here and there is effectively ignorable :) |
||||||||||||||||||||||||||||
self.report(cov, conf) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def report5(self, cov): | ||||||||||||||||||||||||||||
|
@@ -183,9 +189,13 @@ def get_arcs(analysis): | |||||||||||||||||||||||||||
def parse_file(self, cu, analysis): | ||||||||||||||||||||||||||||
"""Generate data for single file.""" | ||||||||||||||||||||||||||||
filename = cu.relative_filename() | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# ensure results are properly merged between platforms | ||||||||||||||||||||||||||||
posix_filename = filename.replace(os.path.sep, '/') | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if self.base_dir and posix_filename.startswith(self.base_dir): | ||||||||||||||||||||||||||||
TheKevJames marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
posix_filename = posix_filename[len(self.base_dir):] | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
source = analysis.file_reporter.source() | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
token_lines = analysis.file_reporter.source_token_lines() | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"source_files": [{"name": "coveralls-python/example/project.py", "source": "def hello():\n print('world')\n\n\nclass Foo:\n \"\"\" Bar \"\"\"\n\n\ndef baz():\n print('this is not tested')\n\ndef branch(cond1, cond2):\n if cond1:\n print('condition tested both ways')\n if cond2:\n print('condition not tested both ways')\n", "coverage": [1, 1, null, null, 1, null, null, null, 1, 0, null, 1, 1, 1, 1, 1]}, {"name": "coveralls-python/example/runtests.py", "source": "from project import branch\nfrom project import hello\n\nif __name__ == '__main__':\n hello()\n branch(False, True)\n branch(True, True)\n", "coverage": [1, 1, null, 1, 1, 1, 1]}], "service_name": "coveralls-python", "config_file": ".coveragerc", "base_dir": null} |
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.
(see below)