From de9a8a2efd2884b1439833806b33684c9482fea3 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Wed, 17 Mar 2021 00:01:24 +1300 Subject: [PATCH] Use IOCapture instead of withoutput (#124) fixes #138, fixes #140, closes #135 --- LICENSE.md | 27 --------- Project.toml | 2 + docs/Manifest.toml | 147 ++++++++++++++++++--------------------------- docs/make.jl | 6 +- src/Documenter.jl | 42 ------------- src/Literate.jl | 24 ++++---- 6 files changed, 76 insertions(+), 172 deletions(-) delete mode 100644 src/Documenter.jl diff --git a/LICENSE.md b/LICENSE.md index 07ca3f9..1f3e701 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -44,30 +44,3 @@ The file src/IJulia.jl contains some utilities copied from the IJulia.jl package > LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION > OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION > WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -> - - -The file src/Documenter.jl contains some utilities copied from the Documenter.jl -package (https://github.com/JuliaDocs/Documenter.jl) which is licensed under -the MIT "Expat" License: - -> Copyright (c) 2016: Michael Hatherly. -> -> Permission is hereby granted, free of charge, to any person obtaining a copy -> of this software and associated documentation files (the "Software"), to deal -> in the Software without restriction, including without limitation the rights -> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -> copies of the Software, and to permit persons to whom the Software is -> furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in all -> copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -> SOFTWARE. -> diff --git a/Project.toml b/Project.toml index 16dfca2..ab92494 100644 --- a/Project.toml +++ b/Project.toml @@ -4,10 +4,12 @@ version = "2.8.0" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" +IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" [compat] +IOCapture = "0.2" JSON = "0.18, 0.19, 0.20, 0.21, 1" julia = "1" diff --git a/docs/Manifest.toml b/docs/Manifest.toml index 63e1ad7..f650214 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -2,9 +2,9 @@ [[Adapt]] deps = ["LinearAlgebra"] -git-tree-sha1 = "345a14764e43fe927d6f5c250fe4c8e4664e6ee8" +git-tree-sha1 = "ffcfa2d345aaee0ef3d8346a073d5dd03c983ebe" uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -version = "2.4.0" +version = "3.2.0" [[Artifacts]] deps = ["Pkg"] @@ -35,9 +35,9 @@ version = "3.10.2" [[ColorTypes]] deps = ["FixedPointNumbers", "Random"] -git-tree-sha1 = "4bffea7ed1a9f0f3d1a131bbcd4b925548d75288" +git-tree-sha1 = "32a2b8af383f11cbb65803883837a149d10dfe8a" uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" -version = "0.10.9" +version = "0.10.12" [[Colors]] deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Reexport"] @@ -57,12 +57,6 @@ git-tree-sha1 = "8e695f735fca77e9708e795eda62afdb869cbb70" uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" version = "0.3.4+0" -[[Conda]] -deps = ["JSON", "VersionParsing"] -git-tree-sha1 = "c0647249d785f1d5139c0cc96db8f6b32f7ec416" -uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" -version = "1.5.0" - [[Contour]] deps = ["StaticArrays"] git-tree-sha1 = "9f02045d934dc030edad45944ea80dbd1f0ebea7" @@ -70,15 +64,15 @@ uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" version = "0.5.7" [[DataAPI]] -git-tree-sha1 = "ad84f52c0b8f05aa20839484dbaf01690b41ff84" +git-tree-sha1 = "dfb3b7e89e395be1e25c2ad6d7690dc29cc53b1d" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.4.0" +version = "1.6.0" [[DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "fb0aa371da91c1ff9dc7fbed6122d3e411420b9c" +git-tree-sha1 = "4437b64df1e0adccc3e5d1adbc3ac741095e4677" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.18.8" +version = "0.18.9" [[DataValueInterfaces]] git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" @@ -93,11 +87,6 @@ uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" deps = ["Mmap"] uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" -[[DisplayAs]] -git-tree-sha1 = "44e8d47bc0b56ec09115056a692e5fa0976bfbff" -uuid = "0b91fe84-8a4c-11e9-3e1d-67c38462b6d6" -version = "0.1.2" - [[Distributed]] deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" @@ -110,7 +99,9 @@ version = "0.8.3" [[Documenter]] deps = ["Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] -git-tree-sha1 = "b7715ae18be02110a8cf9cc8ed2ccdb1e3e3aba2" +git-tree-sha1 = "79536d7359b324b20afef3d32baaf8e3e7f4c309" +repo-rev = "master" +repo-url = "https://github.com/JuliaDocs/Documenter.jl.git" uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" version = "0.26.1" @@ -138,9 +129,6 @@ git-tree-sha1 = "3cc57ad0a213808473eafef4845a74766242e05f" uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5" version = "4.3.1+4" -[[FileWatching]] -uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" - [[FixedPointNumbers]] deps = ["Statistics"] git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc" @@ -179,9 +167,9 @@ version = "3.3.2+1" [[GR]] deps = ["Base64", "DelimitedFiles", "GR_jll", "HTTP", "JSON", "LinearAlgebra", "Pkg", "Printf", "Random", "Serialization", "Sockets", "Test", "UUIDs"] -git-tree-sha1 = "b90b826782cb3ac5b7a7f41b3fd0113180257ed4" +git-tree-sha1 = "12d971c928b7ecf19b748a2c7df6a365690dbf2c" uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" -version = "0.53.0" +version = "0.55.0" [[GR_jll]] deps = ["Artifacts", "Bzip2_jll", "Cairo_jll", "FFMPEG_jll", "Fontconfig_jll", "GLFW_jll", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pixman_jll", "Pkg", "Qt_jll", "Zlib_jll", "libpng_jll"] @@ -191,9 +179,9 @@ version = "0.53.0+0" [[GeometryBasics]] deps = ["EarCut_jll", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"] -git-tree-sha1 = "876f77f0d3253e882ff588af1c95d0e4a86c9766" +git-tree-sha1 = "c7f81b22b6c255861be4007a16bfdeb60e1c7f9b" uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326" -version = "0.3.5" +version = "0.3.11" [[Gettext_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"] @@ -213,22 +201,16 @@ uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe" version = "1.0.0" [[HTTP]] -deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"] -git-tree-sha1 = "c7ec02c4c6a039a98a15f955462cd7aea5df4508" +deps = ["Base64", "Dates", "IniFile", "MbedTLS", "NetworkOptions", "Sockets", "URIs"] +git-tree-sha1 = "c9f380c76d8aaa1fa7ea9cf97bddbc0d5b15adc2" uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "0.8.19" - -[[IJulia]] -deps = ["Base64", "Conda", "Dates", "InteractiveUtils", "JSON", "Markdown", "MbedTLS", "Pkg", "Printf", "REPL", "Random", "SoftGlobalScope", "Test", "UUIDs", "ZMQ"] -git-tree-sha1 = "0862f73c51b49d80168e75b141a26d1cbb9a7295" -uuid = "7073ff75-c697-5162-941a-fcdaad2a7d2a" -version = "1.23.1" +version = "0.9.5" [[IOCapture]] deps = ["Logging"] -git-tree-sha1 = "377252859f740c217b936cebcd918a44f9b53b59" +git-tree-sha1 = "1868e4e7ad2f93d8de0904d89368c527b46aa6a1" uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" -version = "0.1.1" +version = "0.2.1" [[IniFile]] deps = ["Test"] @@ -280,15 +262,15 @@ uuid = "dd4b983a-f0e5-5f8d-a1b7-129d4a5fb1ac" version = "2.10.0+3" [[LaTeXStrings]] -git-tree-sha1 = "c7aebfecb1a60d59c0fe023a68ec947a208b1e6b" +git-tree-sha1 = "c7f1c695e06c01b95a67f0cd1d34994f3e7db104" uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" -version = "1.2.0" +version = "1.2.1" [[Latexify]] deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "Printf", "Requires"] -git-tree-sha1 = "3a0084cec7bf157edcb45a67fac0647f88fe5eaf" +git-tree-sha1 = "fbc08b5a78e264ba3d19da90b36ce1789ca67a40" uuid = "23fbe1c1-3f47-55db-b15f-69d7ec21a316" -version = "0.14.7" +version = "0.14.11" [[LibGit2]] deps = ["Printf"] @@ -356,10 +338,10 @@ deps = ["Libdl"] uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" [[Literate]] -deps = ["Base64", "DisplayAs", "IJulia", "JSON", "REPL"] +deps = ["Base64", "IOCapture", "JSON", "REPL"] path = ".." uuid = "98b081ad-f1c9-55d3-8b20-4c87d4299306" -version = "2.7.0" +version = "2.8.0" [[Logging]] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" @@ -393,9 +375,9 @@ version = "0.3.1" [[Missings]] deps = ["DataAPI"] -git-tree-sha1 = "ed61674a0864832495ffe0a7e889c0da76b0f4c8" +git-tree-sha1 = "f8c673ccc215eb50fcadb285f522420e29e69e1c" uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" -version = "0.4.4" +version = "0.4.5" [[Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" @@ -405,6 +387,11 @@ git-tree-sha1 = "bfe47e760d60b82b66b61d2d44128b62e3a369fb" uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" version = "0.3.5" +[[NetworkOptions]] +git-tree-sha1 = "ed3157f48a05543cce9b241e1f2815f7e843d96e" +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" +version = "1.2.0" + [[Ogg_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "a42c0f138b9ebe8b58eba2271c5053773bde52d0" @@ -424,9 +411,9 @@ uuid = "91d4177d-7536-5919-b921-800302f37372" version = "1.3.1+3" [[OrderedCollections]] -git-tree-sha1 = "cf59cfed2e2c12e8a2ff0a4f1e9b2cd8650da6db" +git-tree-sha1 = "4fa2ba51070ec13fcc7517db714445b4ab986bdf" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.3.2" +version = "1.4.0" [[PCRE_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -436,9 +423,9 @@ version = "8.42.0+4" [[Parsers]] deps = ["Dates"] -git-tree-sha1 = "50c9a9ed8c714945e01cd53a21007ed3865ed714" +git-tree-sha1 = "223a825cccef2228f3fdbf2ecc7ca93363059073" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "1.0.15" +version = "1.0.16" [[Pixman_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -452,9 +439,9 @@ uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" [[PlotThemes]] deps = ["PlotUtils", "Requires", "Statistics"] -git-tree-sha1 = "c6f5ea535551b3b16835134697f0c65d06c94b91" +git-tree-sha1 = "a3a964ce9dc7898193536002a6dd892b1b5a6f1d" uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" -version = "2.0.0" +version = "2.0.1" [[PlotUtils]] deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"] @@ -464,9 +451,9 @@ version = "1.0.10" [[Plots]] deps = ["Base64", "Contour", "Dates", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "JSON", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"] -git-tree-sha1 = "4797acb266b8d9ff316f4581924e71c6709f152d" +git-tree-sha1 = "142dd04f5060c04de91cc10ca76dffb291a02426" uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" -version = "1.10.1" +version = "1.10.6" [[Printf]] deps = ["Unicode"] @@ -493,9 +480,9 @@ version = "1.1.1" [[RecipesPipeline]] deps = ["Dates", "NaNMath", "PlotUtils", "RecipesBase"] -git-tree-sha1 = "9ea2f5bf1b26918b16e9f885bb8e05206bfc2144" +git-tree-sha1 = "c4d54a78e287de7ec73bbc928ce5eb3c60f80b24" uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c" -version = "0.2.1" +version = "0.3.1" [[Reexport]] git-tree-sha1 = "57d8440b0c7d98fc4f889e478e80f268d534c9d5" @@ -504,9 +491,9 @@ version = "1.0.0" [[Requires]] deps = ["UUIDs"] -git-tree-sha1 = "cfbac6c1ed70c002ec6361e7fd334f02820d6419" +git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621" uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "1.1.2" +version = "1.1.3" [[SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" @@ -533,12 +520,6 @@ version = "0.3.2" [[Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" -[[SoftGlobalScope]] -deps = ["REPL"] -git-tree-sha1 = "986ec2b6162ccb95de5892ed17832f95badf770c" -uuid = "b85f4697-e234-5449-a836-ec8e2f98b302" -version = "1.1.0" - [[SortingAlgorithms]] deps = ["DataStructures", "Random", "Test"] git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" @@ -561,15 +542,15 @@ uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [[StatsBase]] deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics"] -git-tree-sha1 = "7bab7d4eb46b225b35179632852b595a3162cb61" +git-tree-sha1 = "a83fa3021ac4c5a918582ec4721bc0cf70b495a9" uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" -version = "0.33.2" +version = "0.33.4" [[StructArrays]] deps = ["Adapt", "DataAPI", "Tables"] -git-tree-sha1 = "8099ed9fb90b6e754d6ba8c6ed8670f010eadca0" +git-tree-sha1 = "26ea43b4be7e919a2390c3c0f824e7eb4fc19a0a" uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" -version = "0.4.4" +version = "0.5.0" [[TableTraits]] deps = ["IteratorInterfaceExtensions"] @@ -579,14 +560,19 @@ version = "1.0.0" [[Tables]] deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] -git-tree-sha1 = "240d19b8762006ff04b967bdd833269ad642d550" +git-tree-sha1 = "f03fc113290ee7726b173fc7ea661260d204b3f2" uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -version = "1.2.2" +version = "1.4.0" [[Test]] deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +[[URIs]] +git-tree-sha1 = "7855809b88d7b16e9b029afd17880930626f54a2" +uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" +version = "1.2.0" + [[UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" @@ -594,11 +580,6 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [[Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" -[[VersionParsing]] -git-tree-sha1 = "80229be1f670524750d905f8fc8148e5a8c4537f" -uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" -version = "1.2.0" - [[Wayland_jll]] deps = ["Artifacts", "Expat_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg", "XML2_jll"] git-tree-sha1 = "dc643a9b774da1c2781413fd7b6dcd2c56bb8056" @@ -749,18 +730,6 @@ git-tree-sha1 = "79c31e7844f6ecf779705fbc12146eb190b7d845" uuid = "c5fb5394-a638-5e4d-96e5-b29de1b5cf10" version = "1.4.0+3" -[[ZMQ]] -deps = ["FileWatching", "Sockets", "ZeroMQ_jll"] -git-tree-sha1 = "fc68e8a3719166950a0f3e390a14c7302c48f8de" -uuid = "c2297ded-f4af-51ae-bb23-16f91089e4e1" -version = "1.2.1" - -[[ZeroMQ_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "bba617292e040408cb72baa03c20f43583bf239f" -uuid = "8f1865be-045e-5c20-9c9f-bfbfb0764568" -version = "4.3.2+5" - [[Zlib_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "320228915c8debb12cb434c59057290f0834dbf6" @@ -769,9 +738,9 @@ version = "1.2.11+18" [[Zstd_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "6f1abcb0c44f184690912aa4b0ba861dd64f11b9" +git-tree-sha1 = "2c1332c54931e83f8f94d310fa447fd743e8d600" uuid = "3161d3a3-bdf6-5164-811a-617609db77b4" -version = "1.4.5+2" +version = "1.4.8+0" [[libass_jll]] deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] diff --git a/docs/make.jl b/docs/make.jl index 5e37d38..7610152 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -4,7 +4,8 @@ if haskey(ENV, "GITHUB_ACTIONS") ENV["JULIA_DEBUG"] = "Documenter" end -Documenter.post_status(; type="pending", repo="github.com/fredrikekre/Literate.jl.git") +deployconfig = Documenter.auto_detect_deploy_system() +Documenter.post_status(deployconfig; type="pending", repo="github.com/fredrikekre/Literate.jl.git") using Literate using Plots # to not capture precompilation output @@ -31,7 +32,7 @@ Literate.script(joinpath(@__DIR__, "src/outputformats.jl"), OUTPUT; credit = fal if haskey(ENV, "GITHUB_ACTIONS") folder = Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do Documenter.deploy_folder( - Documenter.auto_detect_deploy_system(); + deployconfig; repo = "github.com/fredrikekre/Literate.jl.git", devbranch = "master", push_preview = true, @@ -66,4 +67,5 @@ makedocs( deploydocs( repo = "github.com/fredrikekre/Literate.jl.git", push_preview=true, + deploy_config = deployconfig, ) diff --git a/src/Documenter.jl b/src/Documenter.jl deleted file mode 100644 index 115d3e7..0000000 --- a/src/Documenter.jl +++ /dev/null @@ -1,42 +0,0 @@ -# this file contains some utilities copied from the Documenter.jl package -# (https://github.com/JuliaDocs/Documenter.jl), see LICENSE.md for license -module Documenter - -function withoutput(f) - # Save the default output streams. - default_stdout = stdout - default_stderr = stderr - - # Redirect both the `stdout` and `stderr` streams to a single `Pipe` object. - pipe = Pipe() - Base.link_pipe!(pipe; reader_supports_async = true, writer_supports_async = true) - redirect_stdout(pipe.in) - redirect_stderr(pipe.in) - # Also redirect logging stream to the same pipe - logger = Base.CoreLogging.SimpleLogger(pipe.in) - - # Bytes written to the `pipe` are captured in `output` and converted to a `String`. - output = UInt8[] - - # Run the function `f`, capturing all output that it might have generated. - # Success signals whether the function `f` did or did not throw an exception. - result, success, backtrace = Base.CoreLogging.with_logger(logger) do - try - f(), true, Vector{Ptr{Cvoid}}() - catch err - err, false, catch_backtrace() - finally - # Force at least a single write to `pipe`, otherwise `readavailable` blocks. - println() - # Restore the original output streams. - redirect_stdout(default_stdout) - redirect_stderr(default_stderr) - # NOTE: `close` must always be called *after* `readavailable`. - append!(output, readavailable(pipe)) - close(pipe) - end - end - return result, success, backtrace, chomp(String(output)) -end - -end diff --git a/src/Literate.jl b/src/Literate.jl index 0398148..1ffdc79 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -6,12 +6,10 @@ https://fredrikekre.github.io/Literate.jl/ for documentation. """ module Literate -import JSON, REPL +import JSON, REPL, IOCapture include("IJulia.jl") import .IJulia -include("Documenter.jl") -import .Documenter # # Some simple rules: # @@ -708,17 +706,19 @@ function execute_block(sb::Module, block::String) # Push a capturing display on the displaystack disp = LiterateDisplay() pushdisplay(disp) - # r is the result - # status = (true|false) - # _: backtrace - # str combined stdout, stderr output - r, status, _, str = Documenter.withoutput() do + # We use the following fields of the object returned by IOCapture.capture: + # - c.value: return value of the do-block (or the error object, if it throws) + # - c.error: set to `true` if the do-block throws an error + # - c.output: combined stdout and stderr + # `rethrow = Union{}` means that we try-catch all the exceptions thrown in the do-block + # and return them via the return value (they get handled below). + c = IOCapture.capture(rethrow = Union{}) do include_string(sb, block) end - popdisplay(disp) # Documenter.withoutput has a try-catch so should always end up here - if !status + popdisplay(disp) # IOCapture.capture has a try-catch so should always end up here + if c.error error(""" - $(sprint(showerror, r)) + $(sprint(showerror, c.value)) when executing the following code block ```julia @@ -726,7 +726,7 @@ function execute_block(sb::Module, block::String) ``` """) end - return r, str, disp.data + return c.value, c.output, disp.data end end # module