Skip to content
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

NEW: Add type, format, transformer info to plugin pages #435

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
'sphinx_extensions.command_block',
'sphinx_extensions.plugin_directory',
'sphinx_extensions.external_links',
'sphinxcontrib.bibtex'
'sphinxcontrib.bibtex',
'sphinx_extensions.types-formats-transformers'
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -116,6 +117,7 @@
exclude_patterns = [
'sphinx_extensions/plugin_directory/templates',
'sphinx_extensions/command_block/templates',
'sphinx_extensions/types-formats-transformers/templates'
]

# The reST default role (used for this markup: `text`) to use for all
Expand Down
1 change: 1 addition & 0 deletions source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Table of contents
interfaces/index
plugins/index
semantic-types
types-formats-transformers-list/types-formats-transformers-list
community
data-resources
supplementary-resources
Expand Down
18 changes: 17 additions & 1 deletion source/sphinx_extensions/plugin_directory/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import jinja2
import qiime2.sdk
import qiime2.core

from sphinx.util import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -46,14 +47,29 @@ def generate_rst(app):
fh.write(rendered)

for plugin in plugins.values():
transformers_list = []

for from_type, to_type in plugin.transformers:
from_type = qiime2.core.util.get_view_name(from_type)
to_type = qiime2.core.util.get_view_name(to_type)

transformers_list.append((from_type, to_type))

# .upper() because Python sorts all capitalized elements above all
# lowercase ones, and I figured we didn't want 'dict' sorting under
# 'TaxonomicClassifierDirFmt'
transformers_list.sort(
key=lambda element: (element[0].upper(), element[1].upper()))

plugin_cli_name = plugin.name.replace('_', '-')
plugin_dir = os.path.join(rst_dir, plugin_cli_name)
os.mkdir(plugin_dir)

index_path = os.path.join(plugin_dir, 'index.rst')
with open(index_path, 'w') as fh:
template = env.get_template('plugin.rst')
rendered = template.render(title=plugin_cli_name, plugin=plugin)
rendered = template.render(title=plugin_cli_name, plugin=plugin,
transformers_list=transformers_list)
fh.write(rendered)

if plugin.citations:
Expand Down
11 changes: 11 additions & 0 deletions source/sphinx_extensions/types-formats-transformers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2016-2019, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from .extension import setup

__all__ = ['setup']
93 changes: 93 additions & 0 deletions source/sphinx_extensions/types-formats-transformers/extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2016-2019, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

import jinja2
import qiime2.sdk
import qiime2.core
import os
import shutil

from sphinx.util import logging
logger = logging.getLogger(__name__)


def generate_rst(app):
pm = qiime2.sdk.PluginManager()

loader = jinja2.PackageLoader(
'sphinx_extensions.types-formats-transformers', 'templates')
env = jinja2.Environment(loader=loader)

rst_dir = os.path.join(app.env.srcdir, 'types-formats-transformers-list')
app.types_rst_dir = rst_dir
cleanup_rst(app, None)
os.mkdir(rst_dir)

index_path = os.path.join(rst_dir, 'types-formats-transformers-list.rst')

type_list = []
for type in pm.get_semantic_types():
type_list.append(repr(type))
type_list.sort()

importable_formats = [
repr(importable_format) for importable_format
in pm.get_formats(importable=True)]
importable_formats.sort()

exportable_formats = [
repr(exportable_format) for exportable_format
in pm.get_formats(exportable=True)]
exportable_formats.sort()

all_formats_set = {*importable_formats, *exportable_formats,
*[repr(format) for format
in pm.get_formats(include_all=True)]}
all_formats = [repr(format) for format in all_formats_set]
all_formats.sort()

transformers_list = []
for from_type in pm.transformers:
for to_type in pm.transformers[from_type]:
transformers_list.append((repr(from_type), repr(to_type)))

# .upper() because Python sorts all capitalized elements above all
# lowercase ones, and I figured we didn't want 'dict' sorting under
# 'TaxonomicClassifierDirFmt'
transformers_list.sort(
key=lambda element: (element[0].upper(), element[1].upper()))

reverse_transformers_list = []
for to_type in pm._reverse_transformers:
for from_type in pm.transformers[to_type]:
reverse_transformers_list.append((repr(from_type), repr(to_type)))

reverse_transformers_list.sort(
key=lambda element: (element[0].upper(), element[1].upper()))

template = env.get_template('types-formats-transformers-list.rst')
with open(index_path, 'w') as fh:
rendered = template.render(
type_list=type_list, format_list=all_formats,
importable_formats=importable_formats,
exportable_formats=exportable_formats,
transformers_list=transformers_list,
reverse_transformers_list=reverse_transformers_list)
fh.write(rendered)


def cleanup_rst(app, exception):
if hasattr(app, 'types_rst_dir') and \
os.path.exists(app.types_rst_dir):
shutil.rmtree(app.types_rst_dir)


def setup(app):
app.connect('builder-inited', generate_rst)
app.connect('build-finished', cleanup_rst)
return {'version': '0.0.1'}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Types List
==========

{% for type in type_list %}
- {{ type }}
{% endfor %}

Formats List
============

All Formats
-----------
{% for format in format_list %}
- {{ format }}
{% endfor %}

Importable Formats
------------------
{% for imp in importable_formats %}
- {{ imp }}
{% endfor %}

Exportable Formats
------------------
{% for exp in exportable_formats %}
- {{ exp }}
{% endfor %}

Transformers
============

Transformers
------------
{% for from, to in transformers_list %}
- {{ from }} -> {{ to }}
{% endfor %}

Reverse Transformers
--------------------
{% for from, to in reverse_transformers_list %}
- {{ from }} -> {{ to }}
{% endfor %}