Skip to content

Commit

Permalink
feat: create use_quarto_ext() & quarto-add cmd for using extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kelly-sovacool committed Dec 30, 2024
1 parent 73980ee commit 0f54b8e
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 10 deletions.
11 changes: 11 additions & 0 deletions docs/_extensions/fnl/_extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: fnl
author: Kelly Sovacool
version: 0.1.3
quarto-required: ">=1.5.0"
contributes:
formats:
html:
theme:
dark: [darkly, fnl-dark.scss]
light: [flatly, fnl-light.scss]
toc: true
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
9 changes: 2 additions & 7 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ website:
background: black
foreground: white
left: |
[![](/img/fnl-logo-dark.png){height=70px}](https://frederick.cancer.gov/research/science-areas/bioinformatics-and-computational-science/advanced-biomedical-computational-science)
[![](/_extensions/fnl/fnl-logo-dark.png){height=70px}](https://frederick.cancer.gov/research/science-areas/bioinformatics-and-computational-science/advanced-biomedical-computational-science)
center: |
Created by the
[CCR Collaborative Bioinformatics Resource](https://github.com/CCBR)
Expand Down Expand Up @@ -101,9 +101,4 @@ execute:
eval: true
echo: true

format:
html:
theme:
dark: [darkly, themes/fnl-dark.scss]
light: [flatly, themes/fnl-light.scss]
toc: true
format: fnl-html
Binary file added docs/fnl-logo-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/fnl-logo-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/ccbr_tools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CustomClickGroup,
)
from .send_email import send_email_msg
from .templates import use_quarto_ext


all_commands = "All installed tools:\n" + "\n".join(
Expand Down Expand Up @@ -133,7 +134,24 @@ def send_email(to_address, text, subject, attach_html, from_addr, debug):
send_email_msg(to_address, text, subject, attach_html, from_addr, debug)


@click.command()
@click.argument(
"ext_name",
type=str,
required=True,
)
def quarto_add(ext_name):
"""
Add a quarto extension
Arguments:
ext_name The name of the extension in ccbr_tools
"""
use_quarto_ext(ext_name)


cli.add_command(send_email)
cli.add_command(quarto_add)
cli.add_command(cite)
cli.add_command(version)

Expand Down
27 changes: 25 additions & 2 deletions src/ccbr_tools/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
Template files for CCBR Tools.
Templates:
- `ccbr_tools.templates.submit_slurm.sh`
"""
- `~ccbr_tools.templates.submit_slurm.sh`
Quarto extensions
- `~ccbr_tools.templates._extensions.fnl`
"""
import importlib.resources
import pathlib
import shutil


def read_template(template_name):
Expand Down Expand Up @@ -46,3 +50,22 @@ def use_template(template_name, output_filepath=None, **kwargs: str):
output_filepath = template_name
with open(output_filepath, "wt") as outfile:
outfile.write(template_str.format(**kwargs))


def use_quarto_ext(ext_name):
"""
Use a Quarto extension
Args:
ext_name (str): The name of the extension in ccbr_tools
Examples:
>>> use_quarto_ext("fnl")
"""
template_files = importlib.resources.files(__package__)
ext_dir = pathlib.Path("_extensions")
if not ext_dir.exists():
ext_dir.mkdir()
template_dir = template_files / "_extensions" / ext_name
shutil.copytree(template_dir, ext_dir / ext_name)
print(f"Copied {ext_name} to {ext_dir}")
9 changes: 9 additions & 0 deletions src/ccbr_tools/templates/_extensions/fnl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Quarto HTML format with FNL branding guidelines
First run `ccbr_tools quarto-add fnl`, then add the following to your `_quarto.yml` file:
```yaml
format: fnl-html
```
"""
11 changes: 11 additions & 0 deletions src/ccbr_tools/templates/_extensions/fnl/_extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: fnl
author: Kelly Sovacool
version: 0.1.3
quarto-required: ">=1.5.0"
contributes:
formats:
html:
theme:
dark: [darkly, fnl-dark.scss]
light: [flatly, fnl-light.scss]
toc: true
45 changes: 45 additions & 0 deletions src/ccbr_tools/templates/_extensions/fnl/fnl-dark.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*-- scss:defaults --*/

// colors
// https://nih.sharepoint.com/:b:/r/sites/NCI-Fred/Communications/Shared%20Documents/Branding%20guidelines%20LIVE.pdf?csf=1&web=1&e=e9PrVO

// primary
$black: #000000;
$white: #ffffff;
$lime: #7cc349;
$teal: #296b7f;

//secondary
$teal-light: #4e9db5;
$teal-dark: #19424e;
$almost-black: #03191f;
$lime-light: #b1ee85;
$lime-dark: #528230;
$orange: #ecba4c;

// set colors
$primary: $teal;
$secondary: $lime;

$body-bg: $almost-black;
$body-color: $white;
$link-color: $lime;

$navbar-bg: $teal-dark;
$navbar-hl: $lime-light;

$footer-bg: $black;
$footer-fg: $white;
$footer-hl: $lime-light;

$sidebar-hl: $lime-light;

$code-block-bg-alpha: -0.8;
$code-bg-alpha: -0.8;
$code-alpha: 0.9;
$code-bg: $teal-dark;
$code-color: $orange;

// font
$font-family-sans-serif: "Roboto", sans-serif;
$font-family-monospace: "Roboto Mono", monospace;
32 changes: 32 additions & 0 deletions src/ccbr_tools/templates/_extensions/fnl/fnl-light.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*-- scss:defaults --*/

// colors
// https://nih.sharepoint.com/:b:/r/sites/NCI-Fred/Communications/Shared%20Documents/Branding%20guidelines%20LIVE.pdf?csf=1&web=1&e=e9PrVO

// primary
$black: #000000;
$white: #ffffff;
$lime: #7cc349;
$teal: #296b7f;

//secondary
$teal-light: #4e9db5;
$teal-dark: #19424e;
$almost-black: #03191f;
$lime-light: #b1ee85;
$lime-dark: #528230;
$orange: #ecba4c;

// set colors
$primary: $teal-dark;
$secondary: $lime;
$link-color: $teal;

$footer-bg: black;
$footer-fg: white;

$code-color: $lime-dark;

// font
$font-family-sans-serif: "Roboto", sans-serif;
$font-family-monospace: "Roboto Mono", monospace;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import tempfile

from ccbr_tools.templates import read_template, use_template
from ccbr_tools.templates import read_template, use_template, use_quarto_ext


def test_read_template():
Expand Down Expand Up @@ -65,3 +65,17 @@ def test_use_template_blanks():
output_filepath=out_filepath,
)
assert str(exc_info.value) == "KeyError: 'MODULES'"


def test_use_quarto_ext():
with tempfile.TemporaryDirectory() as tmp_dir:
current_wd = os.getcwd()
tmp_wd = pathlib.Path(current_wd) / tmp_dir
os.chdir(tmp_wd)
use_quarto_ext("fnl")
assertions = [
pathlib.Path("_extensions/fnl").is_dir(),
pathlib.Path("_extensions/fnl/_extension.yml").is_file(),
]
os.chdir(current_wd)
assert all(assertions)

0 comments on commit 0f54b8e

Please sign in to comment.