From 32c6e7f78bb8f04d27615cfd8948b0b89f27b4e6 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 8 Dec 2014 20:34:06 -0500 Subject: [PATCH] Implement share_test command. Make the tool test json blob produced by default. Add new command share_test - to publish this blob to gist (requires setting github credentials in ~/.planemo.yml) and produce a sharable URL to rich HTML report based on these results. ``` % planemo test ... All 1 test(s) executed passed. simple_constructs[0]: passed % planemo share_test File published to Github Gist. Raw URL: https://gist.githubusercontent.com/jmchilton/457933350b28a3d1e752/raw/3888694aa109e0928a93ddd414b9acadaf578dc5/index Share results with URL: http://galaxyproject.github.io/planemo/tool_test_viewer.html?test_data_url=https://gist.githubusercontent.com/jmchilton/457933350b28a3d1e752/raw/3888694aa109e0928a93ddd414b9acadaf578dc5/index Embed results with markdown: [View Tool Test Results](http://galaxyproject.github.io/planemo/tool_test_viewer.html?test_data_url=https://gist.githubusercontent.com/jmchilton/457933350b28a3d1e752/raw/3888694aa109e0928a93ddd414b9acadaf578dc5/index) ``` --- docs/commands.rst | 1 + docs/commands/share_test.rst | 26 +++++++++++++++++ docs/planemo.reports.rst | 22 +++++++++++++++ docs/planemo.rst | 9 ++++++ planemo/commands/cmd_create_gist.py | 38 +++++++++++++++++++++++++ planemo/commands/cmd_share_test.py | 43 +++++++++++++++++++++++++++++ planemo/commands/cmd_test.py | 2 +- planemo/github_util.py | 36 ++++++++++++++++++++++++ scripts/commands_to_rst.py | 8 +++++- 9 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 docs/commands/share_test.rst create mode 100644 docs/planemo.reports.rst create mode 100644 planemo/commands/cmd_create_gist.py create mode 100644 planemo/commands/cmd_share_test.py create mode 100644 planemo/github_util.py diff --git a/docs/commands.rst b/docs/commands.rst index d07c35d49..4a88d8f4a 100644 --- a/docs/commands.rst +++ b/docs/commands.rst @@ -16,6 +16,7 @@ documentation describes these commands. .. include:: commands/lint.rst .. include:: commands/project_init.rst .. include:: commands/serve.rst +.. include:: commands/share_test.rst .. include:: commands/shed_diff.rst .. include:: commands/shed_upload.rst .. include:: commands/syntax.rst diff --git a/docs/commands/share_test.rst b/docs/commands/share_test.rst new file mode 100644 index 000000000..cb56b9296 --- /dev/null +++ b/docs/commands/share_test.rst @@ -0,0 +1,26 @@ + +``share_test`` command +=============================== + +This section is auto-generated from the help text for the planemo command +``share_test``. This help message can be generated with ``planemo share_test +--help``. + +**Usage**:: + + planemo share_test [OPTIONS] FILE_PATH + +**Help** + +Publish JSON test results to Github Gist and produce sharable URL. + +Sharable URL can be used to share an HTML version of the report that +can be easily embedded in pull requests or commit messages. Requires +a ~/.planemo.yml with Github 'username' and 'password' defined in a +'github' section of that configuration file. + +**Options**:: + + + --help Show this message and exit. + diff --git a/docs/planemo.reports.rst b/docs/planemo.reports.rst new file mode 100644 index 000000000..9b9d128eb --- /dev/null +++ b/docs/planemo.reports.rst @@ -0,0 +1,22 @@ +planemo.reports package +======================= + +Submodules +---------- + +planemo.reports.build_report module +----------------------------------- + +.. automodule:: planemo.reports.build_report + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: planemo.reports + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/planemo.rst b/docs/planemo.rst index bb114c6a8..ed3bfca5b 100644 --- a/docs/planemo.rst +++ b/docs/planemo.rst @@ -7,6 +7,7 @@ Subpackages .. toctree:: planemo.commands + planemo.reports Submodules ---------- @@ -51,6 +52,14 @@ planemo.galaxy_test module :undoc-members: :show-inheritance: +planemo.github_util module +-------------------------- + +.. automodule:: planemo.github_util + :members: + :undoc-members: + :show-inheritance: + planemo.io module ----------------- diff --git a/planemo/commands/cmd_create_gist.py b/planemo/commands/cmd_create_gist.py new file mode 100644 index 000000000..04e02c10d --- /dev/null +++ b/planemo/commands/cmd_create_gist.py @@ -0,0 +1,38 @@ +""" +""" +import click + +from planemo.cli import pass_context +from planemo.io import info +from planemo import github_util + +target_path = click.Path( + file_okay=True, + dir_okay=False, + resolve_path=True, +) + + +@click.command("create_gist") +@click.argument( + 'path', + metavar="FILE_PATH", + type=target_path, +) +@click.option( + "--link_type", + type=click.Choice(["raw", "html"]), + default="raw", + help=("Link type to generate for the file.") +) +@pass_context +def cli(ctx, path, **kwds): + """Download a tool repository as a tarball from the tool shed and extract + to the specified directory. + """ + file_url = github_util.publish_as_gist_file(ctx, path) + if kwds.get("link_type") == "raw": + share_url = file_url + else: + share_url = "http://htmlpreview.github.io/?%s" % file_url + info("File published to Github Gist - share with %s" % share_url) diff --git a/planemo/commands/cmd_share_test.py b/planemo/commands/cmd_share_test.py new file mode 100644 index 000000000..eb179fd6d --- /dev/null +++ b/planemo/commands/cmd_share_test.py @@ -0,0 +1,43 @@ +""" +""" +import click + +from planemo.cli import pass_context +from planemo.io import info +from planemo import github_util + +PLANEMO_TEST_VIEWER_URL_TEMPLATE = ( + "http://galaxyproject.github.io/planemo/tool_test_viewer.html" + "?test_data_url=%s" +) + +target_path = click.Path( + file_okay=True, + dir_okay=False, + resolve_path=True, +) + + +@click.command("share_test") +@click.argument( + 'path', + metavar="FILE_PATH", + type=target_path, + default="tool_test_output.json", +) +@pass_context +def cli(ctx, path, **kwds): + """Publish JSON test results to Github Gist and produce sharable URL. + + Sharable URL can be used to share an HTML version of the report that + can be easily embedded in pull requests or commit messages. Requires + a ~/.planemo.yml with Github 'username' and 'password' defined in a + 'github' section of that configuration file. + """ + file_url = github_util.publish_as_gist_file(ctx, path) + share_url = PLANEMO_TEST_VIEWER_URL_TEMPLATE % file_url + info("File published to Github Gist.") + info("Raw URL: %s" % file_url) + info("Share results with URL: %s" % share_url) + markdown = "[View Tool Test Results](%s)" % share_url + info("Embed results with markdown: %s" % markdown) diff --git a/planemo/commands/cmd_test.py b/planemo/commands/cmd_test.py index cbf6e8508..78d1f8717 100644 --- a/planemo/commands/cmd_test.py +++ b/planemo/commands/cmd_test.py @@ -52,7 +52,7 @@ "--test_output_json", type=click.Path(file_okay=True, resolve_path=True), help="Output test report (planemo json).", - default=None, + default="tool_test_output.json", ) @click.option( "--job_output_files", diff --git a/planemo/github_util.py b/planemo/github_util.py new file mode 100644 index 000000000..ac724f7c2 --- /dev/null +++ b/planemo/github_util.py @@ -0,0 +1,36 @@ +""" +""" + +try: + import github + has_github_lib = True +except ImportError: + github = None + has_github_lib = False + +NO_GITHUB_DEP_ERROR = ("Cannot use github functionality - " + "PyGithub library not available.") + + +def get_github_config(ctx): + if "github" not in ctx.global_config: + return None + global_github_config = ctx.global_config["github"] + return GithubConfig(global_github_config) + + +class GithubConfig(object): + + def __init__(self, config): + if not has_github_lib: + raise Exception(NO_GITHUB_DEP_ERROR) + self._github = github.Github(config["username"], config["password"]) + + +def publish_as_gist_file(ctx, path, name="index"): + github_config = get_github_config(ctx) + user = github_config._github.get_user() + content = open(path, "r").read() + content_file = github.InputFileContent(content) + gist = user.create_gist(False, {name: content_file}) + return gist.files[name].raw_url diff --git a/scripts/commands_to_rst.py b/scripts/commands_to_rst.py index a2f93a9bf..6cad917c7 100644 --- a/scripts/commands_to_rst.py +++ b/scripts/commands_to_rst.py @@ -15,7 +15,13 @@ planemo_cli = cli.planemo runner = CliRunner() -INTERNAL_COMMANDS = ['travis_before_install', 'shed_download'] +# Don't document the following commands - they should not be considered part +# of the planemo API. +INTERNAL_COMMANDS = [ + 'create_gist', + 'travis_before_install', + 'shed_download', +] COMMAND_TEMPLATE = Template(''' ``${command}`` command