Skip to content

Commit af7aa48

Browse files
Expand user defined mapping documentation.
Make it more explicit what the user defined mapping does, and add a couple more examples from the field that explain the direction of the mapping. Have an anchor leading to the user defined mapping section from a previous doc section where it us used.
1 parent 8985af7 commit af7aa48

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

docs/explanation.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ no matter where this virtualenv may be located.
8383
### Identity mapping
8484

8585
When unable to find an installed package that corresponds to a declared
86-
dependency either via a user-provided mapping or local Python environments,
87-
FawltyDeps will fall back to one of two strategies. "Identity mapping", which we
88-
present in this section is the default fallback strategy. We discuss the other
89-
strategy in the next subsection.
86+
dependency either via a [user-defined mapping](#user-defined-mapping) or local
87+
Python environments, FawltyDeps will fall back to one of two strategies.
88+
"Identity mapping", which we present in this section is the default fallback
89+
strategy. We discuss the other strategy in the next subsection.
9090

9191
Identity mapping relies on the simplistic assumption that the dependency provides
9292
a single import of the same name, i.e. it will expect that when you depend on
@@ -135,16 +135,28 @@ In this case, FawltyDeps will throw an error and abort.
135135

136136
### User-defined mapping
137137

138+
Sometimes Python dependencies are imported using a different name than the package
139+
name used in the `import` statement. Some Python packages might have hyphens in
140+
their dependency names used by package managers, but underscores in their import
141+
names, for example.
142+
138143
We provide a custom mapping functionality to users wishing to take control
139144
over the way FawltyDeps resolves dependencies. You may define your own mapping
140145
of dependency names to import names, by providing a TOML file like this:
141146

142147
```toml
148+
langchain-core = ["langchain_core"]
149+
multiple-modules = ["module1", "module2"]
143150
my-package = ["mpkg"]
151+
python-dotenv = ["dotenv"]
144152
scikit-learn = ["sklearn"]
145-
multiple-modules = ["module1", "module2"]
146153
```
147154

155+
The package name of the dependency is on the left-hand side of the `=`, and the
156+
import name(s) are on the right-hand side. You can provide multiple import names
157+
for a single dependency.
158+
159+
148160
To use your mapping, run:
149161

150162
```sh
@@ -159,9 +171,11 @@ project, inside a `[tool.fawltydeps.custom_mapping]` section, like this:
159171

160172
```toml
161173
[tool.fawltydeps.custom_mapping]
174+
langchain-core = ["langchain_core"]
175+
multiple-modules = ["module1", "module2"]
162176
my-package = ["mpkg"]
177+
python-dotenv = ["dotenv"]
163178
scikit-learn = ["sklearn"]
164-
multiple-modules = ["module1", "module2"]
165179
```
166180

167181
The provided mapping can be complete or partial. When a dependency is not

0 commit comments

Comments
 (0)