Literate and Artifacts

I seem to be unable to use Literate when the script I’m trying to convert tries to load an artifact. The full setup - all files in the same folder - is printed at the bottom of this post.

  • If I execute the script by activating the package and then using include("test.jl") it executes correctely.
  • If I activate the package followed by
using Literate
Literate.markdown("test.jl"; execute=true)

I get the following error message:

[ Info: generating markdown page from `~/gits/ACE1pack/tmp/test.jl`
ERROR: LoadError: Cannot locate '(Julia)Artifacts.toml' file when attempting to use artifact 'TiAl_tutorial' in 'Main.var"##292"'
in expression starting at string:1
in expression starting at string:1
when executing the following code block in file `~/gits/ACE1pack/tmp/test.jl`

# ```
data_file = joinpath(artifact"TiAl_tutorial", "TiAl_tutorial.xyz")
# ```

Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] execute_block(sb::Module, block::String; inputfile::String)
   @ Literate ~/.julia/packages/Literate/PIFdc/src/Literate.jl:822
 [3] execute_markdown!(io::IOBuffer, sb::Module, block::String, outputdir::String; inputfile::String, flavor::Literate.DocumenterFlavor, image_formats::Vector{Tuple{MIME, String}})
   @ Literate ~/.julia/packages/Literate/PIFdc/src/Literate.jl:567
 [4] markdown(inputfile::String, outputdir::String; config::Dict{Any, Any}, kwargs::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:execute,), Tuple{Bool}}})
   @ Literate ~/.julia/packages/Literate/PIFdc/src/Literate.jl:546
 [5] top-level scope
   @ REPL[6]:1

I have found no information anywhere on how to use artifacts within Literate.jl - any suggests or pointes to working examples would be greatly appreciated.

DETAILS / FILE CONTENTS

# Project.toml 
[deps]
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"

# Artifacts.toml
[TiAl_tutorial]
git-tree-sha1 = "b437d7d5fac4424b8203d0afc31732879d3da5b2"
lazy = true

    [[TiAl_tutorial.download]]
    sha256 = "3677174b6ab4adfd07dc03235b797c88234515df793d8603cce5ab7ce0db637d"
    url = "https://github.com/ACEsuit/ACEData/blob/master/trainingsets/TiAl_tutorial.tar.gz?raw=true"

# test.jl 

# We need LazyArtifacts to obtain a dataset 

using LazyArtifacts

# ... try to obtain the dataset

data_file = joinpath(artifact"TiAl_tutorial", "TiAl_tutorial.xyz")

EDIT: previous message deleted, seems to have been an incorrect guess.

But I’ve now narrowed the problem down to the following:

using Pkg.Artifacts
block = "data_file = joinpath(artifact\"TiAl_tutorial\", \"TiAl_tutorial.xyz\")"
include_string(Main, block)     # same error message 
eval(Meta.parse(block))         # same error message 
data_file = joinpath(artifact"TiAl_tutorial", "TiAl_tutorial.xyz")       #  works as expected

I am now guessing that the @artifact_str macro behind the artifact"..." syntax sugar is the culprit? If I do the following instead, then Literate generates the MD without problems:

data_file = joinpath(artifact_path(artifact_hash("TiAl_tutorial", find_artifacts_toml("."))), "TiAl_tutorial.xyz")

Not particularly elegant though …

unless there is something nicer, does this sound like an issue / PR for Pkg.jl?

Fixed in Literate.jl#195 included in Literate version 2.13.2.

1 Like

thank you for the amazing turnaround. So just to check that I understand correctly - if I had somehow specified the working directory or output directory manually it would still have worked? From cd(config["literate_outputdir"]) I gather I should set literate_outputdir? This requires that the artifact is in that directory (or a parent)?

No that was a separate bug I found when fixing this, not related to your problem. @artifact_str looks for Artifacts.toml upwards in the file hierarchy starting with the file (@__FILE__), not the working directory.

Ok - thank you