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 4 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.

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

Comment on lines +417 to +418
new MalformedDirectiveError(err.describe, pUri.positions)
) // TODO: better error type
Copy link
Contributor

Choose a reason for hiding this comment

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

just a new error class would do, I think

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