You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _overviews/scala3-book/scala-for-python-devs.md
+5-12Lines changed: 5 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1293,7 +1293,7 @@ Follow the links below for more details:
1293
1293
1294
1294
## How to setup a virtual environnement in Scala?
1295
1295
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
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`.
1306
1306
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
1316
1308
1317
1309
```
1318
1310
cd myapp
1319
1311
sbt compile
1320
1312
```
1321
1313
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
+
1323
1316
1324
1317
[collections-classes]: {% link _overviews/scala3-book/collections-classes.md %}
1325
1318
[concurrency]: {% link _overviews/scala3-book/concurrency.md %}
0 commit comments