JunoLab / Weave.jl

Scientific reports/literate programming for Julia
http://weavejl.mpastell.com
MIT License
821 stars 94 forks source link

Adds `:displaysize` as chunk option and chunks now correctly respect `displaysize` #433

Open torfjelde opened 3 years ago

torfjelde commented 3 years ago

AFAIK there's not a good way of setting the displaysize for IO instances in Weave.jl. In particular this leads to issues when outputting tables, e.g. https://github.com/JunoLab/Weave.jl/issues/200. The issue is made more confusing by the fact that we have a :line_width chunk option which specifies the number of columns before we wrap the lines, not truncate, and so even if you try to do

withenv("COLUMNS" => 200) do
    ...
end

within a notebook, you still end up with wrapped output even though now the truncation is okay.

So, this PR makes the following changes:

  1. All chunks are evaluated with the default displaysize. This is equivalent to the current behavior since as of right now we simply set :limit => true and thus implicitly :displaysize => displaysize() introduced in #311.
  2. Allow further specification of displaysize as a chunk option. This addresses all the annoyances with truncated tables, etc. + naturally follows the same behavior as you'd expect from IO.
  3. Disable wrap by default since it's utility is somewhat limited due to the #311 + the default value of :line_width is actually lower than the default displaysize()[2] (which is 80), hence we end up wrapping lines that "shouldn't" be wrapped according to default settings in Julia (most other packages will display according to displaysize so most outputs will take advantage of 80 cols if need be).

~I'll add docs too once I get the thumbs up that this is a good idea from ya'll :)~

EDIT: Added tests.

codecov-commenter commented 3 years ago

Codecov Report

Merging #433 (919fa4b) into master (381de22) will decrease coverage by 1.14%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #433      +/-   ##
==========================================
- Coverage   74.05%   72.91%   -1.15%     
==========================================
  Files          26       26              
  Lines        1353     1355       +2     
==========================================
- Hits         1002      988      -14     
- Misses        351      367      +16     
Flag Coverage Δ
unittests 72.91% <100.00%> (-1.15%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/config.jl 20.00% <ø> (ø)
src/run.jl 84.42% <100.00%> (+0.12%) :arrow_up:
src/rendering/common.jl 69.87% <0.00%> (-19.28%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 381de22...919fa4b. Read the comment docs.

torfjelde commented 2 years ago

@sebastianpech would you be willing to accept this?

sebastianpech commented 2 years ago

I assume that you meant to tag @pfitzseb

torfjelde commented 2 years ago

Haha, yes; sorry!