Skip to content

Support links in using file directive (implements #1328) #3681

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ivan-klass
Copy link

@ivan-klass ivan-klass commented May 15, 2025

Scala Tooling Spree 15.05

see #1328

Co-authored-by: Michał Pawlik <[email protected]>
Co-authored-by: tgodzik <[email protected]>
@ivan-klass
Copy link
Author

ivan-klass commented May 16, 2025

git+ssh is not supported by coursier and should be addressed there - currently only HTTP is assumed:

coursier.cache.internal.Downloader.Blocking.doDownload

@ivan-klass
Copy link
Author

@majk-p @tgodzik It works! Indeed, dependencies are resolved recursively already.

out/test.scala:

//> using file https://raw.githubusercontent.com/softwaremill/sttp/refs/heads/master/examples/src/main/scala/sttp/client4/examples/json/GetAndParseJsonCatsEffectCirce.scala

./mill 'cli[3.3.6].run' out/test.scala:

Got response code: 200
Right(HttpBinResponse(87.116.164.191,Map(Accept-Encoding -> gzip, deflate, Host -> httpbin.org, User-Agent -> Java-http-client/17.0.13, X-Amzn-Trace-Id -> Root=1-6826f31e-7030221a5448052d12774af8)))

@ivan-klass ivan-klass marked this pull request as ready for review May 16, 2025 08:16
@Gedochao Gedochao self-requested a review May 16, 2025 12:55
@Gedochao Gedochao self-assigned this May 16, 2025
@Gedochao
Copy link
Contributor

Note: need to fix formatting & regenerate reference docs for the CI to pass.
https://github.com/VirtusLab/scala-cli/blob/main/CONTRIBUTING.md

Copy link
Contributor

@Gedochao Gedochao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to skip git+ssh IMO, we don't support that anywhere else, either.
The solution looks good so far, just need to address the TODOs and add tests

As for tests, maybe can reuse stuff from scala.cli.integration.RunGistTestDefinitions.

Comment on lines +408 to +409
// TODO: reuse existing one? e.g. scala.cli.commands.shared.SharedOptions.coursierCache
lazy val fileCache: FileCache[coursier.util.Task] = FileCache()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think it's accurate that SharedOptions.coursierCache should be used.

Copy link
Author

@ivan-klass ivan-klass May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gedochao but scala.cli.commands.shared.SharedOptions.coursierCache is in cli module, while we're in build here - so that definition is inaccessible (build doesn't depend on cli)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why we haven't picked it up and left a todo

Copy link
Contributor

@Gedochao Gedochao May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...well, yes, but cli depends on build.
so what I mean here is that the way to go would be to pass it all the way from cli to CrossSources.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you just leave a TODO, it's very likely to get forgotten.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you don't have time to fix it, please at least create a ticket for the follow-up and link it back in the code.

Comment on lines 411 to 421
private def downloadFile(pUri: Positioned[java.net.URI]) =
import scala.build.options.ScalaVersionUtil.fileWithTtl0
val artifact = Artifact(pUri.value.toString).withChanging(true)
fileCache.fileWithTtl0(artifact)
.left
.map(err =>
new MalformedDirectiveError(err.describe, pUri.positions)
) // TODO: better error type
.map(f => os.read.bytes(os.Path(f, Os.pwd))).map(content =>
Seq(Virtual(pUri.value.toString, content))
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very similar to SharedOptions.downloadInputs... I wonder if the function itself could be passed all the way here, rather than the cache

@@ -126,6 +126,8 @@ Manually add sources to the project. Does not support chaining, sources are adde
#### Examples
`//> using file utils.scala`

`//> using file https://raw.githubusercontent.com/softwaremill/sttp/refs/heads/master/examples/src/main/scala/sttp/client4/examples/json/GetAndParseJsonCatsEffectCirce.scala`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gedochao I think it would be nice to reference a file within scala-cli repo itself

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean... dunno if it matters, as long as the example is useful, to be honest. 🤷

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

Successfully merging this pull request may close these issues.

//> using file directives should allow URLs and git repository paths
2 participants