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

Clarify the docs of @__DIR__ #52442

Merged
merged 3 commits into from
Feb 7, 2024
Merged

Conversation

lmiq
Copy link
Contributor

@lmiq lmiq commented Dec 7, 2023

The original docs start with Expand, which is already a concept that might not be clear to the reader. Furthermore, in this version there is an example to illustrate how this macro is different from pwd().

lmiq and others added 3 commits December 7, 2023 13:28
The original docs start with `Expand`, which is already a concept that might not be clear to the reader. Furthermore, in this version there is an example to illustrate how this macro is different from `pwd()`.
@brenhinkeller brenhinkeller added the docs This change adds or pertains to documentation label Dec 8, 2023
@fingolfin fingolfin merged commit 32687b0 into JuliaLang:master Feb 7, 2024
4 of 8 checks passed
@sjkelly
Copy link
Contributor

sjkelly commented Feb 7, 2024

This commit seems to have broken the julia build with:

LoadError("sysimg.jl", 3, LoadError("Base.jl", 541, ErrorException("cannot document the following expression:\n\nprintln(\"@__DIR__ = \", \"/home/sjkelly/julia/base\")\n")))

For some reason the @__DIR__ is interpolated in?


julia> # create script at /home/JuliaUser/Projects
open("/home/JuliaUser/Projects/test.jl","w") do io
print(io, """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This escaping is incorrect here and closes the original docstring scope incidentally.

sjkelly added a commit to sjkelly/julia that referenced this pull request Feb 7, 2024
This issue was introduced in JuliaLang#52442.
The markdown parser had issues with the triple-quotes.
Usually you can use quadruple-quotes to fix this, but
this does not appear to supported, so we escape
each with backslash.

Here is the corrected docstring rendered:

```julia-repl
help?> @__DIR__
  @__DIR__ -> String

  Macro to obtain the absolute path of the current directory as a string.

  If in a script, returns the directory of the script containing the @__DIR__ macrocall. If run from a REPL or if
  evaluated by julia -e <expr>, returns the current working directory.

  Example
  ≡≡≡≡≡≡≡

  The example illustrates the difference in the behaviors of @__DIR__ and pwd(), by creating a simple script in a
  different directory than the current working one and executing both commands:

  julia> cd("/home/JuliaUser") # working directory

  julia> # create script at /home/JuliaUser/Projects
         open("/home/JuliaUser/Projects/test.jl","w") do io
             print(io, """
                 println("@__DIR__ = ", @__DIR__)
                 println("pwd() = ", pwd())
             """)
         end

  julia> # outputs script directory and current working directory
         include("/home/JuliaUser/Projects/test.jl")
  @__DIR__ = /home/JuliaUser/Projects
  pwd() = /home/JuliaUser
```
DilumAluthge pushed a commit that referenced this pull request Feb 7, 2024
This issue was introduced in #52442.
The markdown parser had issues with the triple-quotes.
Usually you can use quadruple-quotes to fix this, but
this does not appear to be supported, so we escape
each with backslash.

Here is the corrected docstring rendered:

```julia-repl
help?> @__DIR__
  @__DIR__ -> String

  Macro to obtain the absolute path of the current directory as a string.

  If in a script, returns the directory of the script containing the @__DIR__ macrocall. If run from a REPL or if
  evaluated by julia -e <expr>, returns the current working directory.

  Example
  ≡≡≡≡≡≡≡

  The example illustrates the difference in the behaviors of @__DIR__ and pwd(), by creating a simple script in a
  different directory than the current working one and executing both commands:

  julia> cd("/home/JuliaUser") # working directory

  julia> # create script at /home/JuliaUser/Projects
         open("/home/JuliaUser/Projects/test.jl","w") do io
             print(io, """
                 println("@__DIR__ = ", @__DIR__)
                 println("pwd() = ", pwd())
             """)
         end

  julia> # outputs script directory and current working directory
         include("/home/JuliaUser/Projects/test.jl")
  @__DIR__ = /home/JuliaUser/Projects
  pwd() = /home/JuliaUser
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants