Skip to content

Commit

Permalink
Merge pull request #1 from sequana/update_wrapper_ext
Browse files Browse the repository at this point in the history
Finalise package
  • Loading branch information
cokelaer committed Nov 24, 2021
2 parents 1fb65f6 + 9b49d8f commit 7b39683
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 36 deletions.
30 changes: 27 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Sequana Sphinxext
##################


.. image:: https://badge.fury.io/py/sequana_sphinxext.svg
:target: https://pypi.python.org/pypi/sequana_sphinxext
.. image:: https://badge.fury.io/py/sequana-sphinxext.svg
:target: https://pypi.python.org/pypi/sequana-sphinxext

.. image:: https://github.com/sequana/sequana_sphinxext/actions/workflows/main.yml/badge.svg?branch=master
:target: https://github.com/sequana/sequana_sphinext/actions/workflows/main.yml
Expand All @@ -17,7 +17,8 @@ Sequana Sphinxext


:Python version: 3.7.3, 3.8 ,3.9
:Issues: `On github <https://github.com/sequana/sequana/issues>`_
:Status: Production
:Issues: Please fill issues `On github <https://github.com/sequana/sequana/issues>`_
:How to cite: Citations are important for us to carry on developments.
For Sequana library (including the pipelines), please use

Expand All @@ -28,3 +29,26 @@ Sequana Sphinxext
The sequana_sphinxext package is used exclusively to provide Sphinx extensions for the Sequana
project. **Sequana** includes a set of pipelines related to NGS (new generation sequencing) including quality control, variant calling, coverage, taxonomy, transcriptomics. **Please see the** `documentation <http://sequana.readthedocs.org>`_ for an up-to-date status.

We have three sphinx extension to be added in your Sphinx configuration files in the extensions list:

extensions += [
"sequana_sphinxext.snakemakerule",
"sequana_sphinxext.pipeline",
"sequana_sphinxext.wrapper"]

You can then include a wrapper from `sequana wrappers <https://github.com/sequana/sequana-wrappers>` using e.g.::

.. sequana_wrapper:: fastqc

or a rule from Sequana::

.. snakemakerule:: fastq_sampling

or a pipeline from sequana::

.. sequana_pipeline:: demultiplex





14 changes: 7 additions & 7 deletions sequana_sphinxext/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ def get_rule_doc(name):

try:
data = urllib.request.urlopen(url).read().decode("utf8")
except HTTPError:
except HTTPError: # pragma: no cover
return f"Could not access to {url}"

try:
from sequana_pipetools import Module

m = Module(f"pipeline:{name}")
version = m.version
except ValueError:
except ValueError: # pragma: no cover
version = "Not installed locally."
except ImportError:
except ImportError: # pragma: no cover
version = "?"

docstring = "**current version**:{}\n\n{}".format(version, data)

return docstring


class snakemake_base(Body, Element):
class snakemake_base(Body, Element): # pragma: no cover
def dont_traverse(self, *args, **kwargs):
return []

Expand Down Expand Up @@ -91,17 +91,17 @@ def visit_perform(self, node):
res = core.publish_parts(node.rule_docstring, writer=w)["html_body"]
self.body.append('<div class="">' + res + "</div>")
node.children = []
except Exception as err:
except Exception as err: # pragma: no cover
print(err)
self.body.append('<div class=""> no docstring </div>')

def depart_perform(self, node):
node.children = []

def visit_ignore(self, node):
def visit_ignore(self, node): # pragma: no cover
node.children = []

def depart_ignore(self, node):
def depart_ignore(self, node): # pragma: no cover
node.children = []

app.add_node(
Expand Down
10 changes: 5 additions & 5 deletions sequana_sphinxext/snakemakerule.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_rule_doc(name):
rule = Module(name)
filename = rule.path + "/%s.rules" % name
data = open(filename, "r").read()
except ImportError:
except ImportError: # pragma no cover
url = "https://raw.githubusercontent.com/sequana/sequana/master/sequana/rules/"
if name.count("/") == 0:
url = f"{url}/{name}/{name}.rules"
Expand Down Expand Up @@ -88,12 +88,12 @@ def get_rule_doc(name):
return docstring


class snakemake_base(Body, Element):
class snakemake_base(Body, Element): # pragma: no cover
def dont_traverse(self, *args, **kwargs):
return []


class snakemake_rule(snakemake_base):
class snakemake_rule(snakemake_base): # pragma: no cover
pass


Expand Down Expand Up @@ -141,10 +141,10 @@ def visit_perform(self, node):
def depart_perform(self, node):
node.children = []

def depart_ignore(self, node):
def depart_ignore(self, node): # pragma: no cover
node.children = []

def visit_ignore(self, node):
def visit_ignore(self, node): # pragma: no cover
node.children = []

app.add_node(
Expand Down
32 changes: 15 additions & 17 deletions sequana_sphinxext/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from docutils.nodes import Body, Element


# from sphinx.locale import _
from sphinx.util.docutils import SphinxDirective


Expand All @@ -42,20 +41,18 @@ def get_rule_doc(name):
data = r.content.decode()
rulename_tag = "rule %s" % name

if "404: Not Found" in data:
if "404: Not Found" in data: # pragma no cover
print(f"URL not found: {url}")
return (
title
+ f"**docstring for {name} wrapper not yet available (no README.md found)**"
)
return title + f"**docstring for {name} wrapper not yet available (no README.md found)**"

def get_section(data, section):

if section in ["Example", "Configuration"]:
code = f"\n**{section}**\n::\n\n"
elif section in ["References", "Reference"]:
code = f"\n**{section}**\n\n"
else:
code = ""

found = False
for line in data.split("\n"):
# while requested section is not found, we parse the data
Expand All @@ -77,20 +74,21 @@ def get_section(data, section):
example_code = get_section(data, "Example")
docstring = get_section(data, "Documentation")
config = get_section(data, "Configuration")

rst = docstring + example_code + config
ref = get_section(data, "References")

url = f"https://github.com/sequana/sequana-wrappers/blob/main/wrappers/{name}/README.md"
rst += f"\n`Extra information on the wrapper page itself. <{url}>`_"
rst = f"The `{name} <{url}>`_ wrapper "
rst += docstring + example_code + config + ref
rst += f"\n\n....\n\nFound a bug or have an issue ? Please report here https://github.com/sequana/sequana-wrappers/issues"
return rst


class snakemake_base(Body, Element):
class snakemake_base(Body, Element): # pragma: no cover
def dont_traverse(self, *args, **kwargs):
return []


class sequana_wrapper(snakemake_base):
class sequana_wrapper(snakemake_base): # pragma: no cover
pass


Expand All @@ -99,7 +97,7 @@ def run(content, node_class, state, content_offset):
name = content[0]
try:
node.rule_docstring = get_rule_doc(name)
except Exception:
except Exception: # pragma: no cover
node.rule_docstring = f"Could not read or interpret documentation for {name}"
state.nested_parse(content, content_offset, node)
return [node]
Expand Down Expand Up @@ -131,17 +129,17 @@ def visit_perform(self, node):
res = core.publish_parts(node.rule_docstring, writer=w)["html_body"]
self.body.append('<div class="sequana_wrapper">' + res + "</div><br>")
node.children = []
except Exception as err:
except Exception as err: # pragma: no cover
print(err)
self.body.append('<div class="sequana_wrapper"> no docstring </div>')
self.body.append('<div class="sequana_wrapper"> no valid docstring </div>')

def depart_perform(self, node):
node.children = []

def depart_ignore(self, node):
def depart_ignore(self, node): # pragma: no cover
node.children = []

def visit_ignore(self, node):
def visit_ignore(self, node): # pragma: no cover
node.children = []

app.add_node(
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from setuptools import setup, find_packages


_MAJOR = 0
_MINOR = 2
_MAJOR = 1
_MINOR = 0
_MICRO = 0
version = f"{_MAJOR}.{_MINOR}.{_MICRO}"
release = f"{_MAJOR}.{_MINOR}"
Expand All @@ -13,7 +13,7 @@
"version": version,
"license": "new BSD",
"url": "http://github.com/sequana/sequana_sphinxext",
"description": "A set of standalone application and pipelines dedicated to NGS (new generation sequencing) analysis",
"description": "A set of sphinx extension for Sequana pipelines, wrappers and rules",
"platforms": ["Linux", "Unix", "MacOsX", "Windows"],
"keywords": ["NGS", "snakemake"],
"classifiers": [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_sequana_pipeline():

def test_doc():
res = snakemakerule.get_rule_doc("dag")
res = snakemakerule.get_rule_doc("fastqc_dynamic")
res = snakemakerule.get_rule_doc("fastqc")

try:
res = snakemakerule.get_rule_doc("dummy")
Expand Down

0 comments on commit 7b39683

Please sign in to comment.