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: package-structure-code/declare-dependencies.md
+26-13Lines changed: 26 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ a user requires to install your package, can be stored in a
21
21
dependencies array located within the `[project]` table of your
22
22
pyproject.toml file. This looks something like this:
23
23
24
-
````toml
24
+
```toml
25
25
[project]
26
26
name = "examplePy"
27
27
authors = [
@@ -36,7 +36,7 @@ dependencies = [
36
36
37
37
## Development dependencies
38
38
39
-
Dependencies for building your documentation, running your tests and building your package's distribution files are often referred to as development dependencies. These are the dependnecies that a user needs to run core development elements of your package such as:
39
+
Dependencies for building your documentation, running your tests and building your package's distribution files are often referred to as development dependencies. These are the dependencies that a user needs to run core development elements of your package such as:
40
40
41
41
* running your test suite
42
42
* building your documentation
@@ -45,11 +45,11 @@ Dependencies for building your documentation, running your tests and building yo
45
45
These dependencies can be stored in an
46
46
`[optional.dependencies]` table within the **pyproject.toml** file.
47
47
48
-
```{admonition} What happened to the requirements.txt file for dependencies?
48
+
:::{admonition} What happened to the requirements.txt file for dependencies?
49
49
:class: note
50
50
51
51
The requirements.txt file used to be the default way to store dependencies. However in recent years, the ecosystem has moved to storing all of this information in a single **pyproject.toml** file. You may find that some projects do still maintain a requirements.txt file either for specific local development needs OR to support users who may want to create a pip-based virtual environment.
52
-
````
52
+
:::
53
53
54
54
## How to declare development dependencies
55
55
@@ -60,10 +60,11 @@ To declare dependencies in your **pyproject.toml** file:
60
60
61
61
`group-name = ["dep1", "dep2"]`
62
62
63
-
```{tip}
63
+
```{admonition} Installing packages from GitHub / Gitlab
64
+
:class: tip
64
65
65
66
If you have dependencies that need to be installed
66
-
directly from github using a `git+https` installation
67
+
directly from github using a `git+https` installation
67
68
approach then you may still need to use a requirements.txt or a conda environment file for your dependency installs.
68
69
69
70
```
@@ -88,21 +89,33 @@ lint = [
88
89
89
90
## How to install dependencies from your pyproject.toml
90
91
92
+
:::{admonition} Using `python -m pip`
93
+
94
+
In all of the examples in this guide, you will notice we are calling
95
+
`pip` using the syntax:
96
+
97
+
`python -m pip`
98
+
99
+
Calling pip using `python -m` ensures that the pip that you are using to install your package comes from your current active Python
100
+
environment. We strongly suggest that you use this approach whenever
101
+
you call `pip` to avoid installation conflicts.
102
+
:::
103
+
91
104
You can install development dependencies using the
92
105
groups that you defined above using the syntax:
93
106
94
-
`pip install .[docs]`
107
+
`python -m pip install .[docs]`
95
108
96
109
Above you install the dependencies needed for your documentation and also your package using pip. Below you
97
110
install just the dependencies needed to run your tests:
98
111
99
-
`pip install .[tests]`
112
+
`python -m pip install .[tests]`
100
113
101
114
You can install all dependencies in the `[optional.dependencies]` table using:
102
115
103
-
`pip install .[docs, tests, lint]`
116
+
`python -m pip install .[docs, tests, lint]`
104
117
105
-
Each time you call `pip install .[groups-here]`, you are also installing your package locally and also any dependencies
118
+
Each time you call `python -m pip install .[groups-here]`, you are also installing your package locally and also any dependencies
106
119
that your package needs / has declared in your pyproject.toml file.
107
120
108
121
```{admonition} For zsh shell users
@@ -111,7 +124,7 @@ that your package needs / has declared in your pyproject.toml file.
111
124
Some versions of shell don't support the square bracket syntax. In those cases you will need to add
112
125
quotes to your install call like this:
113
126
114
-
`pip install 'yourPackage.[tests]'`
127
+
`python -m pip install 'yourPackage.[tests]'`
115
128
116
129
```
117
130
@@ -133,12 +146,12 @@ dev = [
133
146
The above allows you to install both the tests and docs dependency lists
134
147
using the command:
135
148
136
-
`pip install .[dev]`
149
+
`python -m pip install .[dev]`
137
150
138
151
```{tip}
139
152
When you install dependencies using the above syntax:
140
153
141
-
`pip install .[tests, docs]`
154
+
`python -m pip install .[tests, docs]`
142
155
143
156
pip will also install both your package and its core dependencies.
0 commit comments