Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
gagolews committed Oct 17, 2023
1 parent f0a7abc commit a23ac19
Show file tree
Hide file tree
Showing 101 changed files with 1,217 additions and 1,866 deletions.
2 changes: 1 addition & 1 deletion .devel/sphinx/genieclust_inequality.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
genieclust.inequality
===================
=====================

.. automodule:: genieclust.inequality
:members:
11 changes: 6 additions & 5 deletions .devel/sphinx/weave/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
# Copyright (c) 2013-2023, Marek Gagolewski <https://www.gagolewski.com>

FILES_RMD = \
basics.Rmd \
sklearn_toy_example.Rmd \
r.Rmd


FILES_RSTW = \
sklearn_toy_example.rstw \
basics.rstw \
benchmarks_ar.rstw \
benchmarks_details.rstw \
benchmarks_approx.rstw \
noise.rstw \
sparse.rstw \
string.rstw \
timings.rstw

# string.rstw \
# sparse.rstw \

RMD_MD_OUTPUTS=$(patsubst %.Rmd,%.md,$(FILES_RMD))
#RMD_RST_OUTPUTS=$(patsubst %.Rmd,%.rst,$(FILES_RMD))

RSTW_RST_OUTPUTS=$(patsubst %.rstw,%.rst,$(FILES_RSTW))

%.md: %.Rmd
Rscript -e 'knitr::knit("$<", "$@")'
./Rmd2md.sh "$<"

#%.rst: %.md
# pandoc -f markdown+grid_tables --wrap=none "$<" -o "$@"
Expand Down
11 changes: 11 additions & 0 deletions .devel/sphinx/weave/Rmd2md-patch.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (C) 2020-2023, Marek Gagolewski <https://www.gagolewski.com>

# I only want ```{r...``` and ```{python...``` to be recognised as
# chunks to-be processed by knitr so that they can be placed within
# MyST's nested admonitions

all_patterns_new <- knitr:::all_patterns
all_patterns_new$md$chunk.begin <- "^[\t >]*```\\s*\\{((r|python)( *[ ,].*)?)\\}\\s*$"
all_patterns_new$md$chunk.end <- "^[\t >]*```\\s*$"
unlockBinding("all_patterns", getNamespace("knitr"))
assign("all_patterns", all_patterns_new, getNamespace("knitr"))
95 changes: 95 additions & 0 deletions .devel/sphinx/weave/Rmd2md.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

# Copyright (C) 2020-2023, Marek Gagolewski <https://www.gagolewski.com>

set -e

if [ ! -f "${1}" ]; then
echo "The input file does not exist or was not provided."
exit 1
fi

basename="${1/%.Rmd/}"
tmpdir="${1/%.Rmd/}"
knitrfile="tmp-md-${1}"
outfile="${1/%.Rmd/.md}"

echo "Rmd2md ${1}${outfile}..."

rm -f "${knitrfile}"
rm -f "${outfile}"

#mkdir -p "cache"

touch "${knitrfile}"

echo "\`\`\`{r __rinit__,echo=FALSE,warning=FALSE,message=FALSE,results='hide'}" >> "${knitrfile}"
cat options.R >> "${knitrfile}"
echo "\`\`\`" >> "${knitrfile}"
echo "" >> "${knitrfile}"

echo "\`\`\`{python __pyinit__,echo=FALSE,warning=FALSE,message=FALSE,results='hide'}" >> "${knitrfile}"
cat options.py >> "${knitrfile}"
echo "\`\`\`" >> "${knitrfile}"
echo "" >> "${knitrfile}"

cat "${1}" >> "${knitrfile}"

# remove HTML comments <!-- ... --> (in a brute force way; beware)
perl -0pi -e 's/(?s)<!--.*?-->\n?//g' "${knitrfile}"

Rscript -e "\
library('knitr'); \
source('Rmd2md-patch.R'); \
opts_knit\$set(
progress=FALSE, \
verbose=TRUE, \
unnamed.chunk.label='${basename}' \
); \
opts_chunk\$set( \
cache.path='${tmpdir}-cache/', \
fig.path='${tmpdir}-figures/' \
); \
knit('${knitrfile}', '${outfile}')
"

rm -f "${knitrfile}"


if [ -d "${tmpdir}-figures" ]
then
for f in ${tmpdir}-figures/*.pdf
do
if [ "$f" -nt "${f/.pdf/.png}" ]
then
echo "Converting ${f} to png...."
convert -density 96 "$f" "${f/.pdf/.png}"
fi
done
fi

# move #> comments inside code blocks outside
Rscript -e "\
source('extract-code-comments.R'); \
extract_code_comments('${outfile}')
"

# convert paths: sphinx/chapter/ → ./
sed -ri -e's/sphinx\/chapter\///g' "${outfile}"

# {chapref}`ref` → {numref}`Chapter %s <ref>`
sed -ri -e's/\{numref\}`chap:([^`]+)`/{numref}`Chapter %s <chap:\1>`/g' "${outfile}"

# {help}`topic` → {command}`help`{code}`("topic")`
sed -ri -e's/\{help\}`([^`]+)`/{command}`help`{code}`("\1")`/g' "${outfile}"

# horizontal lines are bigskips
sed -i -e 's/^\-\-\-$/```{raw} latex\n\\bigskip\n```\n\n```{raw} html\n<div style="margin-top: 1em"><\/div>\n```\n/g' "${outfile}"

# merge input and output chunks:
sed -rz --in-place 's/(\s)```\n\n+```\n/\1/g' "${outfile}"
# merge output and input chunks:
sed -rz --in-place 's/(\s)```\n\n+```r\n/\1/g' "${outfile}"
sed -rz --in-place 's/(\s)```\n\n+```python\n/\1/g' "${outfile}"

echo "Rmd2md ${1}${outfile} DONE."
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a23ac19

Please sign in to comment.