Skip to content

Commit a06381c

Browse files
authored
docs: improve documentation of repositories/package sources (#5605)
Resolves some discussion in #3855
1 parent ddf36aa commit a06381c

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

docs/repositories.md

+36-16
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ By default, Poetry discovers and installs packages from [PyPI](https://pypi.org)
2929
install a dependency to your project for a [simple API repository](#simple-api-repository)? Let's
3030
do it.
3131

32-
First, [configure](#project-configuration) the [package source](#package-source) repository to your
32+
First, [configure](#project-configuration) the [package source](#package-source) as a [secondary package source](#secondary-package-sources) to your
3333
project.
3434

3535
```bash
36-
poetry source add foo https://pypi.example.org/simple/
36+
poetry source add --secondary foo https://pypi.example.org/simple/
3737
```
3838

3939
Then, assuming the repository requires authentication, configure credentials for it.
@@ -99,13 +99,20 @@ when publishing a package.
9999

100100
### Project Configuration
101101

102-
These package sources maybe managed using the [`source`]({{< relref "cli#source" >}}) command for
102+
These package sources may be managed using the [`source`]({{< relref "cli#source" >}}) command for
103103
your project.
104104

105105
```bash
106106
poetry source add foo https://foo.bar/simple/
107107
```
108108

109+
{{% note %}}
110+
111+
If your package source requires [credentials](#configuring-credentials) or
112+
[certificates](#certificates), please refer to the relevant sections below.
113+
114+
{{% /note %}}
115+
109116
This will generate the following configuration snippet in your
110117
[`pyproject.toml`]({{< relref "pyproject" >}}) file.
111118

@@ -117,23 +124,26 @@ default = false
117124
secondary = false
118125
```
119126

120-
{{% warning %}}
121-
122-
If package sources are defined for a project, these will take precedence over
123-
[PyPI](https://pypi.org). If you do not want this to be the case, you should declare **all** package
124-
sources to be [secondary](#secondary-package-sources).
125-
126-
{{% /warning %}}
127+
Any package source not marked as `secondary` will take precedence over [PyPI](https://pypi.org).
127128

128-
See [Supported Package Sources](#supported-package-sources) for source type specific information.
129129

130130
{{% note %}}
131131

132-
If your package source requires [credentials](#configuring-credentials) or
133-
[certificates](#certificates), please refer to the relevant sections below.
132+
If you prefer to disable [PyPI](https://pypi.org) completely, you may choose to set one of your package sources to be the [default](#default-package-source).
133+
134+
If you prefer to specify a package source for a specific dependency, see [Secondary Package Sources](#secondary-package-sources).
134135

135136
{{% /note %}}
136137

138+
139+
{{% warning %}}
140+
141+
If you do not want any of the custom sources to take precedence over [PyPI](https://pypi.org),
142+
you must declare **all** package sources to be [secondary](#secondary-package-sources).
143+
144+
{{% /warning %}}
145+
146+
137147
#### Default Package Source
138148

139149
By default, Poetry configures [PyPI](https://pypi.org) as the default package source for your
@@ -172,11 +182,21 @@ All package sources (including secondary sources) will be searched during the pa
172182
process. These network requests will occur for all sources, regardless of if the package is
173183
found at one or more sources.
174184

175-
If you wish to avoid this, you may explicitly specify which source to search in for a particular
176-
package.
185+
In order to limit the search for a specific package to a particular package repository, you can specify the source explicitly. This is strongly suggested for all private packages to avoid dependency confusion attacks.
177186

178187
```bash
179-
poetry add --source pypi httpx
188+
poetry add --source internal-pypi httpx
189+
```
190+
191+
```toml
192+
[tool.poetry.dependencies]
193+
...
194+
httpx = { version = "^0.22", source = "internal-pypi" }
195+
196+
[[tool.poetry.source]]
197+
name = "internal-pypi"
198+
url = "https://foo.bar/simple/"
199+
secondary = true
180200
```
181201

182202
{{% /note %}}

0 commit comments

Comments
 (0)