From d4c65729e40140cd8bfcd499417a332faf147d35 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 18 Jun 2021 09:50:38 +0100 Subject: [PATCH] Use `RelocatableFolders` for assets folders. --- Project.toml | 4 +-- src/RelocatableFolders.jl | 57 --------------------------------------- src/Weave.jl | 11 +++----- 3 files changed, 5 insertions(+), 67 deletions(-) delete mode 100644 src/RelocatableFolders.jl diff --git a/Project.toml b/Project.toml index 8e314d4..6854eb9 100644 --- a/Project.toml +++ b/Project.toml @@ -12,9 +12,8 @@ Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" +RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00" Requires = "ae029012-a4dd-5104-9daa-d747884805df" -SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" -Scratch = "6c6a2e73-6563-6170-7368-637461726353" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" @@ -24,7 +23,6 @@ JSON = "0.21" Mustache = "0.4.1, 0.5, 1" Plots = "0.28, 0.29, 1.0" Requires = "1.0" -Scratch = "1.1" YAML = "0.3, 0.4" julia = "1.2" diff --git a/src/RelocatableFolders.jl b/src/RelocatableFolders.jl deleted file mode 100644 index 9fd94e8..0000000 --- a/src/RelocatableFolders.jl +++ /dev/null @@ -1,57 +0,0 @@ -module RelocatableFolders - -import Scratch, SHA - -export @folder_str - -macro folder_str(path) - dir = string(__source__.file) - dir = isfile(dir) ? dirname(dir) : pwd() - return :($(Folder)($__module__, $dir, $(esc(path)))) -end - -struct Folder <: AbstractString - mod::Module - path::String - hash::String - files::Dict{String,Vector{UInt8}} - - function Folder(mod::Module, dir, path::AbstractString) - path = isabspath(path) ? path : normpath(joinpath(dir, path)) - isdir(path) || throw(ArgumentError("not a directory: `$path`")) - files = Dict{String,Vector{UInt8}}() - ctx = SHA.SHA1_CTX() - for (root, _, fs) in walkdir(path), f in fs - fullpath = joinpath(root, f) - include_dependency(fullpath) - SHA.update!(ctx, codeunits(fullpath)) - content = read(fullpath) - SHA.update!(ctx, content) - files[relpath(fullpath, path)] = content - end - return new(mod, path, string(Base.SHA1(SHA.digest!(ctx))), files) - end -end - -Base.show(io::IO, path::Folder) = print(io, repr(path.path)) -Base.ncodeunits(f::Folder) = ncodeunits(getpath(f)) -Base.isvalid(f::Folder, index::Integer) = isvalid(getpath(f), index) -Base.iterate(f::Folder) = iterate(getpath(f)) -Base.iterate(f::Folder, state::Integer) = iterate(getpath(f), state) -Base.String(f::Folder) = String(getpath(f)) - -function getpath(f::Folder) - isdir(f.path) && return f.path - dir = Scratch.get_scratch!(f.mod, f.hash) - if !isempty(f.files) && !ispath(joinpath(dir, first(keys(f.files)))) - cd(dir) do - for (file, blob) in f.files - mkpath(dirname(file)) - write(file, blob) - end - end - end - return dir -end - -end # module diff --git a/src/Weave.jl b/src/Weave.jl index c3483ae..a873bc6 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -1,16 +1,13 @@ module Weave -using Highlights, Mustache, Requires, Pkg, REPL - -include("RelocatableFolders.jl") -using .RelocatableFolders +using Highlights, Mustache, Requires, Pkg, REPL, RelocatableFolders # directories const PKG_DIR = normpath(@__DIR__, "..") -const TEMPLATE_DIR = folder"../templates" -const STYLESHEET_DIR = folder"../stylesheets" +const TEMPLATE_DIR = @path joinpath(PKG_DIR, "templates") +const STYLESHEET_DIR = @path joinpath(PKG_DIR, "stylesheets") # keeps paths of sample documents for easy try -const EXAMPLE_FOLDER = folder"../examples" +const EXAMPLE_FOLDER = @path joinpath(PKG_DIR, "examples") # constant names const WEAVE_OPTION_NAME = "weave_options"