@@ -225,6 +225,14 @@ If you want to skip this installation, use the `--no-root` option.
poetry install --no-root
```
Similar to `--no-root` you can use `--no-directory` to skip directory path dependencies:
```bash
poetry install --no-directory
```
This is mainly useful for caching in CI or when building Docker images. See the [FAQ entry]({{<relref"faq#poetry-busts-my-docker-cache-because-it-requires-me-to-copy-my-source-files-in-before-installing-3rd-party-dependencies">}}) for more information on this option.
By default `poetry` does not compile Python source files to bytecode during installation.
This speeds up the installation process, but the first execution may take a little more
time because Python then compiles source files to bytecode automatically.
...
...
@@ -240,6 +248,7 @@ The `--compile` option has no effect if `installer.modern-installation`
is set to `false` because the old installer always compiles source files to bytecode.
{{% /note %}}
### Options
*`--without`: The dependency groups to ignore.
...
...
@@ -248,6 +257,7 @@ is set to `false` because the old installer always compiles source files to byte
*`--only-root`: Install only the root project, exclude all dependencies.
*`--sync`: Synchronize the environment with the locked packages and the specified groups.
*`--no-root`: Do not install the root package (your project).
*`--no-directory`: Skip all directory path dependencies (including transitive ones).
*`--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
*`--extras (-E)`: Features to install (multiple values allowed).
*`--all-extras`: Install all extra features (conflicts with --extras).
@@ -189,3 +189,37 @@ This is done so to be compliant with the broader Python ecosystem.
For example, if Poetry builds a distribution for a project that uses a version that is not valid according to
[PEP 440](https://peps.python.org/pep-0440), third party tools will be unable to parse the version correctly.
### Poetry busts my Docker cache because it requires me to COPY my source files in before installing 3rd party dependencies
By default running `poetry install ...` requires you to have your source files present (both the "root" package and any directory path dependencies you might have).
This interacts poorly with Docker's caching mechanisms because any change to a source file will make any layers (subsequent commands in your Dockerfile) re-run.
For example, you might have a Dockerfile that looks something like this:
```text
FROM python
COPY pyproject.toml poetry.lock .
COPY src/ ./src
RUN pip install poetry && poetry install --no-dev
```
As soon as *any* source file changes, the cache for the `RUN` layer will be invalidated, which forces all 3rd party dependencies (likely the slowest step out of these) to be installed again if you changed any files in `src/`.
To avoid this cache busting you can split this into two steps:
1. Install 3rd party dependencies.
2. Copy over your source code and install just the source code.
This might look something like this:
```text
FROM python
COPY pyproject.toml poetry.lock .
RUN pip install poetry && poetry install --no-root --no-directory
COPY src/ ./src
RUN poetry install --no-dev
```
The two key options we are using here are `--no-root` (skips installing the project source) and `--no-directory` (skips installing any local directory path dependencies, you can omit this if you don't have any).
[More information on the options available for `poetry install`]({{<relref"cli#install">}}).