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

export Base.withenv #10914

Merged
merged 1 commit into from
Apr 20, 2015
Merged

export Base.withenv #10914

merged 1 commit into from
Apr 20, 2015

Conversation

stevengj
Copy link
Member

As discussed in #10836, this exports Base.withenv (renamed from with_env for consistency with setenv); it now takes zero or more var=>val arguments to specify the changes to the environment.

For consistency, I added a setenv method taking var=>val arguments (Pair...). However, the main usage pattern for setenv seems to be to copy(ENV) and modify/set one environment variable. Maybe setenv should be deprecated entirely in favor of withenv?

Note also that the setenv test results weren't actually being checked.

@StefanKarpinski
Copy link
Sponsor Member

Looks great.

@test readall(setenv(`sh -c "echo \$TEST"`,"TEST"=>"Hello World")) == "Hello World\n"
@test (withenv("TEST"=>"Hello World") do
readall(`sh -c "echo \$TEST"`); end) == "Hello World\n"
@test readall(setenv(`sh -c "pwd"`;dir="/")) == readall(setenv(`sh -c "cd / && pwd"`))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this last one's going to fail on windows

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe dir=".." instead of /?

@stevengj
Copy link
Member Author

All of the uses of setenv that I can find in the packages are of the copy(ENV) pattern that would seem better served by withenv:

Theoretically, setenv has the advantage of allowing you to easily completely replace the environment, but it's not clear to me when or why anyone would ever use it this way. But Python exports a similar function, so I guess we might as well continue to export this functionality from libuv?

…s; support similar arguments in setenv for consistency, and fix the setenv tests (closes JuliaLang#10836)
@GlenHertz
Copy link
Contributor

I use setenv to configure minimal environments and find it useful.

@tkelman
Copy link
Contributor

tkelman commented Apr 20, 2015

At the least the way in which setenv currently works, returning a modified Cmd object from the input Cmd object is pretty useful. I think only the DataFrames example above would be able to effectively use this do-block withenv construct, maybe unless you were to wrap the entire BinDeps invocation in the do block.

@stevengj
Copy link
Member Author

Okay.

stevengj added a commit that referenced this pull request Apr 20, 2015
@stevengj stevengj merged commit a49ae53 into JuliaLang:master Apr 20, 2015
stevengj added a commit to JuliaPy/PyCall.jl that referenced this pull request Apr 20, 2015
@JeffBezanson
Copy link
Sponsor Member

I do dislike underscores, but I feel the need to mention that we have with_rounding. We should discuss what the naming convention should be for functions like this.

@StefanKarpinski
Copy link
Sponsor Member

Related:

  • the idea of having a with keyword, Python style and doing resource cleanup by providing methods on an object type like a file handle or a environment type.
  • the idea of having defer keyword, Go/D style and doing resource cleanup whenever unwinding the stack.

jrevels added a commit to JuliaLang/Compat.jl that referenced this pull request Jan 26, 2016
jrevels added a commit to JuliaLang/Compat.jl that referenced this pull request Jan 26, 2016
jrevels added a commit to JuliaLang/Compat.jl that referenced this pull request Jan 26, 2016
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

Successfully merging this pull request may close these issues.

None yet

5 participants