scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

scala-cli should look for project.settings.scala in parent directories as a fallback

Open benwbooth opened this issue 1 year ago • 2 comments

It would be great if scala-cli could look for the project.settings.scala by searching all parent directories of the first script file passed in, similar to how git searches for the .git directory. This would allow users of scala-cli to place the project.settings.scala file at the root of their source folder. Scala scripts would then be able to be placed in nested subdirectory paths but still be able to find the project.settings.scala at the root of the source folder, even if the script being run is nested within multiple subdirectories.

benwbooth avatar Sep 03 '22 18:09 benwbooth

Searching in parent directories of the running script could be done right before searching the current working directory.

benwbooth avatar Sep 03 '22 18:09 benwbooth

Hey, for now we decided against doing this, to avoid ambiguities.

The way we currently look for project.settings.scala (and the project root, as an extension of that) is complex enough as is (just take a look at the relevant doc). Adding more smart detection in the inputs' parent directories (not to mention .git root) might introduce behaviours which would be unexpected to our users, so it probably shouldn't be on as default, if it's to be added at all. (which I'm not so sure about)

For example, for a structure like this:

.
├── .git
├── project.settings.scala
│
├──  src
│   └─── ...
│   
└─── scripts
    └─── script.sc

While running the script independently

$ scala-cli scripts/script.sc

The user might be unaware ./project.settings.cala is included on the classpath. It's not unlikely the script uses conflicting dependencies and including it might even break some of the logic.

And that's just one of potential ambiguities this would introduce (regardless if we're talking just about the input parent directory or all the way to the git root).

TL;DR I'm setting this as low priority. We might revisit this if there's demand, but probably not soon. And even then, it would probably have to be hidden behind a flag (or some setting to be set with scala-cli config), and not to be enabled by default.

Gedochao avatar Sep 05 '22 09:09 Gedochao