Browse Source

Make output directory default to pwd.

pull/110/head
Fredrik Ekre 6 years ago
parent
commit
2ba316ac90
  1. 4
      CHANGELOG.md
  2. 25
      src/Literate.jl
  3. 15
      test/runtests.jl

4
CHANGELOG.md

@ -1,5 +1,9 @@
# Literate.jl changelog # Literate.jl changelog
## Version `v2.5`
* ![Feature][badge-feature] The output directory now defaults to `pwd()` ([TBD][TBD]).
## Version `v2.4` ## Version `v2.4`
* ![Feature][badge-feature] Markdown output can now be executed and the result included * ![Feature][badge-feature] Markdown output can now be executed and the result included

25
src/Literate.jl

@ -299,14 +299,17 @@ See the manual section about [Configuration](@ref) for more information.
const DEFAULT_CONFIGURATION=nothing # Dummy const for documentation const DEFAULT_CONFIGURATION=nothing # Dummy const for documentation
""" """
Literate.script(inputfile, outputdir; config::Dict=Dict(), kwargs...) Literate.script(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
Generate a plain script file from `inputfile` and write the result to `outputdir`. Generate a plain script file from `inputfile` and write the result to `outputdir`.
!!! compat "Literate 2.5"
Default output directory `pwd` requires at least Literate version 2.5.
See the manual section on [Configuration](@ref) for documentation See the manual section on [Configuration](@ref) for documentation
of possible configuration with `config` and other keyword arguments. of possible configuration with `config` and other keyword arguments.
""" """
function script(inputfile, outputdir; config::Dict=Dict(), kwargs...) function script(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
# Create configuration by merging default and userdefined # Create configuration by merging default and userdefined
config = create_configuration(inputfile; user_config=config, user_kwargs=kwargs) config = create_configuration(inputfile; user_config=config, user_kwargs=kwargs)
@ -351,6 +354,10 @@ function script(inputfile, outputdir; config::Dict=Dict(), kwargs...)
isdir(outputdir) || error("not a directory: $(outputdir)") isdir(outputdir) || error("not a directory: $(outputdir)")
outputfile = joinpath(outputdir, config["name"]::String * ".jl") outputfile = joinpath(outputdir, config["name"]::String * ".jl")
if inputfile == outputfile
throw(ArgumentError("outputfile (`$outputfile`) is identical to inputfile (`$inputfile`)"))
end
@info "writing result to `$(Base.contractuser(outputfile))`" @info "writing result to `$(Base.contractuser(outputfile))`"
write(outputfile, content) write(outputfile, content)
@ -358,15 +365,18 @@ function script(inputfile, outputdir; config::Dict=Dict(), kwargs...)
end end
""" """
Literate.markdown(inputfile, outputdir; config::Dict=Dict(), kwargs...) Literate.markdown(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
Generate a markdown file from `inputfile` and write the result Generate a markdown file from `inputfile` and write the result
to the directory `outputdir`. to the directory `outputdir`.
!!! compat "Literate 2.5"
Default output directory `pwd` requires at least Literate version 2.5.
See the manual section on [Configuration](@ref) for documentation See the manual section on [Configuration](@ref) for documentation
of possible configuration with `config` and other keyword arguments. of possible configuration with `config` and other keyword arguments.
""" """
function markdown(inputfile, outputdir; config::Dict=Dict(), kwargs...) function markdown(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
# Create configuration by merging default and userdefined # Create configuration by merging default and userdefined
config = create_configuration(inputfile; user_config=config, user_kwargs=kwargs, type=:md) config = create_configuration(inputfile; user_config=config, user_kwargs=kwargs, type=:md)
@ -487,14 +497,17 @@ line_is_nbmeta(line::Pair) = line_is_nbmeta(line.second)
line_is_nbmeta(line) = startswith(line, "%% ") line_is_nbmeta(line) = startswith(line, "%% ")
""" """
Literate.notebook(inputfile, outputdir; config::Dict=Dict(), kwargs...) Literate.notebook(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
Generate a notebook from `inputfile` and write the result to `outputdir`. Generate a notebook from `inputfile` and write the result to `outputdir`.
!!! compat "Literate 2.5"
Default output directory `pwd` requires at least Literate version 2.5.
See the manual section on [Configuration](@ref) for documentation See the manual section on [Configuration](@ref) for documentation
of possible configuration with `config` and other keyword arguments. of possible configuration with `config` and other keyword arguments.
""" """
function notebook(inputfile, outputdir; config::Dict=Dict(), kwargs...) function notebook(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
# Create configuration by merging default and userdefined # Create configuration by merging default and userdefined
config = create_configuration(inputfile; user_config=config, user_kwargs=kwargs) config = create_configuration(inputfile; user_config=config, user_kwargs=kwargs)

15
test/runtests.jl

@ -413,6 +413,11 @@ const GITLAB_ENV = Dict(
# verify that inputfile exists # verify that inputfile exists
@test_throws ArgumentError Literate.script("nonexistent.jl", outdir) @test_throws ArgumentError Literate.script("nonexistent.jl", outdir)
# default output directory
Literate.script(inputfile; name="default-output-directory")
@test isfile("default-output-directory.jl")
@test_throws ArgumentError Literate.script(inputfile)
end end
end end
end end end end
@ -684,6 +689,11 @@ end end
# verify that inputfile exists # verify that inputfile exists
@test_throws ArgumentError Literate.markdown("nonexistent.jl", outdir) @test_throws ArgumentError Literate.markdown("nonexistent.jl", outdir)
# default output directory
@test !isfile("inputfile.md")
Literate.markdown(inputfile; execute=false)
@test isfile("inputfile.md")
end end
end end
end end end end
@ -983,6 +993,11 @@ end end
# verify that inputfile exists # verify that inputfile exists
@test_throws ArgumentError Literate.notebook("nonexistent.jl", outdir) @test_throws ArgumentError Literate.notebook("nonexistent.jl", outdir)
# default output directory
@test !isfile("inputfile.ipynb")
Literate.notebook(inputfile; execute=false)
@test isfile("inputfile.ipynb")
# world time problem with `IJulia.display_dict` # world time problem with `IJulia.display_dict`
write(inputfile, """ write(inputfile, """
struct VegaLiteRenderable end struct VegaLiteRenderable end

Loading…
Cancel
Save