1 | *************************************** |
---|
2 | Building Tahoe-LAFS On A Desert Island |
---|
3 | *************************************** |
---|
4 | |
---|
5 | (or an airplane, or anywhere else without internet connectivity) |
---|
6 | |
---|
7 | Here's the story: you leave for the airport in an hour, you know you want to |
---|
8 | do some Tahoe hacking on the flight. What can you grab right now that will |
---|
9 | let you install the necessary dependencies later, when you are offline? |
---|
10 | |
---|
11 | Pip can help, with a technique described in the pip documentation |
---|
12 | https://pip.pypa.io/en/stable/user_guide/#installing-from-local-packages . |
---|
13 | |
---|
14 | First, do two setup steps: |
---|
15 | |
---|
16 | * ``mkdir ~/.pip/wheels`` |
---|
17 | * edit ``~/.pip/pip.conf`` to set ``[global] find-links = ~/.pip/wheels`` |
---|
18 | |
---|
19 | (the filename may vary on non-unix platforms: check the pip documentation for |
---|
20 | details) |
---|
21 | |
---|
22 | This instructs all ``pip install`` commands to look in your local directory |
---|
23 | for compiled wheels, in addition to asking PyPI and the normal wheel cache. |
---|
24 | |
---|
25 | Before you get shipwrecked (or leave the internet for a while), do this from |
---|
26 | your tahoe source tree (or any python source tree that you want to hack on): |
---|
27 | |
---|
28 | * ``pip wheel -w ~/.pip/wheels .`` |
---|
29 | |
---|
30 | That command will require network and time: it will download and compile |
---|
31 | whatever is necessary right away. Schedule your shipwreck for *after* it |
---|
32 | completes. |
---|
33 | |
---|
34 | Specifically, it will get wheels for everything that the current project |
---|
35 | (".", i.e. tahoe) needs, and write them to the ``~/.pip/wheels`` directory. |
---|
36 | It will query PyPI to learn the current version of every dependency, then |
---|
37 | acquire wheels from the first source that has one: |
---|
38 | |
---|
39 | * copy from our ``~/.pip/wheels`` directory |
---|
40 | * copy from the local wheel cache (see below for where this lives) |
---|
41 | * download a wheel from PyPI |
---|
42 | * build a wheel from a tarball (cached or downloaded) |
---|
43 | |
---|
44 | Later, on the plane, do this: |
---|
45 | |
---|
46 | * ``virtualenv --no-download ve`` |
---|
47 | * ``. ve/bin/activate`` |
---|
48 | * ``pip install --no-index --editable .`` |
---|
49 | |
---|
50 | That tells virtualenv/pip to not try to contact PyPI, and your ``pip.conf`` |
---|
51 | "find-links" tells them to use the wheels in ``~/.pip/wheels/`` instead. |
---|
52 | |
---|
53 | How This Works |
---|
54 | ============== |
---|
55 | |
---|
56 | The pip wheel cache |
---|
57 | ------------------- |
---|
58 | |
---|
59 | Modern versions of pip and setuptools will, by default, cache both their HTTP |
---|
60 | downloads and their generated wheels. When pip is asked to install a package, |
---|
61 | it will first check with PyPI. If the PyPI index says it needs to download a |
---|
62 | newer version, but it can find a copy of the tarball/zipball/wheel in the |
---|
63 | HTTP cache, it will not actually download anything. Then it tries to build a |
---|
64 | wheel: if it already has one in the wheel cache (downloaded or built |
---|
65 | earlier), it will not actually build anything. |
---|
66 | |
---|
67 | If it cannot contact PyPI, it will fail. The ``--no-index`` above is to tell |
---|
68 | it to skip the PyPI step, but that leaves it with no source of packages. The |
---|
69 | ``find-links`` setting is what provides an alternate source of packages. |
---|
70 | |
---|
71 | The HTTP and wheel caches are not single flat directories: they use a |
---|
72 | hierarchy of subdirectories, named after a hash of the URL or name of the |
---|
73 | object being stored (this is to avoid filesystem limitations on the size of a |
---|
74 | directory). As a result, the wheel cache is not suitable for use as a |
---|
75 | ``find-links`` target (but see below). |
---|
76 | |
---|
77 | There is a command named ``pip wheel`` which only creates wheels (and stores |
---|
78 | them in ``--wheel-dir=``, which defaults to the current directory). This |
---|
79 | command does not populate the wheel cache: it reads from (and writes to) the |
---|
80 | HTTP cache, and reads from the wheel cache, but will only save the generated |
---|
81 | wheels into the directory you specify with ``--wheel-dir=``. |
---|
82 | |
---|
83 | Where Does The Cache Live? |
---|
84 | -------------------------- |
---|
85 | |
---|
86 | Pip's cache location depends upon the platform. On linux, it defaults to |
---|
87 | ~/.cache/pip/ (both http/ and wheels/). On OS-X (homebrew), it uses |
---|
88 | ~/Library/Caches/pip/ . On Windows, try ~\AppData\Local\pip\cache . |
---|
89 | |
---|
90 | The location can be overridden by ``pip.conf``. Look for the "wheel-dir", |
---|
91 | "cache-dir", and "find-links" options. |
---|
92 | |
---|
93 | How Can I Tell If It's Using The Cache? |
---|
94 | --------------------------------------- |
---|
95 | |
---|
96 | When "pip install" has to download a source tarball (and build a wheel), it |
---|
97 | will say things like:: |
---|
98 | |
---|
99 | Collecting zfec |
---|
100 | Downloading zfec-1.4.24.tar.gz (175kB) |
---|
101 | Building wheels for collected packages: zfec |
---|
102 | Running setup.py bdist_wheel for zfec ... done |
---|
103 | Stored in directory: $CACHEDIR |
---|
104 | Successfully built zfec |
---|
105 | Installing collected packages: zfec |
---|
106 | Successfully installed zfec-1.4.24 |
---|
107 | |
---|
108 | When "pip install" can use a cached downloaded tarball, but does not have a |
---|
109 | cached wheel, it will say:: |
---|
110 | |
---|
111 | Collecting zfec |
---|
112 | Using cached zfec-1.4.24.tar.gz |
---|
113 | Building wheels for collected packages: zfec |
---|
114 | Running setup.py bdist_wheel for zfec ... done |
---|
115 | Stored in directory: $CACHEDIR |
---|
116 | Successfully built zfec |
---|
117 | Installing collected packages: zfec |
---|
118 | Successfully installed zfec-1.4.24 |
---|
119 | |
---|
120 | When "pip install" can use a cached wheel, it will just say:: |
---|
121 | |
---|
122 | Collecting zfec |
---|
123 | Installed collected packages: zfec |
---|
124 | Successfully installed zfec-1.4.24 |
---|
125 | |
---|
126 | Many packages publish pre-built wheels next to their source tarballs. This is |
---|
127 | common for non-platform-specific (pure-python) packages. It is also common |
---|
128 | for them to provide pre-compiled windows and OS-X wheel, so users do not have |
---|
129 | to have a compiler installed (pre-compiled Linux wheels are not common, |
---|
130 | because there are too many platform variations). When "pip install" can use a |
---|
131 | downloaded wheel like this, it will say:: |
---|
132 | |
---|
133 | Collecting six |
---|
134 | Downloading six-1.10.0-py2.py3-none-any.whl |
---|
135 | Installing collected packages: six |
---|
136 | Successfully installed six-1.10.0 |
---|
137 | |
---|
138 | Note that older versions of pip do not always use wheels, or the cache. Pip |
---|
139 | 8.0.0 or newer should be ok. The version of setuptools may also be |
---|
140 | significant. |
---|