Skip to content

Commit

Permalink
Merge branch 'develop' into fix-2530
Browse files Browse the repository at this point in the history
  • Loading branch information
vigsterkr committed Jan 12, 2022
2 parents 6d35886 + 1e33c65 commit 52f79d4
Show file tree
Hide file tree
Showing 45 changed files with 5,753 additions and 52 deletions.
160 changes: 121 additions & 39 deletions .github/workflows/test_deploy.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/test_publish.yml
Expand Up @@ -9,7 +9,7 @@ on:
- renku/core/commands/providers/*.py

jobs:
test-linux-integration:
test-linux-integration-publish:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
OLOS_ACCESS_TOKEN: ${{ secrets.OLOS_ACCESS_TOKEN }}
run: pytest -m publish -v

test-macos-integration:
test-macos-integration-publish:
runs-on: macos-latest
strategy:
max-parallel: 4
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -91,3 +91,6 @@ helm-chart/renku-core/charts
renku/templates/
temp/
tmp/

# pytest-recording cache
cassettes
173 changes: 173 additions & 0 deletions docs/_ext/cheatsheet.py
@@ -0,0 +1,173 @@
from collections import defaultdict

from docutils import nodes
from docutils.parsers.rst import Directive, directives
from sphinx.locale import _
from sphinx.util import texescape
from sphinx.util.docutils import SphinxDirective


def latex_escape(text):
"""Escape characters in text for use in latex."""
return texescape.escape(text).replace(r"\sphinxhyphen{}", "-")


def add_linebreaks(text, breakstring=" \\linebreak "):
"""Replace ||| with linebreaks."""
return text.replace("\n", " ").replace("|||", breakstring)


class cheatsheet_list(nodes.General, nodes.Element):
"""Sphinx element to output a list of cheatsheet entries."""

pass


class CheatsheetListDirective(Directive):
"""Sphinx directive to output a list of cheatsheet elements."""

def run(self):
"""Run method that produces dummy node to be replaced with cheatsheet in post processing."""
return [cheatsheet_list("")]


class CheatsheetDirective(SphinxDirective):
"""Sphinx directive to define a cheatsheet entry."""

has_content = True

option_spec = {
"command": directives.unchanged_required,
"description": directives.unchanged_required,
"group": directives.unchanged_required,
"extended": directives.flag,
}

def run(self):
"""Process a cheatsheet entry."""

if not hasattr(self.env, "cheatsheet_all_entries"):
self.env.cheatsheet_all_entries = []

command = self.options.get("command")
description = self.options.get("description")
group = self.options.get("group")

if any(
command == e["command"] and description == e["description"] and group == e["group"]
for e in self.env.cheatsheet_all_entries
):
return []

self.env.cheatsheet_all_entries.append(
{
"command": command,
"description": description,
"group": group,
"extended": True if "extended" in self.options else False,
"docname": self.env.docname,
}
)

return []


def purge_cheatsheet(app, env, docname):
"""Clear environment if source files changed."""
if not hasattr(env, "cheatsheet_all_entries"):
return

env.cheatsheet_all_entries = [entry for entry in env.cheatsheet_all_entries if entry["docname"] != docname]


def merge_cheatsheets(app, env, docnames, other):
"""Merge cheatsheet entries during parallel build."""
if not hasattr(env, "cheatsheet_all_entries"):
env.cheatsheet_all_entries = []

if hasattr(other, "cheatsheet_all_entries"):
env.cheatsheet_all_entries.extend(other.cheatsheet_all_entries)


def process_latex_entries(content, entries, groups):
"""Create output when building latex cheatsheet."""
for group in groups:
entry_list = entries[group]
content.append(nodes.raw("", f"\section{{{group}}}", format="latex"))

for entry in entry_list:
description = latex_escape(entry["description"])
description = add_linebreaks(description)
command = latex_escape(entry["command"])
command = add_linebreaks(command)
content.append(nodes.raw("", f"\commandsubsection{{{command}}}{{{description}}}", format="latex"))


def process_regular_entries(content, entries, groups):
"""Create output when building regular (html) cheatsheet."""
for group in groups:
entry_list = entries[group]
paragraph = nodes.section(ids=[group])
paragraph += nodes.title(group, group)

for entry in entry_list:
description = entry["description"]
command = entry["command"]

entry_paragraph = nodes.paragraph()

command = "<p class='cheatsheet_command'>" + add_linebreaks(command, "<br />") + "</p>"
command = nodes.raw("", command, format="html")
entry_paragraph += command

description = "<p class='cheatsheet_description'>" + add_linebreaks(description, "<br />") + "</p>"
description = nodes.raw("", description, format="html")
entry_paragraph += description

paragraph += entry_paragraph

content.append(paragraph)


def process_cheatsheet_nodes(app, doctree, fromdocname):
"""Process cached cheatsheet entries to create a cheatsheet list."""

env = app.builder.env
if not hasattr(env, "cheatsheet_all_entries"):
env.cheatsheet_all_entries = []

for node in doctree.traverse(cheatsheet_list):
content = []

entries = defaultdict(list)

for cheatsheet_info in env.cheatsheet_all_entries:
if not cheatsheet_info["extended"] or app.config.cheatsheet_extended:
entries[cheatsheet_info["group"]].append(cheatsheet_info)

if app.builder.name == "latex":
process_latex_entries(content, entries, app.config.cheatsheet_groups)
else:
process_regular_entries(content, entries, app.config.cheatsheet_groups)

node.replace_self(content)


def setup(app):
"""Run setup method for directive/plugin."""

app.add_config_value("cheatsheet_extended", False, "html")
app.add_config_value("cheatsheet_groups", [], "html")
app.add_node(cheatsheet_list)

app.add_directive("cheatsheet", CheatsheetDirective)
app.add_directive("cheatsheetlist", CheatsheetListDirective)
app.connect("doctree-resolved", process_cheatsheet_nodes)
app.connect("env-purge-doc", purge_cheatsheet)
app.connect("env-merge-info", merge_cheatsheets)

return {
"version": "0.1",
"parallel_read_safe": True,
"parallel_write_safe": True,
}
Binary file added docs/_static/cheatsheet/cheatsheet.pdf
Binary file not shown.
Binary file added docs/_static/cheatsheet/fonts/Inconsolata.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added docs/_static/cheatsheet/fonts/SourceSans3.ttf
Binary file not shown.

0 comments on commit 52f79d4

Please sign in to comment.