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

Where are functions defined? Docstrings not found #265

Open
gdalle opened this issue Sep 19, 2023 · 7 comments
Open

Where are functions defined? Docstrings not found #265

gdalle opened this issue Sep 19, 2023 · 7 comments

Comments

@gdalle
Copy link

gdalle commented Sep 19, 2023

Source code:

## Documentation

Even if your code does everything it is supposed to, it will be useless to others (and pretty soon to yourself) without proper documentation.
Adding [docstrings](https://docs.julialang.org/en/v1/manual/documentation/) everywhere needs to be a second nature.

```!
"""
    myfunc(a, b; kwargs...)

One-line sentence describing the purpose of the function,
just below the (indented) signature.

More details if needed.
"""
function myfunc end;
```

This way, readers and users of your code can query them through the REPL help mode:

```?
myfunc
```

Result:
image

@tlienart
Copy link
Owner

the offending lines are

line = first(split(ci.code, r"\r?\n", limit=2))
r = eval(Meta.parse("@doc $line"))

I suspect the eval should be run in the page module, this one amounts to Main.eval(...).

could you try swapping this for lc.nb_code.mdl.eval(...)? (I can try myself but am away from my dev laptop)

@gdalle gdalle mentioned this issue Sep 19, 2023
@gdalle
Copy link
Author

gdalle commented Sep 19, 2023

Nope, doesn't work, but no rush

@tlienart
Copy link
Owner

Hmm :'(

this:

julia> module A
       """
       abc
       """
       foo(x) = 0
       end
Main.A

help?> A.foo
  abc

julia> A.eval("@doc foo")
"@doc foo"

julia> A.eval(Meta.parse("@doc foo"))
  abc

works but there's likely something a bit subtle going on... might end up asking this one on Discourse, I don't understand well how docstrings are processed

@gdalle
Copy link
Author

gdalle commented Sep 19, 2023

It's not just about docstrings, I also have the issue with modules

@gdalle
Copy link
Author

gdalle commented Sep 19, 2023

Screenshot 2023-09-19 at 21 22 52

@tlienart
Copy link
Owner

tlienart commented Sep 20, 2023

hmm we're wading into tricky territory here in terms of how far Xranklin can go to make code execution inside a module look like the normal REPL, demoing pkg stuff is likely to be on the edge of that..

It looks like if the package is already in your dev path it should work though:

julia> lc = Xranklin.ToyLocalContext()

julia> s = """
       ```>
       using Pkg
       Pkg.develop(path="/Users/tlienart/.julia/dev/FP2")
       using FP2
       
       FP2.subs("abc", 2:3)
       ```
       """

julia> html(s, lc) |> println
[ Info:   ⏯️  evaluating cell auto_cell_1_1...
[ Info:   ⏯️  evaluating cell auto_cell_1_2...
[ Info:   ⏯️  evaluating cell auto_cell_1_3...
[ Info:   ⏯️  evaluating cell auto_cell_1_4...
<pre><code class="julia-repl"><span class="sgr32"><span class="sgr1">julia&gt;</span></span> using Pkg

<span class="sgr32"><span class="sgr1">julia&gt;</span></span> Pkg.develop(path=&quot;/Users/tlienart/.julia/dev/FP2&quot;)
<span class="sgr32"><span class="sgr1">   Resolving</span></span> package versions...
<span class="sgr32"><span class="sgr1">    Updating</span></span> `~/.julia/dev/Xranklin/Project.toml`
  <span class="sgr90">[c78977f6] </span><span class="sgr92">+ FP2 v0.1.0 `~/.julia/dev/FP2`</span>
<span class="sgr32"><span class="sgr1">    Updating</span></span> `~/.julia/dev/Xranklin/Manifest.toml`
  <span class="sgr90">[67c07d97] </span><span class="sgr92">+ Automa v1.0.1</span>
  <span class="sgr90">[c78977f6] </span><span class="sgr92">+ FP2 v0.1.0 `~/.julia/dev/FP2`</span>

<span class="sgr32"><span class="sgr1">julia&gt;</span></span> using FP2

<span class="sgr32"><span class="sgr1">julia&gt;</span></span> FP2.subs(&quot;abc&quot;, 2:3)
bc
</code></pre>

maybe give me the full sequence of instructions here? if you take the users through a "create a package" step and then do as above it should work I think. But probably easier for me to try to reproduce this.

@gdalle
Copy link
Author

gdalle commented Sep 20, 2023

The full sequence of instructions is here: https://github.com/modernjuliaworkflows/modernjuliaworkflows.github.io/blob/main/pages/sharing/sharing.md
And strangely it seems to work online.

Honestly at this point it's an extremely niche problem so I wouldn't worry too much

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

Successfully merging a pull request may close this issue.

2 participants