Skip to content

Commit 0901d64

Browse files
authored
add section: File resolution (DavHau#434)
1 parent 4dde445 commit 0901d64

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Readme.md

+55
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Table of Contents
4444
* [Why nix?](#why-nix)
4545
* [How does mach-nix work?](#how-does-mach-nix-work)
4646
* [Dependency resolution](#dependency-resolution)
47+
* [File resolution](#file-resolution)
4748
* [Generating a nix expression](#generating-a-nix-expression)
4849
* [Contributing](#contributing)
4950
* [Limitations](#limitations)
@@ -203,6 +204,60 @@ As core for the resolving resolvelib is used: https://github.com/sarugaku/resolv
203204

204205
Mach-nix supports multiple providers to retrieve python packages from. The user can specify which providers should be preferred. Packages from different providers can be mixed.
205206

207+
### File resolution
208+
With `pypi-deps-db`, we have built a dependency graph, where each package is defined by name and version, for example `pillow-9.1.0`.
209+
210+
To download a package, we need it's URL and hash. This is where [nix-pypi-fetcher](https://github.com/DavHau/nix-pypi-fetcher) comes in.
211+
`nix-pypi-fetcher` is another database, which allows us to resolve packages to their URL and hash.
212+
213+
For example, the declaration "package pillow + version 9.1.0 + python 3.9 + linux" resolves to
214+
215+
```json
216+
"Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl": [
217+
"gig6+ZwcOluh2kTGcpbVqtGfEcU1tVGlrlUyijF84zE=",
218+
"cp39"
219+
],
220+
```
221+
222+
The wheel URL is constructed in [pypi-crawlers/src/crawl_wheel_deps.py](pypi-crawlers/src/crawl_wheel_deps.py)
223+
224+
```py
225+
def construct_url(name, pyver, filename: str):
226+
base_url = "https://files.pythonhosted.org/packages/"
227+
return f"{base_url}{pyver}/{name[0]}/{name}/{filename}"
228+
```
229+
230+
So in this example, the full URL would be
231+
232+
```
233+
https://files.pythonhosted.org/packages/cp39/p/pillow/Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
234+
```
235+
236+
Now we can call Nix's `fetchurl` like
237+
238+
```nix
239+
builtins.fetchurl {
240+
url = "https://files.pythonhosted.org/packages/cp39/p/pillow/Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl";
241+
sha256 = "gig6+ZwcOluh2kTGcpbVqtGfEcU1tVGlrlUyijF84zE=";
242+
}
243+
```
244+
245+
... and we get
246+
247+
```
248+
$ unzip -l /nix/store/7gbbbrsqkw7f69axyh818abh9yw45fnb-Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | head
249+
Archive: /nix/store/7gbbbrsqkw7f69axyh818abh9yw45fnb-Pillow-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
250+
Length Date Time Name
251+
--------- ---------- ----- ----
252+
0 04-01-2022 10:08 PIL/
253+
0 04-01-2022 10:08 Pillow.libs/
254+
0 04-01-2022 10:08 Pillow-9.1.0.dist-info/
255+
7311 04-01-2022 10:08 PIL/PdfImagePlugin.py
256+
141328 04-01-2022 10:08 PIL/_imagingcms.cpython-39-x86_64-linux-gnu.so
257+
46872 04-01-2022 10:08 PIL/_imagingtk.cpython-39-x86_64-linux-gnu.so
258+
1513 04-01-2022 10:08 PIL/GribStubImagePlugin.py
259+
```
260+
206261
### Generating a nix expression
207262
After all python dependencies and their providers have been determined by the dependency resolver, mach-nix will generate a nix expression defining your python environment.
208263

0 commit comments

Comments
 (0)