Skip to content

Commit d1cd2de

Browse files
committed
Virtual envs are an implementation detail in Scala build tools
1 parent f1e5d5b commit d1cd2de

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

_overviews/scala3-book/scala-for-python-devs.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ Follow the links below for more details:
12931293

12941294
## How to setup a virtual environnement in Scala?
12951295

1296-
In Python there is a common practice of creating an isolated environnement for a particular project. For example, say we are working on application `myapp`, then using `venv` Python module we might do
1296+
By default Python and Python modules are installed at system-wide directories or user-wide directories. Virtual environments are a way of obtaining an isolated environment on a per-project basis. Typical flow to configure the virtual environment using for example `venv` module in Python might be something like so
12971297

12981298
```
12991299
cd myapp
@@ -1302,24 +1302,17 @@ source myapp-env/bin/activate
13021302
pip install -r requirements.txt
13031303
```
13041304

1305-
This installs all the dependencies under project's directory `myapp/myapp-env` and alters the shell environmental variable `PATH` to look up dependencies from `myapp-env`. Another popular approach is to use Pipenv
1305+
This installs all the dependencies under project's directory `myapp/myapp-env` and alters the shell environmental variable `PATH` to look up dependencies from `myapp-env`.
13061306

1307-
```
1308-
cd myapp
1309-
pipenv shell
1310-
pipenv install
1311-
```
1312-
1313-
which makes use of `Pipfile` and corresponding lock file to manage dependencies.
1314-
1315-
Key difference in Scala is that project's dependencies are not installed per project, and hence potentially same dependency of the same version is duplicated across multiple projects, but instead dependencies are installed inside a central local repository which is reused across projects. Dependency of particular version is installed only once and then reused across different projects that require it. For example using `sbt` build tool we specify dependencies inside `build.sbt` file (which is conceptually similar to `Pipfile`) under `libraryDependencies`, then executing
1307+
In Scala there is no need to explicitly setup an equivalent of Python's virtual environnement. By default, build tools manage project's dependencies such that user does not have to explicitly think about site directories. For example using `sbt` build tool we specify dependencies inside `build.sbt` file under `libraryDependencies` setting, then executing
13161308

13171309
```
13181310
cd myapp
13191311
sbt compile
13201312
```
13211313

1322-
downloads all the dependencies under the local repository. The location of the local repository can be queried with `show csrCacheDirectory` inside `sbt` shell. Note by using `sbt` each project gets its own isolated environment without the need for lock files or modification of the shell environnement. All the necessary paths are managed by the build tool itself.
1314+
would automatically resolve all dependencies for that particular project. The location of downloaded dependencies is largely an implementation detail of the build tool that users do not interact with directly. For example, if were to delete the whole sbt dependencies cache, one next compilation of the project, sbt will simply re-resolve automatically all the required dependencies.
1315+
13231316

13241317
[collections-classes]: {% link _overviews/scala3-book/collections-classes.md %}
13251318
[concurrency]: {% link _overviews/scala3-book/concurrency.md %}

0 commit comments

Comments
 (0)