-
Notifications
You must be signed in to change notification settings - Fork 757
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
fix Score examples and Platform.defaultTempDir on OSX #4221
fix Score examples and Platform.defaultTempDir on OSX #4221
Conversation
SCClassLibrary/Platform/Platform.sc
Outdated
var dir; | ||
dir = Platform.userAppSupportDir ++ "/tmp/"; | ||
dir.mkdir; | ||
^dir; |
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 change causes the defaultTempDir
to no longer be /tmp
on Linux. Maybe this is a good thing? It's worth discussing.
I'm guessing that Windows won't be too happy about ++ "/tmp/"
. You should make use of +/+
. Also, we should keep using File.exists
so that we don't call .mkdir
every time.
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.
Ignore my comment about Windows. I didn't really understand how Platform works on Windows.
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.
@geoffroymontel It seems that /tmp
not being writeable is a macOS-only issue (and from a basic search it seems to only happen on El Capitan although I'm not 100% sure about that).
I'd strongly suggest to not change default /tmp
folder on linux but rather use that workaround for macOS only.
@gusano @patrickdupuis thanks for your reviews ! I reverted Platform.defaultTempDir to /tmp on Linux and changed it in OSX only. |
|
||
defaultTempDir { | ||
var dir; | ||
dir = Platform.userAppSupportDir +/+ "tmp"; |
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.
@geoffroymontel Now I believe that the trailing /
is missing here
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.
@gusano I've tested the code and it seems to work without the trailing slash. Is it ok for you ?
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.
why would the trailing slash be necessary? @gusano
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.
@brianlheim it seems that Platform.defaultTempDir()
already returns a trailing slash by default so it might be better to keep it that way to not break existing code?
@geoffroymontel I'm surprised that it works, I cannot test it now but my guess is that the file might end being
"/path-to-app-support-dir/tmpasScore-Help.aif"
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.
Sorry @gusano you're right, I had not fully tested !
I added a trailing slash like on 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.
ok, fair, did not know that. everyone should be using +/+ to concatenate paths though precisely to not get burned by this kind of detail. i believe other platform directory methods return paths without the trailing slash.
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.
@geoffroymontel thanks
var dir; | ||
// ensure trailing slash | ||
dir = Platform.userAppSupportDir +/+ "tmp/"; | ||
if (File.exists(dir).not, { dir.mkdir; }); |
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.
please fix formatting - if(File.exists(dir).not) { dir.mkdir };
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.
Wow, I did not know this syntax was allowed !
if (bool) { "true".postln } { "false".postln }
I always thought parenthesis around functions were needed, because if was a function that would take a boolean and two functions.
if (bool, { "true".postln }, { "false".postln });
This syntax is not mentionned in http://doc.sccode.org/Reference/Control-Structures.html
Should I fill a separate PR for that ?
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.
also, why no space between if and the condition ?
is there a guide somewhere for the codebase formatting ?
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.
There's this WIP guide. I seems to contradict what is being suggested here: https://github.com/supercollider/supercollider/wiki/Code-style-guidelines#whitespace-1
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.
Thanks Patrick. I think I will rewrite it as :
if (File.exists(dir).not) { dir.mkdir };
then
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.
After the discussion on Slack, the style guide mentions a space after if for the C++ codebase, but no space for the SCLang codebase.
Then I will use
if(File.exists(dir).not) { dir.mkdir };
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.
changes done
HelpSource/Classes/Score.schelp
Outdated
// render the pattern to aiff (4 beats) | ||
|
||
p.render("asScore-Help.aif", 4.0); | ||
p.render(Platform.defaultTempDir ++ "asScore-Help.aif", 4.0); |
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.
use +/+
here
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.
Definitely, I will do that
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.
Done
HelpSource/Classes/Score.schelp
Outdated
f.write(g.asCompileString); | ||
f.close; | ||
) | ||
|
||
z = Score.newFromFile("score-test"); | ||
z = Score.newFromFile(Platform.defaultTempDir ++ "score-test"); |
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.
use +/+
here and in the other spots above (i count 7)
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.
Thanks, and sorry this PR needs so much review for so little code
if (File.exists(dir).not, { dir.mkdir; });
conforms to the main syntax given in the docs:
if (expr, trueFunc, falseFunc);
Or am I misunderstanding your point?
Cheers,
eddi
…
|
@alln4tural my point was that I wrote initially if (File.exists(dir).not, { dir.mkdir; }); and Brian suggested I wrote if(File.exists(dir).not) { dir.mkdir }; instead, which is a style more in line with other programming languages, but I did not know SuperCollider allowed that. |
Ah, sorry! That wasn't apparent from the email I got.
…
|
|
||
defaultTempDir { | ||
var dir; | ||
// ensure trailing slash |
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.
one last thing i didn't notice before -- this comment explains 'what', but not 'why' - can you please add a note that this is due to backwards compatibility, referencing this PR (#4221), so that future generations are not confused? sorry i didn't catch this before, after this it is definitely ready to merge. :)
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.
Done !
I think it was the worst number of lines of code / number of requested changes ever 😆
I will try to do better next time !
Thanks everyone for your patience.
…s to the github PR page
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.
thanks, in the future don't need the entire URL, just the number
Purpose and Motivation
Fixes #1271
Types of changes
Platform.defaultTempDir
because/tmp
is not writeable on OSX and is used in Score renderingChecklist
Remaining Work