-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Add support for determining name of script #14114
Conversation
@@ -174,6 +174,7 @@ export | |||
UnicodeError, | |||
|
|||
# Global constants and variables | |||
FILE_NAME, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be alphabetized in each grouping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know. Thanks
I think n+1 people have wanted this, so docs and a NEWS.md entry might be in order? (I also wonder if this opens up module as a script functionality?) |
I added/updated documentation and an entry to NEWS.md. What do people think of the name |
Maybe use |
@omus: Julia: Seems like |
I like that name better. I'll change it to |
After messing around with this more global const PROGRAM_FILE = UTF8String(shift!(ARGS)) Unfortunately this won't work as I would also like to support having The repercussions of this is that |
@@ -151,6 +151,8 @@ New language features | |||
|
|||
* `@__LINE__` special macro now available to reflect invocation source line number ([#12727]). | |||
|
|||
* `PROGRAM_FILE` global is now available for determining the name of the running script ([#14114]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to run julia doc/NEWS-update.jl
to update the cross-reference links.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Is there some Julia contribution documentation that mentions this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it isn't mentioned somewhere in CONTRIBUTING.md
it probably should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I just noticed that this was accidentally added to the Julia 0.4 NEWS, not the Julia 0.5 NEWS...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 47c29a9
I'll squash these commits |
was the issue with
sorted, or is it a minor concern? |
@tkelman I think it is a minor concern. Basically Here's a demonstration of the current behavior: $ echo 'println("PROGRAM_FILE: $PROGRAM_FILE"); for (i, arg) in enumerate(ARGS); println("$i: $arg"); end' > script.jl
$ julia script.jl foo -bar --baz
PROGRAM_FILE: script.jl
1: foo
2: -bar
3: --baz
$ julia -L script.jl script.jl foo -bar --baz
PROGRAM_FILE:
1: script.jl
2: foo
3: -bar
4: --baz
PROGRAM_FILE: script.jl
1: foo
2: -bar
3: --baz What do you think? |
I guess it not being |
@@ -14,6 +14,10 @@ Constants | |||
A symbol representing the name of the operating system. Possible values | |||
are ``:Linux``, ``:Darwin`` (OS X), or ``:Windows``. | |||
|
|||
.. data:: PROGRAM_FILE | |||
|
|||
A string containing the script name passed to Julia. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to clarify here exactly how this differs from @__FILE__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll add some more details.
Yes it could be modified. I'll note that |
@tkelman I updated the documentation to be clearer. I noticed however that macro's don't seem to support permalinks which means the |
@@ -320,7 +320,7 @@ | |||
|
|||
.. Docstring generated from Julia source | |||
|
|||
``@__FILE__`` expands to a string with the absolute path and file name of the script being run. Returns ``nothing`` if run from a REPL or an empty string if evaluated by ``julia -e <expr>``\ . | |||
``@__FILE__`` expands to a string with the absolute path and file name of the containing the macro. Returns ``nothing`` if run from a REPL or an empty string if evaluated by ``julia -e <expr>``\ . Alternatively see :data:`PROGRAM_FILE`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is autogenerated so should be changed at the jl docstring source
I tracked down the permalink issue with |
Rebased on to latest master. I also separated the PROGRAM_FILE tests from the ARGS tests. |
LGTM. @StefanKarpinski what do you think? |
LGTM. |
Note that PROGRAM_FILE was chosen as the name for this variable as it matches the help for the Julia CLI.
Rebased again on to the latest master. Fixed conflict with 7d5def6 |
The appveyor 64-bit Windows failure looks like it just got killed at 1 hour. |
RFC: Add support for determining name of script
Thanks! |
Fixes #14109.