tidalcycles / tidal-chocolatey

6 stars 5 forks source link

Move the SuperDirt install into the SuperCollider startup.scd script #11

Closed cleary closed 1 year ago

cleary commented 1 year ago

This is a cross-platform method to install the SuperDirt quark (and Vowel/Samples etc) from a SuperDirt startup.scd file. The idea being to reduce the number of steps required in the Choco install process which is fragile and completely dependent on upstream moderators and their schedules for approving fixes.

It can be dropped in a User's %LOCALAPPDATA%/SuperCollider/startup.scd location, then on SuperCollider first start will install SuperDirt AND write a new startup.scd template with useful superdirt starting content (@telephon is it safe for us to depend on that template?).

This method is also cross-platform, and could be referenced as part of the manual install doco if we wanted - I don't know which repo could be a good home for it, but potentially the https://github.com/musikinformatik/SuperDirt one (@telephon thoughts?)

var sd_startup = (thisProcess.platform.userConfigDir +/+ "sd_startup.scd");
var startup = (thisProcess.platform.userConfigDir +/+ "startup.scd");

if(Quarks.isInstalled("SuperDirt").not) {
    Quarks.install("SuperDirt");
    thisProcess.recompile;
} {
    Download.new("https://raw.githubusercontent.com/musikinformatik/SuperDirt/develop/superdirt_startup.scd", sd_startup,
        {
            File.delete(startup);
            File.copy(sd_startup, startup);
            File.delete(sd_startup);
            startup.load;
        },
        {\error.postln;},
        {|rec, tot| [rec, tot].postln});
};
telephon commented 1 year ago

This looks dangerous  – someone may have a lot of information in their startup.scd file that would get overwritten. But it is a good idea to streamline this process. Maybe there is a less intrusive variant?

cleary commented 1 year ago

This looks dangerous  – someone may have a lot of information in their startup.scd file that would get overwritten. But it is a good idea to streamline this process. Maybe there is a less intrusive variant?

Well, the intent is to inject it into a brand new supercollider installation as the startup.scd (as part of the tidal setup). If the file already exists you'd just fall back to a manual installation message.

telephon commented 1 year ago

Yes, sure. But when someone downloads this and installs it, it won't check if there is a startup already and just do File.delete(startup);. No?

If the file already exists you'd just fall back to a manual installation message.

This fall back isn't in the above code, so I wonder where this happens

cleary commented 1 year ago

Yes, sure. But when someone downloads this and installs it, it won't check if there is a startup already and just do File.delete(startup);. No?

Yes, if someone just downloads and runs it -

If the file already exists you'd just fall back to a manual installation message.

This fall back isn't in the above code, so I wonder where this happens

This would happen in the choco install script.


There are a couple of options, I can think of to make it safer for general use:

  1. Remove the file deletion, and instead keep sd_startup.scd separate, and load it separately. The downside to this is all the tidal startup.scd doco will break a bit

  2. Put in a safe version (uncommented) and an unsafe version (commented) for a user to choose

  3. Just put in lots of visible warning comments

telephon commented 1 year ago

A number of things (sorry, I don't know how choco works, so it may be solved in some other way):

A check for an existing file could look like this:

canWriteAtPath = { |pathForFile, overwriteIfEmpty = false|
    var paths = thisProcess.platform.startupFiles;
    pathForFile = pathForFile.standardizePath;
    paths.every { |p|
        if(pathForFile == p) {
            if(File.exists(pathForFile)) {
                if(File.readAllString(pathForFile).size > 0) {
                    "non-empty startup file already exists at this path: %".format(pathForFile).postln;
                    false
                } {
                    if(overwriteIfEmpty) {
                        "empty startup file already exists at this path, overwriting: %".format(pathForFile).postln;
                        true
                } { 
                    false 
                }
            } {
                true
            }
        } {
            true
        }
    }
}

Remove the file deletion, and instead keep sd_startup.scd separate, and load it separately. The downside to this is all the tidal startup.scd doco will break a bit

If you have another startup already, this will potentially have conflicts.

Put in a safe version (uncommented) and an unsafe version (commented) for a user to choose Just put in lots of visible warning comments

The user may not know what they are doing, so better not. It should at least ask whether this can be moved to another location, or renamed. Deleting is not an option in any of the cases, I think.

cleary commented 1 year ago

Thanks @telephon - appreciate your input:

A number of things (sorry, I don't know how choco works, so it may be solved in some other way):

* To directly download the develop branch version of the startup file is a bit risky – e.g. it may deviate from the state of the release that is being installed.

Agree, this needs to be sorted before it goes in (this can be part of the choco script)

* It is definitely better to check if a startup file already exists – you may not know this: people invest a lot of work in their startup file

I'd also just do this in the choco script

* I'm not sure why this directly calls `startup.load;` – the class library needs to be recomplied anyway before it will work.

This file is intended to be initially run as the startup.scd file, so it only overwrites itself.

Remove the file deletion, and instead keep sd_startup.scd separate, and load it separately. The downside to this is all the tidal startup.scd doco will break a bit

If you have another startup already, this will potentially have conflicts.

Put in a safe version (uncommented) and an unsafe version (commented) for a user to choose Just put in lots of visible warning comments

The user may not know what they are doing, so better not. It should at least ask whether this can be moved to another location, or renamed. Deleting is not an option in any of the cases, I think.

Remembering this is a proposal to go into a specific install method (choco) on Windows only. Once the choco script has checked to make sure there is no existing startup.scd file in this case the risk drops to 0.

Once again, appreciate the input - I think the answer to my original question, ie - "Do you think it should be hosted in the superdirt repo?", is a no

telephon commented 1 year ago

Once again, appreciate the input - I think the answer to my original question, ie - "Do you think it should be hosted in the superdirt repo?", is a no

Not sure, we will have to think about how it is done best, that is the main thing.

cleary commented 1 year ago

Superdirt has it's own package - closing https://github.com/il-mix/superdirt-chocolatey