from flask import Blueprint, jsonify

from .security import validate_request_authentication
from qiime.sdk import PluginManager

v1 = Blueprint('v1', __name__)
v1.before_request(validate_request_authentication)


@v1.route('/', methods=['GET', 'POST'])
def root():
    return jsonify(content="!")

@v1.route('/plugins', methods=['GET'])
def plugins():
    pm = PluginManager()
    return jsonify(pm.plugins)

from flask import Blueprint, jsonify

from .security import validate_request_authentication
from qiime.sdk import PluginManager

PLUGIN_MANAGER = PluginManager()
v1 = Blueprint('v1', __name__)
v1.before_request(validate_request_authentication)


@v1.route('/', methods=['GET', 'POST'])
def root():
    return jsonify(content="!")


@v1.route('/plugins', methods=['GET'])
def api_plugins():
    plugin_list = list(PLUGIN_MANAGER.plugins.keys())
    return jsonify({"names": plugin_list})


@v1.route('/workflows/<plugin_name>', methods=['GET'])
def api_workflows(plugin_name):
    plugin = PLUGIN_MANAGER.plugins[plugin_name]
    workflows_dict = {}
    for key, value in plugin.workflows.items():
        workflows_dict[key] = {}
        workflows_dict[key]['info'] = "Produces: {}".format(list(value.signature.output_artifacts.values()))
    return jsonify({"workflows": workflows_dict})

Add plugin workflow fetching to API
Add plugin workflow fetching to API

  from flask import Blueprint, jsonify
  
  from .security import validate_request_authentication
  from qiime.sdk import PluginManager
  
+ PLUGIN_MANAGER = PluginManager()
  v1 = Blueprint('v1', __name__)
  v1.before_request(validate_request_authentication)
  
  
  @v1.route('/', methods=['GET', 'POST'])
  def root():
      return jsonify(content="!")
  
+ 
  @v1.route('/plugins', methods=['GET'])
- def plugins():
+ def api_plugins():
-     pm = PluginManager()
+     plugin_list = list(PLUGIN_MANAGER.plugins.keys())
-     return jsonify(pm.plugins)
+     return jsonify({"names": plugin_list})
  
+ 
+ @v1.route('/workflows/<plugin_name>', methods=['GET'])
+ def api_workflows(plugin_name):
+     plugin = PLUGIN_MANAGER.plugins[plugin_name]
+     workflows_dict = {}
+     for key, value in plugin.workflows.items():
+         workflows_dict[key] = {}
+         workflows_dict[key]['info'] = "Produces: {}".format(list(value.signature.output_artifacts.values()))
+     return jsonify({"workflows": workflows_dict})
+ 
Add plugin workflow fetching to API
## Code Before:
from flask import Blueprint, jsonify

from .security import validate_request_authentication
from qiime.sdk import PluginManager

v1 = Blueprint('v1', __name__)
v1.before_request(validate_request_authentication)


@v1.route('/', methods=['GET', 'POST'])
def root():
    return jsonify(content="!")

@v1.route('/plugins', methods=['GET'])
def plugins():
    pm = PluginManager()
    return jsonify(pm.plugins)

## Instruction:
Add plugin workflow fetching to API
## Code After:
from flask import Blueprint, jsonify

from .security import validate_request_authentication
from qiime.sdk import PluginManager

PLUGIN_MANAGER = PluginManager()
v1 = Blueprint('v1', __name__)
v1.before_request(validate_request_authentication)


@v1.route('/', methods=['GET', 'POST'])
def root():
    return jsonify(content="!")


@v1.route('/plugins', methods=['GET'])
def api_plugins():
    plugin_list = list(PLUGIN_MANAGER.plugins.keys())
    return jsonify({"names": plugin_list})


@v1.route('/workflows/<plugin_name>', methods=['GET'])
def api_workflows(plugin_name):
    plugin = PLUGIN_MANAGER.plugins[plugin_name]
    workflows_dict = {}
    for key, value in plugin.workflows.items():
        workflows_dict[key] = {}
        workflows_dict[key]['info'] = "Produces: {}".format(list(value.signature.output_artifacts.values()))
    return jsonify({"workflows": workflows_dict})
