-
-
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: Use macros for separate functions on OS X and Linux #1387
Conversation
I'm tempted to just hit merge myself, but since one of my changes motivated this I should let at least one other core developer review this. First to do so wins the prize! |
@@ -16,4 +16,20 @@ macro unix_only(ex) | |||
end | |||
end | |||
|
|||
macro osx_only(ex) |
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.
Four nearly-identical one-argument macros sounds like a job for a two-argument macro and better abstraction.
macro os_only(os, ex)
if os == this_os()
ex
else
:nothing
end
end
Then wrap the OS detection code in this_os()
(name bikesheddable).
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.
I'm on board. But are the various Linux OS's being exposed as a consistent name? We'll also still need a hierarchy of names to express those functions that work on both OS X and Linux.
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.
I think the simple refactoring would be fine. I don't think we need to refactor the world yet; just DRYing this up would get the maintainability there and it should be good enough for now.
This looks sane to me. I vote for merge first, dry after. |
Ok. I will merge this now, then DRY it after lunch. |
Provide macros for defining separate functions on OS X and Linux. Use these separate macros to define tempdir() and tempfile() in different ways on OS X and Linux.
I'm a little late to the party, but I recommend splitting not on Linux/OSX, but Linux/BSD, as these kinds of errors are typically because of OSX's BSD heritage, and the corresponding BSD commands usually have the same difference from Linux commands. |
macro os_only(oses, ex)
if any(oses == this_os())
ex
else
:nothing
end
end
@os_only [:bsd, :osx] begin
# platform specific code
end ? Should also address @johnmyleswhite's concern about code applicable to multiple platforms. An analogous |
That works. I also just pushed a more concise version. Unfortunately, I'm unable to get tests to pass due to tempfile stuff that's failing. |
I had problems with tempfile stuff that crept in while revising the tests in Is that the source of your problems? What do |
I'm happy to add these cleaner macros, but I'd like to make sure we have a handle on what OS's are causing problems for temporary files and directories before I do anything else. |
I disabled them for now. The error message is this:
|
What OS (or version of OS X) are you on? That's the error that Tim Holy used to get, which led him to commit changes. Maybe on your machine you need to be running the |
Also, which mktemp is in your path? For me, it's |
That's the issue – I'm using GNU mktemp:
|
So I guess one solution would be to hardcode the absolute path on OS X. |
Looking at the source of http://www.mktemp.org/, I'm starting to think we should just generate a random string and create things inside of ENV["TMPDIR"]. It should be easy to make a minimal version of this in pure Julia. |
On another note, are we trying to get rid of all the previous OS detection stuff? If we're cutting out the linux_only and osx_only along with the unix_only and windows_only macros and replacing them all with
we'll need to revise a lot of other places. Or is the intention to keep unix_only and windows_only, then provide os_only as the alternative when greater specificity is needed? |
There's already a randstring function, which I wrote (Jeff later improved) precisely for this use case. I thought about suggesting it earlier, but we'd have to make certain that two separate Julia sessions wouldn't generate the same strings. |
This is a case where being able to set the seed for a local RNG without effecting the global one would be really helpful. |
Does something like this work on other people's systems?
|
Works great on OSX 10.8.2, generates |
Good to know. I think something like this that removes our dependence on external programs like |
Sadly, does not for me (Kubuntu 12.04, TMPDIR is not an environment variable). We could put it in a try/catch block and default to /tmp, I suppose. And it would be nice to have something that would work for Windows, too. @vtjnash and @loladiro ? |
I guess the other option is to split things up based on the value of some version for |
I think @timholy has the right idea...... for reference, here's how Python does it:
Although if we want to be good Windows citizens, we can do better than that. There's |
To resolve the issues that came up in 3327b62, I've added macros that split apart OS X and Linux in the same way that we previously split apart Windows and Unix. For this specific case, we should ultimately not keep the resulting definitions of
tempdir
andtempfile
, but I suspect that we will find separating OS X from Linux useful in other places as well.Because this introduces new macros everywhere, I wanted to get people's opinions about this strategy before using it for such a small problem.