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

Any way to use the functionalities within a REPL environment? #63

Closed
x-ji opened this issue May 31, 2018 · 5 comments
Closed

Any way to use the functionalities within a REPL environment? #63

x-ji opened this issue May 31, 2018 · 5 comments

Comments

@x-ji
Copy link

x-ji commented May 31, 2018

This library is excellent but I just realized that it seems to be really inconvenient to run Julia as a traditional command-line program (i.e. Julia is really tailored towards REPL usage). It seems that as soon as the process exits, the compilation results will be lost and the next invocation of julia will need to perform the compilation all over again? The startup time will be very long compared with just loading the module in the REPL and then calling its functions afterwards.

However, if I call functions within a REPL, I can't really perform argument parsing with flags and show help messages, in the style of a traditional command line program. I can only call functions with the correct order of arguments.

I just wonder if there's a way to also use this library within a REPL environment? It seems to be really a pity that one cannot enjoy both speed and argument-parsing convenience with Julia until binary executables can be produced. Am I understanding the situation correctly?

@x-ji x-ji changed the title Seems that Julia is really tailored towards being run with the REPL always on, instead of as a command-line program Any way to use the functionalities within a REPL environment? May 31, 2018
@lucatrv
Copy link
Contributor

lucatrv commented May 31, 2018

In future you will be able to use juliac.jl to statically compile your script, see "Static Julia Compiler", included in PackageCompiler.jl. At present we still have issues compiling scripts which use ArgParse.

@lucatrv
Copy link
Contributor

lucatrv commented Jun 11, 2018

See PackageCompiler.jl #76.

@jbrea
Copy link

jbrea commented Jun 13, 2018

For me it works to statically compile a file that uses ArgParse. With the content of example.jl being

using ArgParse

Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
    # initialize the settings (the description is for the help screen)
    s = ArgParseSettings(description = "Example 1 for argparse.jl: minimal usage.")

    @add_arg_table s begin
        "--opt1"               # an option (will take an argument)
        "--opt2", "-o"         # another option, with short form
        "arg1"                 # a positional argument
    end

    parsed_args = parse_args(ARGS, s) # the result is a Dict{String,Any}
    println("Parsed args:")
    for (key,val) in parsed_args
        println("  $key  =>  $(repr(val))")
    end
    return 0
end

and in the Julia REPL

using PackageCompiler
build_executable("example.jl", "example")

I get an executable that produces (in a shell)

./example -o bla                                      
Parsed args:
  arg1  =>  nothing
  opt1  =>  nothing
  opt2  =>  "bla"

@lucatrv
Copy link
Contributor

lucatrv commented Jun 13, 2018

Yes I confirm no issues with ArgParse, see discussion at PackageCompiler.jl #76.

@carlobaldassi
Copy link
Owner

I believe that between the fix in #88 and the compilation examples provided in this thread, this issue can be considered resolved. Otherwise, please comment and I'll reopen.

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

4 participants