@@ -138,22 +138,18 @@ When FawltyDeps looks for undeclared and unused dependencies, it needs to match
138
138
` import ` statements in your code with corresponding package dependencies
139
139
declared in your project configuration.
140
140
141
- To solve this, FawltyDeps adopts several strategies: mapping provided by the user,
142
- identity mapping, and most powerful of all - using your python environment.
141
+ To solve this, FawltyDeps uses a sequence of resolvers (aka. mapping strategies)
142
+ to determine which Python packages that provide which import names:
143
143
144
144
#### Python environment mapping
145
145
146
- FawltyDeps looks at the packages installed in your _ current
147
- Python environment _ and what import names each of them provide in order to
148
- correctly match your dependencies against your imports .
146
+ First of all FawltyDeps looks for _ Python environments _ (virtualenvs or similar
147
+ directories like ` .venv ` or ` __pypackages__ ` .) inside your project (i.e. under
148
+ ` basepath ` , if given, or the current directory) .
149
149
150
- The _ current Python environment_ in this case is the environment in which
151
- FawltyDeps itself is installed. This works well when you, for example,
152
- ` pip install fawltydeps ` into the same virtualenv as your project dependencies.
153
-
154
- If you instead want FawltyDeps to look into a _ different_ Python environment for
155
- mapping dependencies to import names, you can use the ` --pyenv ` option,
156
- for example:
150
+ You can use the ` --pyenv ` option (or the ` pyenvs ` configuration directive)
151
+ to point FawltyDeps at a specific Python environment located within your project
152
+ or elsewhere. For example:
157
153
158
154
``` sh
159
155
fawltydeps --code my_package/ --deps pyproject.toml --pyenv .venv/
@@ -166,17 +162,23 @@ This will tell FawltyDeps:
166
162
- to use the Python environment at ` .venv/ ` to map dependency names in
167
163
` pyproject.toml ` into import names used in your code under ` my_package/ `
168
164
165
+ If ` --pyenv ` is not used, and no Python environments are found within your project,
166
+ FawltyDeps will fall back to looking at your _ current Python environment_ :
167
+ This is the environment in which FawltyDeps itself is installed.
168
+ This works well when you, for example, ` pip install fawltydeps ` into the same
169
+ virtualenv as your project dependencies.
170
+
169
171
You can use ` --pyenv ` multiple times to have FawltyDeps look for packages in
170
- multiple Python environments. When mapping a dependency into import names,
171
- FawltyDeps will then use the union of all imports provided by all matching
172
- packages across those Python environments as valid import names for that
173
- dependency.
172
+ multiple Python environments. In this case (or when multiple Python environments
173
+ are found inside your project) FawltyDeps will use the union (superset) of all
174
+ imports provided by all matching packages across those Python environments as
175
+ valid import names for that dependency.
174
176
175
177
#### Identity mapping
176
178
177
- When FawltyDeps is unable to find an installed package that corresponds to a
178
- declared dependency, FawltyDeps will fall back to an "identity mapping", where
179
- it _ assumes_ that the dependency provides a single import of the same name,
179
+ When unable to find an installed package that corresponds to a declared
180
+ dependency, FawltyDeps will fall back to an "identity mapping", where it
181
+ _ assumes_ that the dependency provides a single import of the same name,
180
182
i.e. it will expect that when you depend on ` some_package ` , then that should
181
183
correspond to ` import some_package ` statements in your code.
182
184
@@ -188,8 +190,8 @@ project dependencies](#why-must-fawltydeps-run-in-the-same-python-environment-as
188
190
189
191
#### User-defined mapping
190
192
191
- You may define your mapping by providing a toml file with package to imports mapping,
192
- ` my_mapping.toml ` :
193
+ As a final solution and/or an ultimate override, you may define your own mapping
194
+ of dependency names to import names, by providing a TOML file like this :
193
195
194
196
``` toml
195
197
my-package = [" mpkg" ]
@@ -203,9 +205,11 @@ To use your mapping, run:
203
205
fawltydeps --custom-mapping-file my_mapping.toml
204
206
```
205
207
206
- FawltyDeps will parse ` my_mapping.toml ` file and use extracted mapping for matching dependencies to imports.
208
+ FawltyDeps will parse your ` my_mapping.toml ` file and use the extracted mapping
209
+ for matching dependencies to imports.
207
210
208
- You may also place the custom mapping in the ` pyproject.toml ` file of your project, inside a ` [tool.fawltydeps.custom_mapping] ` section, like this:
211
+ You may also place the custom mapping in the ` pyproject.toml ` file of your
212
+ project, inside a ` [tool.fawltydeps.custom_mapping] ` section, like this:
209
213
210
214
``` toml
211
215
[tool .fawltydeps .custom_mapping ]
@@ -214,9 +218,10 @@ scikit-learn = ["sklearn"]
214
218
multiple-modules = [" module1" , " module2" ]
215
219
```
216
220
217
- Caution when using your mapping is advised. The user-defined mapping takes precedence over all other resolving strategies.
218
- If the mapping file has some stale mapping entries, they will not be resolved by
219
- Python environment resolver (which in general is the most accurate).
221
+ Caution when using your mapping is advised: The user-defined mapping takes
222
+ precedence over the other resolvers documented above. For example, if the
223
+ mapping file has some stale/incorrect mapping entries, they will _ not_ be
224
+ resolved by the Python environment resolver (which is geenrally more accurate).
220
225
221
226
### Ignoring irrelevant results
222
227
@@ -276,10 +281,11 @@ Here is a complete list of configuration directives we support:
276
281
Defaults to the current directory, i.e. like ` code = ["."] ` .
277
282
- ` deps ` : Files or directories containing the declared dependencies.
278
283
Defaults to the current directory, i.e. like ` deps = ["."] ` .
279
- - ` pyenvs ` : Python environments (directories like ` .venv ` , ` __pypackages__ ` , or
280
- similar) to use for resolving project dependencies into provided import names.
281
- Defaults to an empty list, i.e. like ` pyenvs = [] ` , which is interpreted as
282
- using the Python environment where FawltyDeps is installed (aka. ` sys.path ` ).
284
+ - ` pyenvs ` : Where to look for Python environments (directories like ` .venv ` ,
285
+ ` __pypackages__ ` , or similar) to be uses for resolving project dependencies
286
+ into provided import names. Defaults to looking for Python environments under
287
+ the current directory, i.e. like ` pyenvs = ["."] ` . If none are found, use the
288
+ Python environment where FawltyDeps is installed (aka. ` sys.path ` ).
283
289
- ` output_format ` : Which output format to use by default. One of ` human_summary ` ,
284
290
` human_detailed ` , or ` json ` .
285
291
The default corresponds to ` output_format = "human_summary" ` .
@@ -507,13 +513,19 @@ fawltydeps libX
507
513
508
514
### Why must FawltyDeps run in the same Python environment as my project dependencies?
509
515
510
- As explained above in the section on [ resolving dependencies via your Python
511
- environment] ( #resolving-dependencies-via-your-python-environment ) , the core
512
- logic of FawltyDeps needs to match ` import ` statements in your code with
513
- dependencies declared in your project configuration. This is straightforward
514
- for many packages: for example you ` pip install requests ` and then
515
- you can ` import requests ` in your code. However, this mapping from the name you
516
- install to the name you ` import ` is not always self-evident:
516
+ (This is no longer true since FawltyDeps v0.11: FawltyDeps should be able to
517
+ automatically find your project dependencies when they are installed in a Python
518
+ environment that exists within your project. If your project dependencies are
519
+ installed elsewhere, you can point FawltyDeps in their direction with ` --pyenv ` ,
520
+ as explained above in the section on
521
+ [ Python environment mapping] ( #python-environment-mapping ) )
522
+
523
+ The reason why FawltyDeps need to find your project dependencies _ somewhere_ is
524
+ that the core logic of FawltyDeps needs to match ` import ` statements in your
525
+ code with dependencies declared in your project configuration. This seems
526
+ straightforward for many packages: for example you ` pip install requests ` and
527
+ then you can ` import requests ` in your code. However, this mapping from the name
528
+ you install to the name you ` import ` is not always self-evident:
517
529
518
530
- There are sometimes differences between the package name that you
519
531
declare as a dependency, and the ` import ` name it provides. For example, you
@@ -524,11 +536,18 @@ install to the name you `import` is not always self-evident:
524
536
FawltyDeps need to figure out that this corresponds to the ` setuptools `
525
537
dependency.
526
538
527
- To solve this, FawltyDeps looks at the packages installed in your current Python
528
- environment (or the environment given by the ` --pyenv ` option) to correctly map
529
- dependencies (package names) into the imports that they provide.
539
+ To solve this, FawltyDeps looks at the packages installed in your Python
540
+ environment to correctly map dependencies (package names) into the imports that
541
+ they provide. This is:
542
+
543
+ - any Python environment found via the ` --pyenv ` option, or
544
+ - any Python environment found within your project (` basepath ` or the current
545
+ directory).
546
+ - Failing that, FawltyDeps will use the _ current Python environment_ ,
547
+ i.e. the one in which FawltyDeps itself is running.
530
548
531
- However, when an installed package is not found for a declared dependency, the
549
+ As a final resort, when an installed package is not found for a declared
550
+ dependency, the
532
551
_ identity mapping_ that FawltyDeps falls back to will still do a good job for
533
552
the majority of dependencies where the import name is indeed identical to the
534
553
package name that you depend on.
@@ -545,13 +564,11 @@ _undeclared_ and `scikit-learn` as an _unused_ dependency.
545
564
546
565
This is very much related to the above question. ` scikit-learn ` is an example
547
566
of a package that exposes a different import name: ` sklearn ` .
548
- When ` scikit-learn ` is not installed in the current Python environment (the one
549
- that FawltyDeps uses to find these mappings), then FawltyDeps is unable to make
550
- the connection between these two names.
567
+ When ` scikit-learn ` is not found in the Python environment(s) used by FawltyDeps,
568
+ then FawltyDeps is unable to make the connection between these two names.
551
569
552
- To solve this problem, make sure that you either install and run FawltyDeps
553
- in a development environment (e.g. virtualenv) where your project's dependencies
554
- (including ` scikit-learn ` ) are also installed. Alternatively, you can use the
570
+ To solve this problem, make sure that ` scikit-learn ` is installed in a Python
571
+ environment that belongs to your project. Alternatively, you can use the
555
572
` --pyenv ` option to point at a Python environment where ` scikit-learn ` and your
556
573
other dependencies are installed.
557
574
0 commit comments