ASML-Labs / PPTX.jl

Generate PowerPoint PPTX files from Julia
https://asml-labs.github.io/PPTX.jl/
MIT License
90 stars 7 forks source link

trying to use artifacts #49

Open ig-or opened 5 months ago

ig-or commented 5 months ago

A few very simple changes are proposed, the purpose is to be able to use a PackageCompiler.jl / make pptx file from inside the Julia app on Windows. It also addresses https://github.com/ASML-Labs/PPTX.jl/issues/15 at some point. In short, all the templates are part of the artifact now. The exact location of the artifact is an open question, though.. https://julialang.slack.com/archives/C67EFTEF3/p1715193409165059

matthijscox-asml commented 5 months ago

Thanks for this contribution!

I think you forgot to add using Artifacts in src/PPTX.jl, which is causing the currently failing build pipelines.

May I also ask how you uploaded the artifact to github?

nhz2 commented 5 months ago

Because ZipReader works on Vector{UInt8} you could also bake in the data from the default template instead of using artifacts.

include_dependency(joinpath(TEMPLATE_DIR, "no-slides.pptx"))
include_dependency(joinpath(TEMPLATE_DIR, "tableStyles.xml"))
const default_template_data = read(joinpath(TEMPLATE_DIR, "no-slides.pptx"))
const default_table_style_data = read(joinpath(TEMPLATE_DIR, "tableStyles.xml"))

This way reading the template files would happen during precompile.

ig-or commented 5 months ago

@nhz2 , this might be possible but I'm not sure how this will work with package compiler. When I tried PPTX as a part of the compiled app, TEMPLATE_DIR was pointing on the folder were the PPTX "was compiled". IMHO package compiler is not very good with "assets" but it's OK with artifacts.

ig-or commented 5 months ago

@matthijscox-asml , about "how you uploaded the artifact to github?" As I was told in Julia Slack channel, I made a fake package release (on my Github account) and added the artifact file as an assert to this release. You probably would like to change the artifact file location.

nhz2 commented 5 months ago

This should work with package compiler because the reading from the path won't happen at run time. Though you will also need to edit https://github.com/ASML-Labs/PPTX.jl/blob/64435fe29a9e50c366be5f8067f8e6b4199a8f30/src/write.jl#L144 and https://github.com/ASML-Labs/PPTX.jl/blob/64435fe29a9e50c366be5f8067f8e6b4199a8f30/src/write.jl#L70 to accept Vector{UInt8}

ig-or commented 5 months ago

@nhz2 thanks for the explanation!

matthijscox-asml commented 5 months ago

This should work with package compiler because the reading from the path won't happen at run time.

But as I understand it, when you define the path at compile time, the compiled library won't be relocatable anymore, right?

nhz2 commented 5 months ago

Yes, a package isn't relocatable if it uses a string path at runtime that was defined at compile time. One solution is to use https://github.com/JuliaPackaging/RelocatableFolders.jl or Artifacts to allow the path to change to point to the correct folder. The other option is to not read the template files at runtime.

ig-or commented 5 months ago

Can somebody have a look at the conflicts?

matthijscox-asml commented 5 months ago

Can somebody have a look at the conflicts? @ig-or you can just take the new changes, @nhz2 made a small update where he already included one template file during compilation

ig-or commented 5 months ago

Sorry for the delay. Lets see how it goes now..