Skip to content

Add support for the :require command in the REPL #21658

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

Closed
Gedochao opened this issue Sep 27, 2024 · 5 comments · Fixed by #22343
Closed

Add support for the :require command in the REPL #21658

Gedochao opened this issue Sep 27, 2024 · 5 comments · Fixed by #22343
Assignees
Labels
area:repl compat:scala2:feature-parity Issues tied with features which were at some point included in Scala 2 and could be brought over. itype:enhancement
Milestone

Comments

@Gedochao
Copy link
Contributor

The :require command was (and is) supported by the Scala 2 REPL, while it is visibly absent in Scala 3.

scala -S 2.13
Welcome to Scala 2.13.15 (OpenJDK 64-Bit Server VM, Java 17).
Type in expressions for evaluation. Or try :help.
scala> :help
All commands can be abbreviated, e.g., :he instead of :help.
(...)
:require <path>          add a jar to the classpath
(...)
scala> :require cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_2.13/0.10.7/os-lib_2.13-0.10.7.jar
Added '/user/test/cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_2.13/0.10.7/os-lib_2.13-0.10.7.jar' to classpath.

scala> :require cache/https/repo1.maven.org/maven2/com/lihaoyi/geny_2.13/1.1.1/geny_2.13-1.1.1.jar
Added '/user/test/cache/https/repo1.maven.org/maven2/com/lihaoyi/geny_2.13/1.1.1/geny_2.13-1.1.1.jar' to classpath.

scala> os.pwd
val res0: os.Path = /user/test

scala> 

This is not exactly as good as direct support for //> using dep from inside of the REPL, and would be the equivalent of the //> using jar directive of the runner (that indeed, could be called from inside of the REPL).

@Gedochao Gedochao added itype:enhancement area:repl compat:scala2:feature-parity Issues tied with features which were at some point included in Scala 2 and could be brought over. labels Sep 27, 2024
@Gedochao Gedochao changed the title Add support for the :require command in the REPL Add support for the :require command in the REPL Sep 27, 2024
@mbovel
Copy link
Member

mbovel commented Feb 2, 2025

This issue was picked for the Scala Issue Spree of tomorrow, Monday, February 3rd. @dwijnand and @aherlihy will be working on it.

@SethTisue
Copy link
Member

SethTisue commented Feb 4, 2025

I suspect hardly anyone knows that :require even exists in the Scala 2 REPL. afaicr, I've never seen it mentioned.

On the other hand, this could be a nice stepping stone to eventually supporting on-the-fly //> using dep, as that will break down into two steps: calling Coursier to make sure the dependencies are available on the local filesystem, then adding the JARs to the REPL class path.

@SethTisue
Copy link
Member

Designwise, I think :require has always been a poor name. It's vague and it's easily confusable with the require method in stdlib.

If this is going in, I'd suggest picking a better name (or even going straight to //> using jar ...), perhaps with :require as a deprecated alias.

@Gedochao
Copy link
Contributor Author

If this is going in, I'd suggest picking a better name (or even going straight to //> using jar ...), perhaps with :require as a deprecated alias.

+1, although I wouldn't go straight to //> using jar for now (although I'm hoping we'll be able to have //> using jar and //> using dep in the future inside of the REPL).

for now, :jar, perhaps?

@SethTisue
Copy link
Member

:jar SGTM

@Gedochao Gedochao linked a pull request Mar 7, 2025 that will close this issue
@WojciechMazur WojciechMazur added this to the 3.7.0 milestone Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:repl compat:scala2:feature-parity Issues tied with features which were at some point included in Scala 2 and could be brought over. itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants