Benjamin Schubert pushed to branch bschubert/fix-pip-python at BuildStream / buildstream
Commits:
-
fe33e328
by James Ennis at 2018-11-08T17:54:18Z
-
09faf002
by James Ennis at 2018-11-08T17:54:18Z
-
d153453c
by Javier Jardón at 2018-11-08T18:22:54Z
-
7738f6df
by Daniel Silverstone at 2018-11-09T11:25:44Z
-
62f59eaa
by Valentin David at 2018-11-09T13:30:06Z
-
e9ef7286
by Benjamin Schubert at 2018-11-09T14:22:48Z
5 changed files:
- buildstream/_artifactcache/artifactcache.py
- buildstream/plugin.py
- buildstream/plugins/sources/pip.py
- doc/source/using_config.rst
- tests/utils/misc.py
Changes:
| ... | ... | @@ -937,15 +937,22 @@ class ArtifactCache(): |
| 937 | 937 |
"Invalid cache quota ({}): ".format(utils._pretty_size(cache_quota)) +
|
| 938 | 938 |
"BuildStream requires a minimum cache quota of 2G.")
|
| 939 | 939 |
elif cache_quota > cache_size + available_space: # Check maximum
|
| 940 |
+ if '%' in self.context.config_cache_quota:
|
|
| 941 |
+ available = (available_space / (stat.f_blocks * stat.f_bsize)) * 100
|
|
| 942 |
+ available = '{}% of total disk space'.format(round(available, 1))
|
|
| 943 |
+ else:
|
|
| 944 |
+ available = utils._pretty_size(available_space)
|
|
| 945 |
+ |
|
| 940 | 946 |
raise LoadError(LoadErrorReason.INVALID_DATA,
|
| 941 | 947 |
("Your system does not have enough available " +
|
| 942 | 948 |
"space to support the cache quota specified.\n" +
|
| 943 |
- "You currently have:\n" +
|
|
| 944 |
- "- {used} of cache in use at {local_cache_path}\n" +
|
|
| 945 |
- "- {available} of available system storage").format(
|
|
| 946 |
- used=utils._pretty_size(cache_size),
|
|
| 947 |
- local_cache_path=self.context.artifactdir,
|
|
| 948 |
- available=utils._pretty_size(available_space)))
|
|
| 949 |
+ "\nYou have specified a quota of {quota} total disk space.\n" +
|
|
| 950 |
+ "- The filesystem containing {local_cache_path} only " +
|
|
| 951 |
+ "has: {available_size} available.")
|
|
| 952 |
+ .format(
|
|
| 953 |
+ quota=self.context.config_cache_quota,
|
|
| 954 |
+ local_cache_path=self.context.artifactdir,
|
|
| 955 |
+ available_size=available))
|
|
| 949 | 956 |
|
| 950 | 957 |
# Place a slight headroom (2e9 (2GB) on the cache_quota) into
|
| 951 | 958 |
# cache_quota to try and avoid exceptions.
|
| ... | ... | @@ -111,6 +111,7 @@ Class Reference |
| 111 | 111 |
|
| 112 | 112 |
import os
|
| 113 | 113 |
import subprocess
|
| 114 |
+import sys
|
|
| 114 | 115 |
from contextlib import contextmanager
|
| 115 | 116 |
from weakref import WeakValueDictionary
|
| 116 | 117 |
|
| ... | ... | @@ -190,7 +191,7 @@ class Plugin(): |
| 190 | 191 |
# Dont send anything through the Message() pipeline at destruction time,
|
| 191 | 192 |
# any subsequent lookup of plugin by unique id would raise KeyError.
|
| 192 | 193 |
if self.__context.log_debug:
|
| 193 |
- print("DEBUG: Destroyed: {}".format(self))
|
|
| 194 |
+ sys.stderr.write("DEBUG: Destroyed: {}\n".format(self))
|
|
| 194 | 195 |
|
| 195 | 196 |
def __str__(self):
|
| 196 | 197 |
return "{kind} {typetag} at {provenance}".format(
|
| ... | ... | @@ -80,6 +80,7 @@ _PYPI_INDEX_URL = 'https://pypi.org/simple/' |
| 80 | 80 |
|
| 81 | 81 |
# Used only for finding pip command
|
| 82 | 82 |
_PYTHON_VERSIONS = [
|
| 83 |
+ 'python', # when running in a venv, we might not have the exact version
|
|
| 83 | 84 |
'python2.7',
|
| 84 | 85 |
'python3.0',
|
| 85 | 86 |
'python3.1',
|
| ... | ... | @@ -147,6 +147,44 @@ The default mirror is defined by its name, e.g. |
| 147 | 147 |
``--default-mirror`` command-line option.
|
| 148 | 148 |
|
| 149 | 149 |
|
| 150 |
+Local cache expiry
|
|
| 151 |
+~~~~~~~~~~~~~~~~~~
|
|
| 152 |
+BuildStream locally caches artifacts, build trees, log files and sources within a
|
|
| 153 |
+cache located at ``~/.cache/buildstream`` (unless a $XDG_CACHE_HOME environment
|
|
| 154 |
+variable exists). When building large projects, this cache can get very large,
|
|
| 155 |
+thus BuildStream will attempt to clean up the cache automatically by expiring the least
|
|
| 156 |
+recently *used* artifacts.
|
|
| 157 |
+ |
|
| 158 |
+By default, cache expiry will begin once the file system which contains the cache
|
|
| 159 |
+approaches maximum usage. However, it is also possible to impose a quota on the local
|
|
| 160 |
+cache in the user configuration. This can be done in two ways:
|
|
| 161 |
+ |
|
| 162 |
+1. By restricting the maximum size of the cache directory itself.
|
|
| 163 |
+ |
|
| 164 |
+For example, to ensure that BuildStream's cache does not grow beyond 100 GB,
|
|
| 165 |
+simply declare the following in your user configuration (``~/.config/buildstream.conf``):
|
|
| 166 |
+ |
|
| 167 |
+.. code:: yaml
|
|
| 168 |
+ |
|
| 169 |
+ cache:
|
|
| 170 |
+ quota: 100G
|
|
| 171 |
+ |
|
| 172 |
+This quota defines the maximum size of the artifact cache in bytes.
|
|
| 173 |
+Other accepted values are: K, M, G or T (or you can simply declare the value in bytes, without the suffix).
|
|
| 174 |
+This uses the same format as systemd's
|
|
| 175 |
+`resource-control <https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html>`_.
|
|
| 176 |
+ |
|
| 177 |
+2. By expiring artifacts once the file system which contains the cache exceeds a specified usage.
|
|
| 178 |
+ |
|
| 179 |
+To ensure that we start cleaning the cache once we've used 80% of local disk space (on the file system
|
|
| 180 |
+which mounts the cache):
|
|
| 181 |
+ |
|
| 182 |
+.. code:: yaml
|
|
| 183 |
+ |
|
| 184 |
+ cache:
|
|
| 185 |
+ quota: 80%
|
|
| 186 |
+ |
|
| 187 |
+ |
|
| 150 | 188 |
Default configuration
|
| 151 | 189 |
---------------------
|
| 152 | 190 |
The default BuildStream configuration is specified here for reference:
|
| ... | ... | @@ -27,4 +27,5 @@ def test_parse_size_over_1024T(cli, tmpdir): |
| 27 | 27 |
patched_statvfs = mock_os.mock_statvfs(f_bavail=bavail, f_bsize=BLOCK_SIZE)
|
| 28 | 28 |
with mock_os.monkey_patch("statvfs", patched_statvfs):
|
| 29 | 29 |
result = cli.run(project, args=["build", "file.bst"])
|
| 30 |
- assert "1025T of available system storage" in result.stderr
|
|
| 30 |
+ failure_msg = 'Your system does not have enough available space to support the cache quota specified.'
|
|
| 31 |
+ assert failure_msg in result.stderr
|
