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

Changing global working directory #44

Closed
zsunberg opened this issue Jan 17, 2019 · 5 comments
Closed

Changing global working directory #44

zsunberg opened this issue Jan 17, 2019 · 5 comments
Assignees

Comments

@zsunberg
Copy link

Sometimes this package has the side effect of changing the current working directory for all of Julia and leaving it changed! 😲 This can result in very hard-to-diagnose unexpected behavior like files the user wanted to save in her directory ending up in this package's temporary working dir.

Of course it's fine to change directories temporarily to run commands, but it is hard to guarantee that it is changed back correctly in all cases. The two-argument version of cd() should be used to automatically enforce this. 😃

@mykelk
Copy link
Member

mykelk commented Jan 17, 2019

Oh, this is definitely the way to go. @Shushman do you want to take a crack at this?

@Shushman
Copy link
Collaborator

Yup, on it

@Shushman
Copy link
Collaborator

@zsunberg I'm running into an issue with the f::Function in the two-argument version of cd. If you look at the code between cd(working_dir) here (https://github.com/JuliaTeX/TikzPictures.jl/blob/master/src/TikzPictures.jl#L220) and cd(original_dir) here (https://github.com/JuliaTeX/TikzPictures.jl/blob/master/src/TikzPictures.jl#L220)
that is the behavior I need to replicate by the ::Function. But the function I'm writing to achieve the behavior in that block needs the arguments for tp and f etc (say that function is savePDFTPHelper(::PDF,::TikzPicture) and implements the interim code).

How do I call cd then? I can't do cd(savePDFTPHelper,working_dir) as it does not send through the arguments. But I can't do cd(savePDFTPHelper(f,tp),working_dir) either as that is not a ::Function, it evaluates to Nothing as it executes the function which has no return type.

I've done argument binding before in Julia but they were typically when the bound method still had some argument to operate on, and I was binding only a subset of arguments. Not sure what to do here :(

@rejuvyesh
Copy link

rejuvyesh commented Jan 22, 2019

You can create an anonymous function which just needs the directory argument (IIUC). Also you should be using pwd() for the original directory.

See https://github.com/JuliaLang/julia/blob/master/base/file.jl#L81

@Shushman
Copy link
Collaborator

Can you try out the branch in #45 @zsunberg ?

@mykelk mykelk closed this as completed Mar 6, 2019
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