Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] include within eval blocks, best to use abspath #186

Closed
cserteGT3 opened this issue Jun 29, 2019 · 7 comments
Closed

[docs] include within eval blocks, best to use abspath #186

cserteGT3 opened this issue Jun 29, 2019 · 7 comments

Comments

@cserteGT3
Copy link
Contributor

I can not include() .jl files and don't understand why. Only an error is generated, and serve(verb=true, nomess=true) neither tells me anything.
MWE:
testf.jl:

println("hello")

The following is in index.html:

```julia:rundiary/load
fn = "testf.jl"
println("Is this a file? $(isfile(fn))")
include(fn)
println("this is not printed")
```
\output{rundiary/load}

And the output is:

Is this a file? true
There was an error running the code.

Content of rundiary/output/load.out:

Is this a file? true
There was an error running the code.

Content of rundiary/load.jl:

# This file was generated by JuDoc, do not modify it. # hide
fn = "testf.jl"
println("Is this a file? $(isfile(fn))")
include(fn)
println("this is not printed")
@tlienart
Copy link
Owner

tlienart commented Jul 8, 2019

Hello! I'm back from a fair bit of travelling, apologies for the delay.

Two things from this:

  1. the issue has to do with paths (see below)
  2. reporting the error would be useful (and is actually easy) this will be fixed soon.

So on a prototype branch, I showed the error and it's maybe a bit surprising at first:

Simple code:
```julia:scripts/test186
fn = "tempf.jl"
write(fn, "a = 1+1")
println("Is this a file? $(isfile(fn))")
include(fn)
rm(fn)
```
done.
\output{scripts/test186}

-->

<p>Simple code: <pre><code class="language-julia">fn = "tempf.jl"
write(fn, "a = 1+1")
println("Is this a file? $(isfile(fn))")
include(fn)
rm(fn)</code></pre> done. <pre><code>Is this a file? true
There was an error running the code: LoadError("/Users/tlienart/.julia/dev/JuDoc/test/__tmp/basic/assets/scripts/test186.jl", 5, ErrorException("could not open file /Users/tlienart/.julia/dev/JuDoc/test/__tmp/basic/assets/scripts/tempf.jl")).</code></pre></p>

So it's a path issue. It's not immediately clear what/why is the issue here (I don't think it's related to JuDoc but rather to the fact that we're using nested include, since the script is included by JuDoc (using Main.include) and then there's an include in that script itself, so the include you use may not see the same path as the isfile (I don't know why though, it would be nice to investigate...)

Anyway this works in the mean time: (note the abspath)

Simple code:
```julia:scripts/test186
fn = "tempf.jl"
write(fn, "a = 1+1")
println("Is this a file? $(isfile(fn))")
include(abspath(fn))
println("Now: $a")
rm(fn)
```
done.
\output{scripts/test186}

--->

<p>Simple code: <pre><code class="language-julia">fn = "tempf.jl"
write(fn, "a = 1+1")
println("Is this a file? $(isfile(fn))")
include(abspath(fn))
println("Now: $a")
rm(fn)</code></pre> done. <pre><code>Is this a file? true
Now: 2
</code></pre></p>

tlienart added a commit that referenced this issue Jul 8, 2019
Add error message in eval block (see #186)
@cserteGT3
Copy link
Contributor Author

Hello! I'm back from a fair bit of travelling, apologies for the delay.

Me too :)

So it's a path issue. It's not immediately clear what/why is the issue here (I don't think it's related to JuDoc but rather to the fact that we're using nested include, since the script is included by JuDoc (using Main.include) and then there's an include in that script itself, so the include you use may not see the same path as the isfile (I don't know why though, it would be nice to investigate...)

So far I was just using include() and didn't think about how it works, but the docs describes this behavoir (just the relevant part from ?include):

During including, a task-local  include path is set to the directory containing the file. Nested calls to include will search relative to that path.

Anyway this works in the mean time: (note the abspath)

Thank you! The error message is also a good idea.

Maybe the docs should mention somewhere to use abspath() when using include()?

@tlienart
Copy link
Owner

Yes, I must say it's a bit of a weird use-case to be using includes inside of eval blocks 😄 but I'll add it to the doc, thanks!

@tlienart tlienart changed the title include() doesn't work [docs] include within eval blocks, best to use abspath Jul 11, 2019
@cserteGT3
Copy link
Contributor Author

Yes, I must say it's a bit of a weird use-case to be using includes inside of eval blocks 😄 but I'll add it to the doc, thanks!

Is there another way to include source file? I'd like not to "pollute" my site with that long code (ofc I could use Literate or Weave 😄)

@tlienart
Copy link
Owner

So what you want to do is something like

  • some markdown
  • include a code file
  • some markdown

?

If so you can just do that using https://tlienart.github.io/JuDoc.jl/dev/man/syntax/#Separate-evaluation-1 ? (or otherwise could you suggest an example of what you'd like to do?)

@cserteGT3
Copy link
Contributor Author

cserteGT3 commented Jul 12, 2019

So what you want to do is something like

  • some markdown
  • include a code file
  • some markdown

Yes, something like the earlier linked repo where I tested how to plot. Slowly I finish what I wanted to achieve, if you're interested here's a link.

If so you can just do that using https://tlienart.github.io/JuDoc.jl/dev/man/syntax/#Separate-evaluation-1 ? (or otherwise could you suggest an example of what you'd like to do?)

I'm satisfied as I have a working version, but will think through if my approach is the best/fastest/easiest/etc.

And again, thank you for the awesome package!

@tlienart
Copy link
Owner

thanks for the feedback and the suggestions, it's super helpful :) and when your website is online I'd be glad to add it to the list in the README if you'd like

@tlienart tlienart added the easy label Jul 12, 2019
@tlienart tlienart closed this as completed Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants