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

Add support for includet #172

Closed
navdeeprana opened this issue Aug 20, 2024 · 6 comments
Closed

Add support for includet #172

navdeeprana opened this issue Aug 20, 2024 · 6 comments

Comments

@navdeeprana
Copy link

In a Julia cell include("foo.jl") works, but using Revise; includet("foo.jl") does not.

@jkrumbiegel
Copy link
Collaborator

Could you please clarify what doesn't work? Is there an error or does nothing happen?

@navdeeprana
Copy link
Author

I get an undefvarerror when I run quarto preview index.qmd.

Attached here tarred.tar.gz

Error 1 of 1
@ /home/nrana/Work/test/index.qmd:10
UndefVarError: `add2` not defined
Stacktrace:
 [1] top-level scope
   @ ~/Work/test/index.qmd:13

ERROR: Internal julia server error

Stack trace:
    at writeJuliaCommand (file:///opt/quarto/bin/quarto.js:41721:19)
    at eventLoopTick (ext:core/01_core.js:153:7)
    at async executeJulia (file:///opt/quarto/bin/quarto.js:41615:22)
    at async Object.execute (file:///opt/quarto/bin/quarto.js:41352:20)
    at async renderExecute (file:///opt/quarto/bin/quarto.js:78033:27)
    at async renderFileInternal (file:///opt/quarto/bin/quarto.js:78201:43)
    at async renderFiles (file:///opt/quarto/bin/quarto.js:78069:17)
    at async render (file:///opt/quarto/bin/quarto.js:82929:21)
    at async renderForPreview (file:///opt/quarto/bin/quarto.js:83956:26)
    at async render (file:///opt/quarto/bin/quarto.js:83839:29)
    ````

@jkrumbiegel
Copy link
Collaborator

You can provide MWE code either here in a codeblock or in a github gist, I will not open arbitrary zip files :)

@navdeeprana
Copy link
Author

I understand, I tried just pasting it here but it the code blocks mess up the formatting, I figured out that I can use four backquotes. Anyway here it is.

Contents of test.jl

add2(x) = x + 2

Contents of index.qmd

---
engine: julia
---

```{julia}
add1(x) = x + 1
add1(2)
```

```{julia}
using Revise
includet("test.jl")
add2(5)
```

@MichaelHatherly
Copy link
Collaborator

Based on how Revise implements includet, see https://github.com/timholy/Revise.jl/blob/75a09ea92a3008d721ac09749d5168bb81426ba9/src/packagedef.jl#L1001-L1033 for details, the issue here is because of the hardcoded Main in the 1-argument method of that function. You can probably use the two argument version of it to instead write

includet(@__MODULE__, "test.jl")

Such that it evaluates in the correct module. This is because QuartoNotebookRunner defines a different "main" module into which cells are evaluated rather than using Main like the REPL does.

@MichaelHatherly
Copy link
Collaborator

Closing this as there isn't anything for us to do within this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants