[Notes] [Git][BuildStream/buildstream][lachlan/pickle-yaml-test-list-composite] 11 commits: doc: updates considering website being live now



Title: GitLab

Lachlan pushed to branch lachlan/pickle-yaml-test-list-composite at BuildStream / buildstream

Commits:

19 changed files:

Changes:

  • CONTRIBUTING.rst
    ... ... @@ -1147,7 +1147,7 @@ To actually regenerate the code::
    1147 1147
     Documenting
    
    1148 1148
     -----------
    
    1149 1149
     BuildStream starts out as a documented project from day one and uses
    
    1150
    -sphinx to document itself.
    
    1150
    +`sphinx <www.sphinx-doc.org>`_ to document itself.
    
    1151 1151
     
    
    1152 1152
     This section discusses formatting policies for editing files in the
    
    1153 1153
     ``doc/source`` directory, and describes the details of how the docs are
    
    ... ... @@ -1194,10 +1194,8 @@ The BuildStream documentation style is as follows:
    1194 1194
         the target, e.g.: ``:ref:`Link text <anchor_name>```.
    
    1195 1195
         Note that the "_" prefix is not used when referring to the target.
    
    1196 1196
     
    
    1197
    -Useful links:
    
    1198
    -
    
    1199
    -For further information, please see the `Sphinx Documentation
    
    1200
    -<http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html>`_.
    
    1197
    +For further information about using the reStructuredText with sphinx, please see the
    
    1198
    +`Sphinx Documentation <http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html>`_.
    
    1201 1199
     
    
    1202 1200
     
    
    1203 1201
     Building Docs
    
    ... ... @@ -1266,10 +1264,101 @@ the ``man/`` subdirectory, which will be automatically included
    1266 1264
     in the buildstream distribution.
    
    1267 1265
     
    
    1268 1266
     
    
    1269
    -Documentation Examples
    
    1270
    -~~~~~~~~~~~~~~~~~~~~~~
    
    1271
    -The examples section of the documentation contains a series of standalone
    
    1272
    -examples, here are the criteria for an example addition.
    
    1267
    +User guide
    
    1268
    +~~~~~~~~~~
    
    1269
    +The :ref:`user guide <using>` is comprised of free form documentation
    
    1270
    +in manually written ``.rst`` files and is split up into a few sections,
    
    1271
    +of main interest are the :ref:`tutorial <tutorial>` and the
    
    1272
    +:ref:`examples <examples>`.
    
    1273
    +
    
    1274
    +The distinction of the two categories of user guides is important to
    
    1275
    +understand too.
    
    1276
    +
    
    1277
    +* **Tutorial**
    
    1278
    +
    
    1279
    +  The tutorial is structured as a series of exercises which start with
    
    1280
    +  the most basic concepts and build upon the previous chapters in order
    
    1281
    +  to arrive at a basic understanding of how to create BuildStream projects.
    
    1282
    +
    
    1283
    +  This series of examples should be easy enough to complete in a matter
    
    1284
    +  of a few hours for a new user, and should provide just enough insight to
    
    1285
    +  get the user started in creating their own projects.
    
    1286
    +
    
    1287
    +  Going through the tutorial step by step should also result in the user
    
    1288
    +  becoming proficient enough with the reference manual to get by on their own.
    
    1289
    +
    
    1290
    +* **Examples**
    
    1291
    +
    
    1292
    +  These exist to demonstrate how to accomplish more advanced tasks which
    
    1293
    +  are not always obvious and discoverable.
    
    1294
    +
    
    1295
    +  Alternatively, these also demonstrate elegant and recommended ways of
    
    1296
    +  accomplishing some tasks which could be done in various ways.
    
    1297
    +
    
    1298
    +
    
    1299
    +Guidelines
    
    1300
    +''''''''''
    
    1301
    +Here are some general guidelines for adding new free form documentation
    
    1302
    +to the user guide.
    
    1303
    +
    
    1304
    +* **Focus on a single subject**
    
    1305
    +
    
    1306
    +  It is important to stay focused on a single subject and avoid getting
    
    1307
    +  into tangential material when creating a new entry, so that the articles
    
    1308
    +  remain concise and the user is not distracted by unrelated subject material.
    
    1309
    +
    
    1310
    +  A single tutorial chapter or example should not introduce any additional
    
    1311
    +  subject material than the material being added for the given example.
    
    1312
    +
    
    1313
    +* **Reuse existing sample project elements**
    
    1314
    +
    
    1315
    +  To help avoid distracting from the topic at hand, it is always preferable to
    
    1316
    +  reuse the same project sample material from other examples and only deviate
    
    1317
    +  slightly to demonstrate the new material, than to create completely new projects.
    
    1318
    +
    
    1319
    +  This helps us remain focused on a single topic at a time, and reduces the amount
    
    1320
    +  of unrelated material the reader needs to learn in order to digest the new
    
    1321
    +  example.
    
    1322
    +
    
    1323
    +* **Don't be redundant**
    
    1324
    +
    
    1325
    +  When something has already been explained in the tutorial or in another example,
    
    1326
    +  it is best to simply refer to the other user guide entry in a new example.
    
    1327
    +
    
    1328
    +  Always prefer to link to the tutorial if an explanation exists in the tutorial,
    
    1329
    +  rather than linking to another example, where possible.
    
    1330
    +
    
    1331
    +* **Link into the reference manual at every opportunity**
    
    1332
    +
    
    1333
    +  The format and plugin API is 100% documented at all times. Whenever discussing
    
    1334
    +  anything about the format or plugin API, always do so while providing a link
    
    1335
    +  into the more terse reference material.
    
    1336
    +
    
    1337
    +  We don't want users to have to search for the material themselves, and we also
    
    1338
    +  want the user to become proficient at navigating the reference material over
    
    1339
    +  time.
    
    1340
    +
    
    1341
    +* **Use concise terminology**
    
    1342
    +
    
    1343
    +  As developers, we tend to come up with code names for features we develop, and
    
    1344
    +  then end up documenting a new feature in an example.
    
    1345
    +
    
    1346
    +  Never use a code name or shorthand to refer to a feature in the user guide, instead
    
    1347
    +  always use fully qualified sentences outlining very explicitly what we are doing
    
    1348
    +  in the example, or what the example is for in the case of a title.
    
    1349
    +
    
    1350
    +  We need to be considerate that the audience of our user guide is probably a
    
    1351
    +  proficient developer or integrator, but has no idea what we might have decided
    
    1352
    +  to name a given activity.
    
    1353
    +
    
    1354
    +
    
    1355
    +Structure of an example
    
    1356
    +'''''''''''''''''''''''
    
    1357
    +The :ref:`tutorial <tutorial>` and the :ref:`examples <examples>` sections
    
    1358
    +of the documentation contain a series of sample projects, each chapter in
    
    1359
    +the tutoral, or standalone example uses a sample project.
    
    1360
    +
    
    1361
    +Here is the the structure for adding new examples and tutorial chapters.
    
    1273 1362
     
    
    1274 1363
     * The example has a ``${name}``.
    
    1275 1364
     
    
    ... ... @@ -1280,11 +1369,17 @@ examples, here are the criteria for an example addition.
    1280 1369
     * The example has a documentation component.
    
    1281 1370
     
    
    1282 1371
       * This is added at ``doc/source/examples/${name}.rst``
    
    1283
    -  * A reference to ``examples/${name}`` is added to the toctree in ``doc/source/examples.rst``
    
    1372
    +  * An entry for ``examples/${name}`` is added to the toctree in ``doc/source/using_examples.rst``
    
    1284 1373
       * This documentation discusses the project elements declared in the project and may
    
    1285 1374
         provide some BuildStream command examples.
    
    1286 1375
       * This documentation links out to the reference manual at every opportunity.
    
    1287 1376
     
    
    1377
    +  .. note::
    
    1378
    +
    
    1379
    +     In the case of a tutorial chapter, the ``.rst`` file is added in at
    
    1380
    +     ``doc/source/tutorial/${name}.rst`` and an entry for ``tutorial/${name}``
    
    1381
    +     is added to ``doc/source/using_tutorial.rst``.
    
    1382
    +
    
    1288 1383
     * The example has a CI test component.
    
    1289 1384
     
    
    1290 1385
       * This is an integration test added at ``tests/examples/${name}``.
    

  • buildstream/_loader/loader.py
    ... ... @@ -29,6 +29,7 @@ from .. import _yaml
    29 29
     from ..element import Element
    
    30 30
     from .._profile import Topics, profile_start, profile_end
    
    31 31
     from .._includes import Includes
    
    32
    +from .._yamlcache import YamlCache
    
    32 33
     
    
    33 34
     from .types import Symbol, Dependency
    
    34 35
     from .loadelement import LoadElement
    
    ... ... @@ -108,13 +109,19 @@ class Loader():
    108 109
             #
    
    109 110
             deps = []
    
    110 111
     
    
    111
    -        for target in targets:
    
    112
    -            profile_start(Topics.LOAD_PROJECT, target)
    
    113
    -            junction, name, loader = self._parse_name(target, rewritable, ticker,
    
    114
    -                                                      fetch_subprojects=fetch_subprojects)
    
    115
    -            loader._load_file(name, rewritable, ticker, fetch_subprojects)
    
    116
    -            deps.append(Dependency(name, junction=junction))
    
    117
    -            profile_end(Topics.LOAD_PROJECT, target)
    
    112
    +        # XXX This will need to be changed to the context's top-level project if this method
    
    113
    +        # is ever used for subprojects
    
    114
    +        top_dir = self.project.directory
    
    115
    +
    
    116
    +        cache_file = YamlCache.get_cache_file(top_dir)
    
    117
    +        with YamlCache.open(self._context, cache_file) as yaml_cache:
    
    118
    +            for target in targets:
    
    119
    +                profile_start(Topics.LOAD_PROJECT, target)
    
    120
    +                junction, name, loader = self._parse_name(target, rewritable, ticker,
    
    121
    +                                                          fetch_subprojects=fetch_subprojects)
    
    122
    +                loader._load_file(name, rewritable, ticker, fetch_subprojects, yaml_cache)
    
    123
    +                deps.append(Dependency(name, junction=junction))
    
    124
    +                profile_end(Topics.LOAD_PROJECT, target)
    
    118 125
     
    
    119 126
             #
    
    120 127
             # Now that we've resolve the dependencies, scan them for circular dependencies
    
    ... ... @@ -201,11 +208,12 @@ class Loader():
    201 208
         #    rewritable (bool): Whether we should load in round trippable mode
    
    202 209
         #    ticker (callable): A callback to report loaded filenames to the frontend
    
    203 210
         #    fetch_subprojects (bool): Whether to fetch subprojects while loading
    
    211
    +    #    yaml_cache (YamlCache): A yaml cache
    
    204 212
         #
    
    205 213
         # Returns:
    
    206 214
         #    (LoadElement): A loaded LoadElement
    
    207 215
         #
    
    208
    -    def _load_file(self, filename, rewritable, ticker, fetch_subprojects):
    
    216
    +    def _load_file(self, filename, rewritable, ticker, fetch_subprojects, yaml_cache=None):
    
    209 217
     
    
    210 218
             # Silently ignore already loaded files
    
    211 219
             if filename in self._elements:
    
    ... ... @@ -218,7 +226,8 @@ class Loader():
    218 226
             # Load the data and process any conditional statements therein
    
    219 227
             fullpath = os.path.join(self._basedir, filename)
    
    220 228
             try:
    
    221
    -            node = _yaml.load(fullpath, shortname=filename, copy_tree=rewritable, project=self.project)
    
    229
    +            node = _yaml.load(fullpath, shortname=filename, copy_tree=rewritable,
    
    230
    +                              project=self.project, yaml_cache=yaml_cache)
    
    222 231
             except LoadError as e:
    
    223 232
                 if e.reason == LoadErrorReason.MISSING_FILE:
    
    224 233
                     # If we can't find the file, try to suggest plausible
    
    ... ... @@ -261,13 +270,13 @@ class Loader():
    261 270
             # Load all dependency files for the new LoadElement
    
    262 271
             for dep in element.deps:
    
    263 272
                 if dep.junction:
    
    264
    -                self._load_file(dep.junction, rewritable, ticker, fetch_subprojects)
    
    273
    +                self._load_file(dep.junction, rewritable, ticker, fetch_subprojects, yaml_cache)
    
    265 274
                     loader = self._get_loader(dep.junction, rewritable=rewritable, ticker=ticker,
    
    266 275
                                               fetch_subprojects=fetch_subprojects)
    
    267 276
                 else:
    
    268 277
                     loader = self
    
    269 278
     
    
    270
    -            dep_element = loader._load_file(dep.name, rewritable, ticker, fetch_subprojects)
    
    279
    +            dep_element = loader._load_file(dep.name, rewritable, ticker, fetch_subprojects, yaml_cache)
    
    271 280
     
    
    272 281
                 if _yaml.node_get(dep_element.node, str, Symbol.KIND) == 'junction':
    
    273 282
                     raise LoadError(LoadErrorReason.INVALID_DATA,
    

  • buildstream/_yaml.py
    ... ... @@ -183,20 +183,32 @@ class CompositeTypeError(CompositeError):
    183 183
     #    shortname (str): The filename in shorthand for error reporting (or None)
    
    184 184
     #    copy_tree (bool): Whether to make a copy, preserving the original toplevels
    
    185 185
     #                      for later serialization
    
    186
    +#    yaml_cache (YamlCache): A yaml cache to consult rather than parsing
    
    186 187
     #
    
    187 188
     # Returns (dict): A loaded copy of the YAML file with provenance information
    
    188 189
     #
    
    189 190
     # Raises: LoadError
    
    190 191
     #
    
    191
    -def load(filename, shortname=None, copy_tree=False, *, project=None):
    
    192
    +def load(filename, shortname=None, copy_tree=False, *, project=None, yaml_cache=None):
    
    192 193
         if not shortname:
    
    193 194
             shortname = filename
    
    194 195
     
    
    195 196
         file = ProvenanceFile(filename, shortname, project)
    
    196 197
     
    
    197 198
         try:
    
    199
    +        data = None
    
    198 200
             with open(filename) as f:
    
    199
    -            return load_data(f, file, copy_tree=copy_tree)
    
    201
    +            contents = f.read()
    
    202
    +        if yaml_cache:
    
    203
    +            data, key = yaml_cache.get(project, filename, contents, copy_tree)
    
    204
    +
    
    205
    +        if not data:
    
    206
    +            data = load_data(contents, file, copy_tree=copy_tree)
    
    207
    +
    
    208
    +        if yaml_cache:
    
    209
    +            yaml_cache.put_from_key(project, filename, key, data)
    
    210
    +
    
    211
    +        return data
    
    200 212
         except FileNotFoundError as e:
    
    201 213
             raise LoadError(LoadErrorReason.MISSING_FILE,
    
    202 214
                             "Could not find file at {}".format(filename)) from e
    

  • buildstream/_yamlcache.py
    1
    +#
    
    2
    +#  Copyright 2018 Bloomberg Finance LP
    
    3
    +#
    
    4
    +#  This program is free software; you can redistribute it and/or
    
    5
    +#  modify it under the terms of the GNU Lesser General Public
    
    6
    +#  License as published by the Free Software Foundation; either
    
    7
    +#  version 2 of the License, or (at your option) any later version.
    
    8
    +#
    
    9
    +#  This library is distributed in the hope that it will be useful,
    
    10
    +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    11
    +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    
    12
    +#  Lesser General Public License for more details.
    
    13
    +#
    
    14
    +#  You should have received a copy of the GNU Lesser General Public
    
    15
    +#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
    
    16
    +#
    
    17
    +#  Authors:
    
    18
    +#        Jonathan Maw <jonathan maw codethink co uk>
    
    19
    +
    
    20
    +import os
    
    21
    +import pickle
    
    22
    +import hashlib
    
    23
    +import io
    
    24
    +
    
    25
    +import sys
    
    26
    +
    
    27
    +from contextlib import contextmanager
    
    28
    +from collections import namedtuple
    
    29
    +
    
    30
    +from ._cachekey import generate_key
    
    31
    +from ._context import Context
    
    32
    +from . import utils, _yaml
    
    33
    +
    
    34
    +
    
    35
    +YAML_CACHE_FILENAME = "yaml_cache.pickle"
    
    36
    +
    
    37
    +
    
    38
    +# YamlCache()
    
    39
    +#
    
    40
    +# A cache that wraps around the loading of yaml in projects.
    
    41
    +#
    
    42
    +# The recommended way to use a YamlCache is:
    
    43
    +#   with YamlCache.open(context) as yamlcache:
    
    44
    +#     # Load all the yaml
    
    45
    +#     ...
    
    46
    +#
    
    47
    +# Args:
    
    48
    +#    context (Context): The invocation Context
    
    49
    +#
    
    50
    +class YamlCache():
    
    51
    +
    
    52
    +    def __init__(self, context):
    
    53
    +        self._project_caches = {}
    
    54
    +        self._context = context
    
    55
    +
    
    56
    +    ##################
    
    57
    +    # Public Methods #
    
    58
    +    ##################
    
    59
    +
    
    60
    +    # is_cached():
    
    61
    +    #
    
    62
    +    # Checks whether a file is cached.
    
    63
    +    #
    
    64
    +    # Args:
    
    65
    +    #    project (Project): The project this file is in.
    
    66
    +    #    filepath (str): The path to the file, *relative to the project's directory*.
    
    67
    +    #
    
    68
    +    # Returns:
    
    69
    +    #    (bool): Whether the file is cached.
    
    70
    +    def is_cached(self, project, filepath):
    
    71
    +        cache_path = self._get_filepath(project, filepath)
    
    72
    +        project_name = project.name if project else ""
    
    73
    +        try:
    
    74
    +            project_cache = self._project_caches[project_name]
    
    75
    +            if cache_path in project_cache.elements:
    
    76
    +                return True
    
    77
    +        except KeyError:
    
    78
    +            pass
    
    79
    +        return False
    
    80
    +
    
    81
    +    # open():
    
    82
    +    #
    
    83
    +    # Return an instance of the YamlCache which writes to disk when it leaves scope.
    
    84
    +    #
    
    85
    +    # Args:
    
    86
    +    #    context (Context): The context.
    
    87
    +    #    cachefile (str): The path to the cache file.
    
    88
    +    #
    
    89
    +    # Returns:
    
    90
    +    #    (YamlCache): A YamlCache.
    
    91
    +    @staticmethod
    
    92
    +    @contextmanager
    
    93
    +    def open(context, cachefile):
    
    94
    +        # Try to load from disk first
    
    95
    +        cache = None
    
    96
    +        if os.path.exists(cachefile):
    
    97
    +            try:
    
    98
    +                with open(cachefile, "rb") as f:
    
    99
    +                    cache = BstUnpickler(f, context).load()
    
    100
    +            except EOFError:
    
    101
    +                # The file was empty
    
    102
    +                pass
    
    103
    +            except pickle.UnpicklingError as e:
    
    104
    +                sys.stderr.write("Failed to load YamlCache, {}\n".format(e))
    
    105
    +
    
    106
    +        # Failed to load from disk, create a new one
    
    107
    +        if not cache:
    
    108
    +            cache = YamlCache(context)
    
    109
    +
    
    110
    +        yield cache
    
    111
    +
    
    112
    +        cache._write(cachefile)
    
    113
    +
    
    114
    +    # get_cache_file():
    
    115
    +    #
    
    116
    +    # Retrieves a path to the yaml cache file.
    
    117
    +    #
    
    118
    +    # Returns:
    
    119
    +    #   (str): The path to the cache file
    
    120
    +    @staticmethod
    
    121
    +    def get_cache_file(top_dir):
    
    122
    +        return os.path.join(top_dir, ".bst", YAML_CACHE_FILENAME)
    
    123
    +
    
    124
    +    # get():
    
    125
    +    #
    
    126
    +    # Gets a parsed file from the cache.
    
    127
    +    #
    
    128
    +    # Args:
    
    129
    +    #    project (Project) or None: The project this file is in, if it exists.
    
    130
    +    #    filepath (str): The absolute path to the file.
    
    131
    +    #    contents (str): The contents of the file to be cached
    
    132
    +    #    copy_tree (bool): Whether the data should make a copy when it's being generated
    
    133
    +    #                      (i.e. exactly as when called in yaml)
    
    134
    +    #
    
    135
    +    # Returns:
    
    136
    +    #    (decorated dict): The parsed yaml from the cache, or None if the file isn't in the cache.
    
    137
    +    #    (str):            The key used to look up the parsed yaml in the cache
    
    138
    +    def get(self, project, filepath, contents, copy_tree):
    
    139
    +        key = self._calculate_key(contents, copy_tree)
    
    140
    +        data = self._get(project, filepath, key)
    
    141
    +        return data, key
    
    142
    +
    
    143
    +    # put():
    
    144
    +    #
    
    145
    +    # Puts a parsed file into the cache.
    
    146
    +    #
    
    147
    +    # Args:
    
    148
    +    #    project (Project): The project this file is in.
    
    149
    +    #    filepath (str): The path to the file.
    
    150
    +    #    contents (str): The contents of the file that has been cached
    
    151
    +    #    copy_tree (bool): Whether the data should make a copy when it's being generated
    
    152
    +    #                      (i.e. exactly as when called in yaml)
    
    153
    +    #    value (decorated dict): The data to put into the cache.
    
    154
    +    def put(self, project, filepath, contents, copy_tree, value):
    
    155
    +        key = self._calculate_key(contents, copy_tree)
    
    156
    +        self.put_from_key(project, filepath, key, value)
    
    157
    +
    
    158
    +    # put_from_key():
    
    159
    +    #
    
    160
    +    # Put a parsed file into the cache when given a key.
    
    161
    +    #
    
    162
    +    # Args:
    
    163
    +    #    project (Project): The project this file is in.
    
    164
    +    #    filepath (str): The path to the file.
    
    165
    +    #    key (str): The key to the file within the cache. Typically, this is the
    
    166
    +    #               value of `calculate_key()` with the file's unparsed contents
    
    167
    +    #               and any relevant metadata passed in.
    
    168
    +    #    value (decorated dict): The data to put into the cache.
    
    169
    +    def put_from_key(self, project, filepath, key, value):
    
    170
    +        cache_path = self._get_filepath(project, filepath)
    
    171
    +        project_name = project.name if project else ""
    
    172
    +        try:
    
    173
    +            project_cache = self._project_caches[project_name]
    
    174
    +        except KeyError:
    
    175
    +            project_cache = self._project_caches[project_name] = CachedProject({})
    
    176
    +
    
    177
    +        project_cache.elements[cache_path] = CachedYaml(key, value)
    
    178
    +
    
    179
    +    ###################
    
    180
    +    # Private Methods #
    
    181
    +    ###################
    
    182
    +
    
    183
    +    # Writes the yaml cache to the specified path.
    
    184
    +    #
    
    185
    +    # Args:
    
    186
    +    #    path (str): The path to the cache file.
    
    187
    +    def _write(self, path):
    
    188
    +        parent_dir = os.path.dirname(path)
    
    189
    +        os.makedirs(parent_dir, exist_ok=True)
    
    190
    +        with open(path, "wb") as f:
    
    191
    +            BstPickler(f).dump(self)
    
    192
    +
    
    193
    +    # _get_filepath():
    
    194
    +    #
    
    195
    +    # Returns a file path relative to a project if passed, or the original path if
    
    196
    +    # the project is None
    
    197
    +    #
    
    198
    +    # Args:
    
    199
    +    #    project (Project) or None: The project the filepath exists within
    
    200
    +    #    full_path (str): The path that the returned path is based on
    
    201
    +    #
    
    202
    +    # Returns:
    
    203
    +    #    (str): The path to the file, relative to a project if it exists
    
    204
    +    def _get_filepath(self, project, full_path):
    
    205
    +        if project:
    
    206
    +            assert full_path.startswith(project.directory)
    
    207
    +            filepath = os.path.relpath(full_path, project.directory)
    
    208
    +        else:
    
    209
    +            filepath = full_path
    
    210
    +        return full_path
    
    211
    +
    
    212
    +    # _calculate_key():
    
    213
    +    #
    
    214
    +    # Calculates a key for putting into the cache.
    
    215
    +    #
    
    216
    +    # Args:
    
    217
    +    #    (basic object)... : Any number of strictly-ordered basic objects
    
    218
    +    #
    
    219
    +    # Returns:
    
    220
    +    #   (str): A key made out of every arg passed in
    
    221
    +    @staticmethod
    
    222
    +    def _calculate_key(*args):
    
    223
    +        string = pickle.dumps(args)
    
    224
    +        return hashlib.sha1(string).hexdigest()
    
    225
    +
    
    226
    +    # _get():
    
    227
    +    #
    
    228
    +    # Gets a parsed file from the cache when given a key.
    
    229
    +    #
    
    230
    +    # Args:
    
    231
    +    #    project (Project): The project this file is in.
    
    232
    +    #    filepath (str): The path to the file.
    
    233
    +    #    key (str): The key to the file within the cache. Typically, this is the
    
    234
    +    #               value of `calculate_key()` with the file's unparsed contents
    
    235
    +    #               and any relevant metadata passed in.
    
    236
    +    #
    
    237
    +    # Returns:
    
    238
    +    #    (decorated dict): The parsed yaml from the cache, or None if the file isn't in the cache.
    
    239
    +    def _get(self, project, filepath, key):
    
    240
    +        cache_path = self._get_filepath(project, filepath)
    
    241
    +        project_name = project.name if project else ""
    
    242
    +        try:
    
    243
    +            project_cache = self._project_caches[project_name]
    
    244
    +            try:
    
    245
    +                cachedyaml = project_cache.elements[cache_path]
    
    246
    +                if cachedyaml._key == key:
    
    247
    +                    # We've unpickled the YamlCache, but not the specific file
    
    248
    +                    if cachedyaml._contents is None:
    
    249
    +                        cachedyaml._contents = BstUnpickler.loads(cachedyaml._pickled_contents, self._context)
    
    250
    +                    return cachedyaml._contents
    
    251
    +            except KeyError:
    
    252
    +                pass
    
    253
    +        except KeyError:
    
    254
    +            pass
    
    255
    +        return None
    
    256
    +
    
    257
    +
    
    258
    +CachedProject = namedtuple('CachedProject', ['elements'])
    
    259
    +
    
    260
    +
    
    261
    +class CachedYaml():
    
    262
    +    def __init__(self, key, contents):
    
    263
    +        self._key = key
    
    264
    +        self.set_contents(contents)
    
    265
    +
    
    266
    +    # Sets the contents of the CachedYaml.
    
    267
    +    #
    
    268
    +    # Args:
    
    269
    +    #    contents (provenanced dict): The contents to put in the cache.
    
    270
    +    #
    
    271
    +    def set_contents(self, contents):
    
    272
    +        self._contents = contents
    
    273
    +        self._pickled_contents = BstPickler.dumps(contents)
    
    274
    +
    
    275
    +    # Pickling helper method, prevents 'contents' from being serialised
    
    276
    +    def __getstate__(self):
    
    277
    +        data = self.__dict__.copy()
    
    278
    +        data['_contents'] = None
    
    279
    +        return data
    
    280
    +
    
    281
    +
    
    282
    +# In _yaml.load, we have a ProvenanceFile that stores the project the file
    
    283
    +# came from. Projects can't be pickled, but it's always going to be the same
    
    284
    +# project between invocations (unless the entire project is moved but the
    
    285
    +# file stayed in the same place)
    
    286
    +class BstPickler(pickle.Pickler):
    
    287
    +    def persistent_id(self, obj):
    
    288
    +        if isinstance(obj, _yaml.ProvenanceFile):
    
    289
    +            if obj.project:
    
    290
    +                # ProvenanceFile's project object cannot be stored as it is.
    
    291
    +                project_tag = obj.project.name
    
    292
    +                # ProvenanceFile's filename must be stored relative to the
    
    293
    +                # project, as the project dir may move.
    
    294
    +                name = os.path.relpath(obj.name, obj.project.directory)
    
    295
    +            else:
    
    296
    +                project_tag = None
    
    297
    +                name = obj.name
    
    298
    +            return ("ProvenanceFile", name, obj.shortname, project_tag)
    
    299
    +        elif isinstance(obj, Context):
    
    300
    +            return ("Context",)
    
    301
    +        else:
    
    302
    +            return None
    
    303
    +
    
    304
    +    @staticmethod
    
    305
    +    def dumps(obj):
    
    306
    +        stream = io.BytesIO()
    
    307
    +        BstPickler(stream).dump(obj)
    
    308
    +        stream.seek(0)
    
    309
    +        return stream.read()
    
    310
    +
    
    311
    +
    
    312
    +class BstUnpickler(pickle.Unpickler):
    
    313
    +    def __init__(self, file, context):
    
    314
    +        super().__init__(file)
    
    315
    +        self._context = context
    
    316
    +
    
    317
    +    def persistent_load(self, pid):
    
    318
    +        if pid[0] == "ProvenanceFile":
    
    319
    +            _, tagged_name, shortname, project_tag = pid
    
    320
    +
    
    321
    +            if project_tag is not None:
    
    322
    +                for p in self._context.get_projects():
    
    323
    +                    if project_tag == p.name:
    
    324
    +                        project = p
    
    325
    +                        break
    
    326
    +
    
    327
    +                name = os.path.join(project.directory, tagged_name)
    
    328
    +
    
    329
    +                if not project:
    
    330
    +                    projects = [p.name for p in self._context.get_projects()]
    
    331
    +                    raise pickle.UnpicklingError("No project with name {} found in {}"
    
    332
    +                                                 .format(key_id, projects))
    
    333
    +            else:
    
    334
    +                project = None
    
    335
    +                name = tagged_name
    
    336
    +
    
    337
    +            return _yaml.ProvenanceFile(name, shortname, project)
    
    338
    +        elif pid[0] == "Context":
    
    339
    +            return self._context
    
    340
    +        else:
    
    341
    +            raise pickle.UnpicklingError("Unsupported persistent object, {}".format(pid))
    
    342
    +
    
    343
    +    @staticmethod
    
    344
    +    def loads(text, context):
    
    345
    +        stream = io.BytesIO()
    
    346
    +        stream.write(bytes(text))
    
    347
    +        stream.seek(0)
    
    348
    +        return BstUnpickler(stream, context).load()

  • doc/source/additional_docker.rst
    ... ... @@ -4,19 +4,18 @@
    4 4
     
    
    5 5
     BuildStream and Docker
    
    6 6
     ======================
    
    7
    -
    
    8 7
     BuildStream integrates with Docker in multiple ways. Here are some ways in
    
    9 8
     which these integrations work.
    
    10 9
     
    
    10
    +
    
    11 11
     Run BuildStream inside Docker
    
    12 12
     -----------------------------
    
    13
    +Refer to the `BuildStream inside Docker <https://buildstream.build/docker_install.html>`_
    
    14
    +documentation for instructions on how to run BuildStream as a Docker container.
    
    13 15
     
    
    14
    -Refer to the :ref:`BuildStream inside Docker <docker>` documentation for
    
    15
    -instructions on how to run BuildStream as a Docker container.
    
    16 16
     
    
    17 17
     Generate Docker images
    
    18 18
     ----------------------
    
    19
    -
    
    20 19
     The
    
    21 20
     `bst-docker-import script <https://gitlab.com/BuildStream/buildstream/blob/master/contrib/bst-docker-import>`_
    
    22 21
     can be used to generate a Docker image from built artifacts.
    

  • doc/source/index.rst
    ... ... @@ -13,20 +13,13 @@ They begin with a basic introduction to BuildStream, background
    13 13
     information on basic concepts, and a guide to the BuildStream command line interface.
    
    14 14
     Later sections provide detailed information on BuildStream internals.
    
    15 15
     
    
    16
    -
    
    17 16
     .. toctree::
    
    18 17
        :maxdepth: 1
    
    19 18
     
    
    20 19
        main_about
    
    21
    -   main_install
    
    22 20
        main_using
    
    23 21
        main_core
    
    24 22
        CONTRIBUTING
    
    25 23
     
    
    26
    -
    
    27
    -Resources
    
    28
    ----------
    
    29
    -* GitLab repository: https://gitlab.com/BuildStream/buildstream
    
    30
    -* Bug Tracking: https://gitlab.com/BuildStream/buildstream/issues
    
    31
    -* Mailing list: https://mail.gnome.org/mailman/listinfo/buildstream-list
    
    32
    -* IRC Channel: irc://irc.gnome.org/#buildstream
    24
    +For any other information, including `how to install BuildStream <https://buildstream.build/install.html>`_,
    
    25
    +refer to `the BuildStream website <https://buildstream.build>`_.

  • doc/source/install_docker.rst deleted
    1
    -
    
    2
    -
    
    3
    -.. _docker:
    
    4
    -
    
    5
    -BuildStream inside Docker
    
    6
    --------------------------
    
    7
    -If your system cannot provide the base system requirements for BuildStream, then it is possible to run buildstream within a Docker image.
    
    8
    -
    
    9
    -The BuildStream project provides
    
    10
    -`Docker images <https://hub.docker.com/r/buildstream/buildstream-fedora>`_
    
    11
    -containing BuildStream and its dependencies.
    
    12
    -This gives you an easy way to get started using BuildStream on any Unix-like
    
    13
    -platform where Docker is available, including Mac OS X.
    
    14
    -
    
    15
    -We recommend using the
    
    16
    -`bst-here wrapper script <https://gitlab.com/BuildStream/buildstream/blob/master/contrib/bst-here>`_
    
    17
    -which automates the necessary container setup. You can download it and make
    
    18
    -it executable like this:
    
    19
    -
    
    20
    -.. code:: bash
    
    21
    -
    
    22
    -  mkdir -p ~/.local/bin
    
    23
    -  curl --get https://gitlab.com/BuildStream/buildstream/raw/master/contrib/bst-here > ~/.local/bin/bst-here
    
    24
    -  chmod +x ~/.local/bin/bst-here
    
    25
    -
    
    26
    -Check if ``~/.local/bin`` appears in your PATH environment variable -- if it
    
    27
    -doesn't, you should
    
    28
    -`edit your ~/.profile so that it does <https://stackoverflow.com/questions/14637979/>`_.
    
    29
    -
    
    30
    -Once the script is available in your PATH, you can run ``bst-here`` to open a
    
    31
    -shell session inside a new container based off the latest version of the
    
    32
    -buildstream-fedora Docker image. The current working directory will be mounted
    
    33
    -inside the container at ``/src``.
    
    34
    -
    
    35
    -You can also run individual BuildStream commands as ``bst-here COMMAND``. For
    
    36
    -example: ``bst-here show systems/my-system.bst``. Note that BuildStream won't
    
    37
    -be able to integrate with Bash tab-completion if you invoke it in this way.
    
    38
    -
    
    39
    -Two Docker volumes are set up by the ``bst-here`` script:
    
    40
    -
    
    41
    - * ``buildstream-cache --`` mounted at ``~/.cache/buildstream``
    
    42
    - * ``buildstream-config --`` mounted at ``~/.config/``
    
    43
    -
    
    44
    -These are necessary so that your BuildStream cache and configuration files
    
    45
    -persist between invocations of ``bst-here``.

  • doc/source/install_linux_distro.rst deleted
    1
    -
    
    2
    -
    
    3
    -.. _install_linux_distro:
    
    4
    -
    
    5
    -Installing from distro packages
    
    6
    -===============================
    
    7
    -BuildStream is available on some linux distributions, here are
    
    8
    -some install instructions for the linux distributions which
    
    9
    -have packaged BuildStream.
    
    10
    -
    
    11
    -
    
    12
    -Arch Linux
    
    13
    -----------
    
    14
    -Packages for Arch exist in `AUR <https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages>`_.
    
    15
    -Two different package versions are available:
    
    16
    -
    
    17
    -* Latest release: `buildstream <https://aur.archlinux.org/packages/buildstream>`_
    
    18
    -* Latest development snapshot: `buildstream-git <https://aur.archlinux.org/packages/buildstream-git>`_
    
    19
    -
    
    20
    -
    
    21
    -Fedora
    
    22
    -------
    
    23
    -BuildStream is not yet in the official Fedora repositories, but you can
    
    24
    -install it from a Copr::
    
    25
    -
    
    26
    -  sudo dnf copr enable bochecha/buildstream
    
    27
    -  sudo dnf install buildstream
    
    28
    -
    
    29
    -Optionally, install the ``buildstream-docs`` package to have the BuildStream
    
    30
    -documentation in Devhelp or GNOME Builder.

  • doc/source/install_source.rst deleted
    1
    -
    
    2
    -
    
    3
    -Installing from source
    
    4
    -======================
    
    5
    -Until BuildStream is available in :ref:`your distro <install_linux_distro>`, you will
    
    6
    -need to install it yourself from source.
    
    7
    -
    
    8
    -
    
    9
    -Installing dependencies
    
    10
    ------------------------
    
    11
    -Before installing BuildStream from source, it is necessary to first install
    
    12
    -the system dependencies. Below are some linux distribution specific instructions
    
    13
    -for installing these dependencies.
    
    14
    -
    
    15
    -BuildStream requires the following base system requirements:
    
    16
    -
    
    17
    -* python3 >= 3.5
    
    18
    -* bubblewrap >= 0.1.2
    
    19
    -* fuse2
    
    20
    -
    
    21
    -BuildStream also depends on the host tools for the :mod:`Source <buildstream.source>` plugins.
    
    22
    -Refer to the respective :ref:`source plugin <plugins_sources>` documentation for host tool
    
    23
    -requirements of specific plugins.
    
    24
    -
    
    25
    -The default plugins with extra host dependencies are:
    
    26
    -
    
    27
    -* bzr
    
    28
    -* deb
    
    29
    -* git
    
    30
    -* ostree
    
    31
    -* patch
    
    32
    -* pip
    
    33
    -* tar
    
    34
    -
    
    35
    -If you intend to push built artifacts to a remote artifact server,
    
    36
    -which requires special permissions, you will also need:
    
    37
    -
    
    38
    -* ssh
    
    39
    -
    
    40
    -
    
    41
    -Arch Linux
    
    42
    -~~~~~~~~~~
    
    43
    -Install the dependencies with::
    
    44
    -
    
    45
    -  sudo pacman -S \
    
    46
    -      python fuse2 bubblewrap \
    
    47
    -      python-pip
    
    48
    -
    
    49
    -For the default plugins::
    
    50
    -
    
    51
    -  sudo pacman -S \
    
    52
    -      bzr git lzip ostree patch python-gobject
    
    53
    -
    
    54
    -
    
    55
    -The package *python-arpy* is required by the deb source plugin. This is not
    
    56
    -obtainable via `pacman`, you must get *python-arpy* from AUR:
    
    57
    -https://aur.archlinux.org/packages/python-arpy/
    
    58
    -
    
    59
    -To install::
    
    60
    -
    
    61
    -  wget https://aur.archlinux.org/cgit/aur.git/snapshot/python-arpy.tar.gz
    
    62
    -  tar -xvf python-arpy.tar.gz
    
    63
    -  cd python-arpy
    
    64
    -  makepkg -si
    
    65
    -
    
    66
    -
    
    67
    -Debian
    
    68
    -~~~~~~
    
    69
    -Install the dependencies with::
    
    70
    -
    
    71
    -  sudo apt-get install \
    
    72
    -      python3 fuse bubblewrap \
    
    73
    -      python3-pip python3-dev
    
    74
    -
    
    75
    -For the default plugins:
    
    76
    -
    
    77
    -
    
    78
    -Stretch
    
    79
    -+++++++
    
    80
    -With stretch, you first need to ensure that you have the backports repository
    
    81
    -setup as described `here <https://backports.debian.org/Instructions/>`_
    
    82
    -
    
    83
    -By adding the following line to your sources.list::
    
    84
    -
    
    85
    -  deb http://deb.debian.org/debian stretch-backports main
    
    86
    -
    
    87
    -And then running::
    
    88
    -
    
    89
    -  sudo apt update
    
    90
    -
    
    91
    -At this point you should be able to get the system requirements for the default plugins with::
    
    92
    -
    
    93
    -  sudo apt install \
    
    94
    -      bzr git lzip patch python3-arpy python3-gi
    
    95
    -  sudo apt install -t stretch-backports \
    
    96
    -      gir1.2-ostree-1.0 ostree
    
    97
    -
    
    98
    -
    
    99
    -Buster or Sid
    
    100
    -+++++++++++++
    
    101
    -For debian unstable or testing, only the following line should be enough
    
    102
    -to get the system requirements for the default plugins installed::
    
    103
    -
    
    104
    -  sudo apt-get install \
    
    105
    -      lzip gir1.2-ostree-1.0 git bzr ostree patch python3-arpy python3-gi
    
    106
    -
    
    107
    -
    
    108
    -Fedora
    
    109
    -~~~~~~
    
    110
    -For recent fedora systems, the following line should get you the system
    
    111
    -requirements you need::
    
    112
    -
    
    113
    -  dnf install -y \
    
    114
    -      python3 fuse bubblewrap \
    
    115
    -      python3-pip python3-devel
    
    116
    -
    
    117
    -For the default plugins::
    
    118
    -
    
    119
    -  dnf install -y \
    
    120
    -      bzr git lzip patch ostree python3-gobject
    
    121
    -  pip3 install --user arpy
    
    122
    -
    
    123
    -
    
    124
    -Ubuntu
    
    125
    -~~~~~~
    
    126
    -
    
    127
    -
    
    128
    -Ubuntu 18.04 LTS or later
    
    129
    -+++++++++++++++++++++++++
    
    130
    -Install the dependencies with::
    
    131
    -
    
    132
    -  sudo apt install \
    
    133
    -      python3 fuse bubblewrap \
    
    134
    -      python3-pip python3-dev
    
    135
    -
    
    136
    -For the default plugins::
    
    137
    -
    
    138
    -  sudo apt install \
    
    139
    -      bzr gir1.2-ostree-1.0 git lzip ostree patch python3-arpy python3-gi
    
    140
    -
    
    141
    -
    
    142
    -Ubuntu 16.04 LTS
    
    143
    -++++++++++++++++
    
    144
    -On Ubuntu 16.04, neither `bubblewrap <https://github.com/projectatomic/bubblewrap/>`_
    
    145
    -or `ostree <https://github.com/ostreedev/ostree>`_ are available in the official repositories.
    
    146
    -You will need to install them in whichever way you see fit. Refer the the upstream documentation
    
    147
    -for advice on this.
    
    148
    -
    
    149
    -
    
    150
    -Installing
    
    151
    -----------
    
    152
    -Once you have the base system dependencies, you can install the BuildStream
    
    153
    -python package as a regular user.
    
    154
    -
    
    155
    -
    
    156
    -Installing from PyPI (recommended)
    
    157
    -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    158
    -Since we only ever publish :ref:`release versions <install_semantic_versioning>` on
    
    159
    -PyPI, it is currently recommended to use this installation path. This will
    
    160
    -ensure that you always have the latest recommended version of BuildStream that
    
    161
    -we recommend.
    
    162
    -
    
    163
    -To install from PyPI, you will additionally require:
    
    164
    -
    
    165
    -* pip for python3 (only required for setup)
    
    166
    -* Python 3 development libraries and headers
    
    167
    -
    
    168
    -Simply run the following command::
    
    169
    -
    
    170
    -  pip3 install --user BuildStream
    
    171
    -
    
    172
    -This will install latest stable version of BuildStream and its pure python
    
    173
    -dependencies into your user's homedir in ``~/.local``.
    
    174
    -
    
    175
    -Keep following the instructions below to ensure that the ``bst``
    
    176
    -command is in your ``PATH`` and to enable bash completions for it.
    
    177
    -
    
    178
    -.. note::
    
    179
    -
    
    180
    -  If you want a specific version of BuildStream, you can install it using
    
    181
    -  ``pip install --user BuildStream==<version-number>``
    
    182
    -
    
    183
    -
    
    184
    -Upgrading from PyPI
    
    185
    -+++++++++++++++++++
    
    186
    -Once you have already installed BuildStream from PyPI, you can later update
    
    187
    -to the latest recommended version like so::
    
    188
    -
    
    189
    -  pip install --user --upgrade BuildStream
    
    190
    -
    
    191
    -
    
    192
    -.. _install_git_checkout:
    
    193
    -
    
    194
    -Installing from a git checkout
    
    195
    -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    196
    -To install directly from the `git repository <https://gitlab.com/BuildStream/buildstream.git>`_
    
    197
    -using python's ``pip`` package manager, you will additionally require:
    
    198
    -
    
    199
    -* pip for python3 (only required for setup)
    
    200
    -* Python 3 development libraries and headers
    
    201
    -* git (to checkout BuildStream)
    
    202
    -
    
    203
    -Before installing, please check the existing tags in the git repository
    
    204
    -and determine which version you want to install, and whether you want
    
    205
    -to install an official release version (recommended), or a development snapshot
    
    206
    -to help us out testing the bleeding edge of development. Follow the
    
    207
    -:ref:`semantic versioning guide <install_semantic_versioning>` to determine
    
    208
    -which tag you intend to install.
    
    209
    -
    
    210
    -Run the following commands::
    
    211
    -
    
    212
    -  git clone https://gitlab.com/BuildStream/buildstream.git
    
    213
    -  cd buildstream
    
    214
    -  git checkout <desired release tag>
    
    215
    -  pip3 install --user -e .
    
    216
    -
    
    217
    -This will install buildstream's pure python dependencies into
    
    218
    -your user's homedir in ``~/.local`` and will run BuildStream directly
    
    219
    -from the git checkout directory.
    
    220
    -
    
    221
    -Keep following the instructions below to ensure that the ``bst``
    
    222
    -command is in your ``PATH`` and to enable bash completions for it.
    
    223
    -
    
    224
    -.. note::
    
    225
    -
    
    226
    -   We recommend the ``-e`` option because you can upgrade your
    
    227
    -   installation by simply updating the checked out git repository.
    
    228
    -
    
    229
    -   If you want a full installation that is not linked to your
    
    230
    -   git checkout, just omit the ``-e`` option from the above commands.
    
    231
    -
    
    232
    -
    
    233
    -Upgrading from a git checkout
    
    234
    -+++++++++++++++++++++++++++++
    
    235
    -If you installed BuildStream from a local git checkout using ``-e`` option, all
    
    236
    -you need to do to upgrade BuildStream is to update your local git checkout::
    
    237
    -
    
    238
    -  cd /path/to/buildstream
    
    239
    -  git pull --rebase
    
    240
    -
    
    241
    -If you did not specify the ``-e`` option at install time or the dependancies
    
    242
    -have changed, you will need to cleanly reinstall BuildStream::
    
    243
    -
    
    244
    -  pip3 uninstall buildstream
    
    245
    -  cd /path/to/buildstream
    
    246
    -  git pull --rebase
    
    247
    -  pip3 install --user .
    
    248
    -
    
    249
    -.. note::
    
    250
    -
    
    251
    -   If BuildStream has added any dependencies since the last upgrade,
    
    252
    -   you will need to uninstall and reinstall to ensure those dependencies
    
    253
    -   are met, regardless of whether you have used the ``-e`` option at
    
    254
    -   install time.
    
    255
    -
    
    256
    -
    
    257
    -Post install setup
    
    258
    -------------------
    
    259
    -After having installed from source using any of the above methods, some
    
    260
    -setup will be required to use BuildStream.
    
    261
    -
    
    262
    -
    
    263
    -Adjust PATH
    
    264
    -~~~~~~~~~~~
    
    265
    -Since BuildStream is now installed under your local user's install directories,
    
    266
    -you need to ensure that ``PATH`` is adjusted.
    
    267
    -
    
    268
    -A regular way to do this is to add the following line to the end of your ``~/.bashrc``::
    
    269
    -
    
    270
    -  export PATH="${PATH}:${HOME}/.local/bin"
    
    271
    -
    
    272
    -.. note::
    
    273
    -
    
    274
    -   You will have to restart your terminal in order for these changes to take effect.
    
    275
    -
    
    276
    -
    
    277
    -Bash completions
    
    278
    -~~~~~~~~~~~~~~~~
    
    279
    -Bash completions are supported by sourcing the ``buildstream/data/bst``
    
    280
    -script found in the BuildStream repository. On many systems this script
    
    281
    -can be installed into a completions directory but when installing BuildStream
    
    282
    -without a package manager this is not an option.
    
    283
    -
    
    284
    -To enable completions for an installation of BuildStream you
    
    285
    -installed yourself from git, just append the script verbatim
    
    286
    -to your ``~/.bash_completion``:
    
    287
    -
    
    288
    -.. literalinclude:: ../../buildstream/data/bst
    
    289
    -   :language: yaml

  • doc/source/install_versions.rst deleted
    1
    -
    
    2
    -
    
    3
    -.. _install_semantic_versioning:
    
    4
    -
    
    5
    -Semantic Versioning
    
    6
    -===================
    
    7
    -BuildStream follows the Semantic Versioning Convention `(SemVer) <https://semver.org/>`_,
    
    8
    -and uses even minor point numbers to denote releases intended for users while
    
    9
    -odd minor point numbers represent development snapshops.
    
    10
    -
    
    11
    -For example, for a given version number ``X.Y.Z``
    
    12
    - * The ``X.<even number>.*`` versions are releases intended for users.
    
    13
    - * The ``X.<odd number>.*`` versions are development spanshots intended for testing.
    
    14
    -
    
    15
    -If you are :ref:`installing from git <install_git_checkout>`, please look for the latest
    
    16
    -tag to ensure you're getting the latest release.
    
    17
    -
    
    18
    -* Latest release:
    
    19
    -
    
    20
    -  .. include:: release-badge.rst
    
    21
    -
    
    22
    -* Latest development snapshot:
    
    23
    -
    
    24
    -  .. include:: snapshot-badge.rst

  • doc/source/main_install.rst deleted
    1
    -
    
    2
    -
    
    3
    -.. _install:
    
    4
    -
    
    5
    -Install
    
    6
    -=======
    
    7
    -
    
    8
    -.. include:: release-badge.rst
    
    9
    -
    
    10
    -.. include:: snapshot-badge.rst
    
    11
    -
    
    12
    -This section provides instructions for installing BuildStream and its
    
    13
    -companion artifact server on various platforms, along with any installation
    
    14
    -related materials.
    
    15
    -
    
    16
    -.. note::
    
    17
    -
    
    18
    -   BuildStream is currently only supported natively on Linux. Users of Unix-like
    
    19
    -   systems where Docker is available can still use BuildStream by following the
    
    20
    -   :ref:`Docker install guide <docker>`
    
    21
    -
    
    22
    -.. toctree::
    
    23
    -   :maxdepth: 1
    
    24
    -
    
    25
    -   install_source
    
    26
    -   install_linux_distro
    
    27
    -   install_docker
    
    28
    -   install_artifacts
    
    29
    -   install_versions

  • doc/source/main_using.rst
    1 1
     
    
    2 2
     
    
    3
    +.. _using:
    
    4
    +
    
    3 5
     Using
    
    4 6
     =====
    
    5 7
     This section includes user facing documentation including tutorials,
    
    ... ... @@ -15,3 +17,4 @@ guides and information on user preferences and configuration.
    15 17
        using_examples
    
    16 18
        using_config
    
    17 19
        using_commands
    
    20
    +   using_configuring_artifact_server

  • doc/source/release-badge.rst deleted
    1
    -
    
    2
    -.. Use this file to include the badge in the documentation, but not in
    
    3
    -   the README.rst or gitlab rendered materials, that doesnt work.
    
    4
    -
    
    5
    -   This is partly a workaround for a sphinx issue, we will be able
    
    6
    -   to avoid the raw html once this is implemented in sphinx:
    
    7
    -
    
    8
    -       https://github.com/sphinx-doc/sphinx/issues/2240
    
    9
    -
    
    10
    -   Using the <object> tag instead of the <img> tag which sphinx generates
    
    11
    -   allows the svg to be "interactive", for us this basically means that
    
    12
    -   the link we encode in the badge svg is used, rather than static urls
    
    13
    -   which need to be used around the <img> tag.
    
    14
    -
    
    15
    -   WARNING: The custom CSS on the style tag will need to change if we
    
    16
    -            change the theme, so that the <object> tag behaves similar
    
    17
    -	    to how the <img> tag is themed by the style sheets.
    
    18
    -
    
    19
    -.. raw:: html
    
    20
    -
    
    21
    -   <a class="reference external image-reference">
    
    22
    -     <object style="margin-bottom:24px;vertical-align:middle"
    
    23
    -             data=""
    
    24
    -	     type="image/svg+xml"/>
    
    25
    -     </object>
    
    26
    -   </a>

  • doc/source/snapshot-badge.rst deleted
    1
    -
    
    2
    -.. Use this file to include the badge in the documentation, but not in
    
    3
    -   the README.rst or gitlab rendered materials, that doesnt work.
    
    4
    -
    
    5
    -   This is partly a workaround for a sphinx issue, we will be able
    
    6
    -   to avoid the raw html once this is implemented in sphinx:
    
    7
    -
    
    8
    -       https://github.com/sphinx-doc/sphinx/issues/2240
    
    9
    -
    
    10
    -   Using the <object> tag instead of the <img> tag which sphinx generates
    
    11
    -   allows the svg to be "interactive", for us this basically means that
    
    12
    -   the link we encode in the badge svg is used, rather than static urls
    
    13
    -   which need to be used around the <img> tag.
    
    14
    -
    
    15
    -   WARNING: The custom CSS on the style tag will need to change if we
    
    16
    -            change the theme, so that the <object> tag behaves similar
    
    17
    -	    to how the <img> tag is themed by the style sheets.
    
    18
    -
    
    19
    -.. raw:: html
    
    20
    -
    
    21
    -   <a class="reference external image-reference">
    
    22
    -     <object style="margin-bottom:24px;vertical-align:middle"
    
    23
    -             data=""
    
    24
    -	     type="image/svg+xml"/>
    
    25
    -     </object>
    
    26
    -   </a>

  • doc/source/install_artifacts.rstdoc/source/using_configuring_artifact_server.rst
    ... ... @@ -2,8 +2,8 @@
    2 2
     
    
    3 3
     .. _artifacts:
    
    4 4
     
    
    5
    -Installing an artifact server
    
    6
    -=============================
    
    5
    +Configuring Artifact Server
    
    6
    +===========================
    
    7 7
     BuildStream caches the results of builds in a local artifact cache, and will
    
    8 8
     avoid building an element if there is a suitable build already present in the
    
    9 9
     local artifact cache.
    
    ... ... @@ -72,7 +72,7 @@ Installing the server
    72 72
     ~~~~~~~~~~~~~~~~~~~~~
    
    73 73
     You will also need to install BuildStream on the artifact server in order
    
    74 74
     to receive uploaded artifacts over ssh. Follow the instructions for installing
    
    75
    -BuildStream :ref:`here <install>`
    
    75
    +BuildStream `here <https://buildstream.build/install.html>`_.
    
    76 76
     
    
    77 77
     When installing BuildStream on the artifact server, it must be installed
    
    78 78
     in a system wide location, with ``pip3 install .`` in the BuildStream
    

  • doc/source/using_examples.rst
    1 1
     
    
    2
    +
    
    3
    +.. _examples:
    
    4
    +
    
    2 5
     Examples
    
    3 6
     ========
    
    4 7
     This page contains documentation for real examples of BuildStream projects,
    

  • doc/source/using_tutorial.rst
    1 1
     
    
    2
    +
    
    3
    +.. _tutorial:
    
    4
    +
    
    2 5
     Tutorial
    
    3 6
     ========
    
    4 7
     This is a step by step walkthrough meant help the user quickly get
    

  • tests/frontend/yamlcache.py
    1
    +import os
    
    2
    +import pytest
    
    3
    +import hashlib
    
    4
    +import tempfile
    
    5
    +from ruamel import yaml
    
    6
    +
    
    7
    +from tests.testutils import cli, generate_junction, create_element_size, create_repo
    
    8
    +from buildstream import _yaml
    
    9
    +from buildstream._yamlcache import YamlCache
    
    10
    +from buildstream._project import Project
    
    11
    +from buildstream._context import Context
    
    12
    +from contextlib import contextmanager
    
    13
    +
    
    14
    +
    
    15
    +def generate_project(tmpdir, ref_storage, with_junction, name="test"):
    
    16
    +    if with_junction == 'junction':
    
    17
    +        subproject_dir = generate_project(
    
    18
    +            tmpdir, ref_storage,
    
    19
    +            'no-junction', name='test-subproject'
    
    20
    +        )
    
    21
    +
    
    22
    +    project_dir = os.path.join(tmpdir, name)
    
    23
    +    os.makedirs(project_dir)
    
    24
    +    # project.conf
    
    25
    +    project_conf_path = os.path.join(project_dir, 'project.conf')
    
    26
    +    elements_path = 'elements'
    
    27
    +    project_conf = {
    
    28
    +        'name': name,
    
    29
    +        'element-path': elements_path,
    
    30
    +        'ref-storage': ref_storage,
    
    31
    +    }
    
    32
    +    _yaml.dump(project_conf, project_conf_path)
    
    33
    +
    
    34
    +    # elements
    
    35
    +    if with_junction == 'junction':
    
    36
    +        junction_name = 'junction.bst'
    
    37
    +        junction_dir = os.path.join(project_dir, elements_path)
    
    38
    +        junction_path = os.path.join(project_dir, elements_path, junction_name)
    
    39
    +        os.makedirs(junction_dir)
    
    40
    +        generate_junction(tmpdir, subproject_dir, junction_path)
    
    41
    +        element_depends = [{'junction': junction_name, 'filename': 'test.bst'}]
    
    42
    +    else:
    
    43
    +        element_depends = []
    
    44
    +
    
    45
    +    element_name = 'test.bst'
    
    46
    +    create_element_size(element_name, project_dir, elements_path, element_depends, 1)
    
    47
    +
    
    48
    +    return project_dir
    
    49
    +
    
    50
    +
    
    51
    +@contextmanager
    
    52
    +def with_yamlcache(project_dir):
    
    53
    +    context = Context()
    
    54
    +    project = Project(project_dir, context)
    
    55
    +    cache_file = YamlCache.get_cache_file(project_dir)
    
    56
    +    with YamlCache.open(context, cache_file) as yamlcache:
    
    57
    +        yield yamlcache, project
    
    58
    +
    
    59
    +
    
    60
    +def yamlcache_key(yamlcache, in_file, copy_tree=False):
    
    61
    +    with open(in_file) as f:
    
    62
    +        key = yamlcache._calculate_key(f.read(), copy_tree)
    
    63
    +    return key
    
    64
    +
    
    65
    +
    
    66
    +def modified_file(input_file, tmpdir):
    
    67
    +    with open(input_file) as f:
    
    68
    +        data = f.read()
    
    69
    +    assert 'variables' not in data
    
    70
    +    data += '\nvariables: {modified: True}\n'
    
    71
    +    _, temppath = tempfile.mkstemp(dir=tmpdir, text=True)
    
    72
    +    with open(temppath, 'w') as f:
    
    73
    +        f.write(data)
    
    74
    +
    
    75
    +    return temppath
    
    76
    +
    
    77
    +
    
    78
    +@pytest.mark.parametrize('ref_storage', ['inline', 'project.refs'])
    
    79
    +@pytest.mark.parametrize('with_junction', ['no-junction', 'junction'])
    
    80
    +@pytest.mark.parametrize('move_project', ['move', 'no-move'])
    
    81
    +def test_yamlcache_used(cli, tmpdir, ref_storage, with_junction, move_project):
    
    82
    +    # Generate the project
    
    83
    +    project = generate_project(str(tmpdir), ref_storage, with_junction)
    
    84
    +    if with_junction == 'junction':
    
    85
    +        result = cli.run(project=project, args=['fetch', '--track', 'junction.bst'])
    
    86
    +        result.assert_success()
    
    87
    +
    
    88
    +    # bst show to put it in the cache
    
    89
    +    result = cli.run(project=project, args=['show', 'test.bst'])
    
    90
    +    result.assert_success()
    
    91
    +
    
    92
    +    element_path = os.path.join(project, 'elements', 'test.bst')
    
    93
    +    with with_yamlcache(project) as (yc, prj):
    
    94
    +        # Check that it's in the cache
    
    95
    +        assert yc.is_cached(prj, element_path)
    
    96
    +
    
    97
    +        # *Absolutely* horrible cache corruption to check it's being used
    
    98
    +        # Modifying the data from the cache is fraught with danger,
    
    99
    +        # so instead I'll load a modified version of the original file
    
    100
    +        temppath = modified_file(element_path, str(tmpdir))
    
    101
    +        contents = _yaml.load(temppath, copy_tree=False, project=prj)
    
    102
    +        key = yamlcache_key(yc, element_path)
    
    103
    +        yc.put_from_key(prj, element_path, key, contents)
    
    104
    +
    
    105
    +    # Show that a variable has been added
    
    106
    +    result = cli.run(project=project, args=['show', '--format', '%{vars}', 'test.bst'])
    
    107
    +    result.assert_success()
    
    108
    +    data = yaml.safe_load(result.output)
    
    109
    +    assert 'modified' in data
    
    110
    +    assert data['modified'] == 'True'
    
    111
    +
    
    112
    +
    
    113
    +@pytest.mark.parametrize('ref_storage', ['inline', 'project.refs'])
    
    114
    +@pytest.mark.parametrize('with_junction', ['junction', 'no-junction'])
    
    115
    +def test_yamlcache_changed_file(cli, tmpdir, ref_storage, with_junction):
    
    116
    +    # i.e. a file is cached, the file is changed, loading the file (with cache) returns new data
    
    117
    +    # inline and junction can only be changed by opening a workspace
    
    118
    +    # Generate the project
    
    119
    +    project = generate_project(str(tmpdir), ref_storage, with_junction)
    
    120
    +    if with_junction == 'junction':
    
    121
    +        result = cli.run(project=project, args=['fetch', '--track', 'junction.bst'])
    
    122
    +        result.assert_success()
    
    123
    +
    
    124
    +    # bst show to put it in the cache
    
    125
    +    result = cli.run(project=project, args=['show', 'test.bst'])
    
    126
    +    result.assert_success()
    
    127
    +
    
    128
    +    element_path = os.path.join(project, 'elements', 'test.bst')
    
    129
    +    with with_yamlcache(project) as (yc, prj):
    
    130
    +        # Check that it's in the cache then modify
    
    131
    +        assert yc.is_cached(prj, element_path)
    
    132
    +        with open(element_path, "a") as f:
    
    133
    +            f.write('\nvariables: {modified: True}\n')
    
    134
    +        # Load modified yaml cache file into cache
    
    135
    +        _yaml.load(element_path, copy_tree=False, project=prj, yaml_cache=yc)
    
    136
    +
    
    137
    +    # Show that a variable has been added
    
    138
    +    result = cli.run(project=project, args=['show', '--format', '%{vars}', 'test.bst'])
    
    139
    +    result.assert_success()
    
    140
    +    data = yaml.safe_load(result.output)
    
    141
    +    assert 'modified' in data
    
    142
    +    assert data['modified'] == 'True'

  • tests/yaml/yaml.py
    1 1
     import os
    
    2 2
     import pytest
    
    3
    +import tempfile
    
    3 4
     from collections import Mapping
    
    4 5
     
    
    5 6
     from buildstream import _yaml
    
    6 7
     from buildstream._exceptions import LoadError, LoadErrorReason
    
    8
    +from buildstream._context import Context
    
    9
    +from buildstream._yamlcache import YamlCache
    
    7 10
     
    
    8 11
     DATA_DIR = os.path.join(
    
    9 12
         os.path.dirname(os.path.realpath(__file__)),
    
    ... ... @@ -150,6 +153,21 @@ def test_composite_preserve_originals(datafiles):
    150 153
         assert(_yaml.node_get(orig_extra, str, 'old') == 'new')
    
    151 154
     
    
    152 155
     
    
    156
    +def load_yaml_file(filename, *, cache_path, shortname=None, from_cache='raw'):
    
    157
    +
    
    158
    +    _, temppath = tempfile.mkstemp(dir=os.path.join(cache_path.dirname, cache_path.basename), text=True)
    
    159
    +    context = Context()
    
    160
    +
    
    161
    +    with YamlCache.open(context, temppath) as yc:
    
    162
    +        if from_cache == 'raw':
    
    163
    +            return _yaml.load(filename, shortname)
    
    164
    +        elif from_cache == 'cached':
    
    165
    +            _yaml.load(filename, shortname, yaml_cache=yc)
    
    166
    +            return _yaml.load(filename, shortname, yaml_cache=yc)
    
    167
    +        else:
    
    168
    +            assert False
    
    169
    +
    
    170
    +
    
    153 171
     # Tests for list composition
    
    154 172
     #
    
    155 173
     # Each test composits a filename on top of basics.yaml, and tests
    
    ... ... @@ -165,6 +183,7 @@ def test_composite_preserve_originals(datafiles):
    165 183
     #    prov_col: The expected provenance column of "mood"
    
    166 184
     #
    
    167 185
     @pytest.mark.datafiles(os.path.join(DATA_DIR))
    
    186
    +@pytest.mark.parametrize('caching', [('raw'), ('cached')])
    
    168 187
     @pytest.mark.parametrize("filename,index,length,mood,prov_file,prov_line,prov_col", [
    
    169 188
     
    
    170 189
         # Test results of compositing with the (<) prepend directive
    
    ... ... @@ -195,14 +214,15 @@ def test_composite_preserve_originals(datafiles):
    195 214
         ('implicitoverwrite.yaml', 0, 2, 'overwrite1', 'implicitoverwrite.yaml', 4, 8),
    
    196 215
         ('implicitoverwrite.yaml', 1, 2, 'overwrite2', 'implicitoverwrite.yaml', 6, 8),
    
    197 216
     ])
    
    198
    -def test_list_composition(datafiles, filename,
    
    217
    +def test_list_composition(datafiles, filename, tmpdir,
    
    199 218
                               index, length, mood,
    
    200
    -                          prov_file, prov_line, prov_col):
    
    201
    -    base = os.path.join(datafiles.dirname, datafiles.basename, 'basics.yaml')
    
    202
    -    overlay = os.path.join(datafiles.dirname, datafiles.basename, filename)
    
    219
    +                          prov_file, prov_line, prov_col, caching):
    
    220
    +    base_file = os.path.join(datafiles.dirname, datafiles.basename, 'basics.yaml')
    
    221
    +    overlay_file = os.path.join(datafiles.dirname, datafiles.basename, filename)
    
    222
    +
    
    223
    +    base = load_yaml_file(base_file, cache_path=tmpdir, shortname='basics.yaml', from_cache=caching)
    
    224
    +    overlay = load_yaml_file(overlay_file, cache_path=tmpdir, shortname=filename, from_cache=caching)
    
    203 225
     
    
    204
    -    base = _yaml.load(base, shortname='basics.yaml')
    
    205
    -    overlay = _yaml.load(overlay, shortname=filename)
    
    206 226
         _yaml.composite_dict(base, overlay)
    
    207 227
     
    
    208 228
         children = _yaml.node_get(base, list, 'children')
    
    ... ... @@ -254,6 +274,7 @@ def test_list_deletion(datafiles):
    254 274
     #    prov_col: The expected provenance column of "mood"
    
    255 275
     #
    
    256 276
     @pytest.mark.datafiles(os.path.join(DATA_DIR))
    
    277
    +@pytest.mark.parametrize('caching', [('raw'), ('cached')])
    
    257 278
     @pytest.mark.parametrize("filename1,filename2,index,length,mood,prov_file,prov_line,prov_col", [
    
    258 279
     
    
    259 280
         # Test results of compositing literal list with (>) and then (<)
    
    ... ... @@ -310,9 +331,9 @@ def test_list_deletion(datafiles):
    310 331
         ('listoverwrite.yaml', 'listprepend.yaml', 2, 4, 'overwrite1', 'listoverwrite.yaml', 5, 10),
    
    311 332
         ('listoverwrite.yaml', 'listprepend.yaml', 3, 4, 'overwrite2', 'listoverwrite.yaml', 7, 10),
    
    312 333
     ])
    
    313
    -def test_list_composition_twice(datafiles, filename1, filename2,
    
    334
    +def test_list_composition_twice(datafiles, tmpdir, filename1, filename2,
    
    314 335
                                     index, length, mood,
    
    315
    -                                prov_file, prov_line, prov_col):
    
    336
    +                                prov_file, prov_line, prov_col, caching):
    
    316 337
         file_base = os.path.join(datafiles.dirname, datafiles.basename, 'basics.yaml')
    
    317 338
         file1 = os.path.join(datafiles.dirname, datafiles.basename, filename1)
    
    318 339
         file2 = os.path.join(datafiles.dirname, datafiles.basename, filename2)
    
    ... ... @@ -320,9 +341,9 @@ def test_list_composition_twice(datafiles, filename1, filename2,
    320 341
         #####################
    
    321 342
         # Round 1 - Fight !
    
    322 343
         #####################
    
    323
    -    base = _yaml.load(file_base, shortname='basics.yaml')
    
    324
    -    overlay1 = _yaml.load(file1, shortname=filename1)
    
    325
    -    overlay2 = _yaml.load(file2, shortname=filename2)
    
    344
    +    base = load_yaml_file(file_base, cache_path=tmpdir, shortname='basics.yaml', from_cache=caching)
    
    345
    +    overlay1 = load_yaml_file(file1, cache_path=tmpdir, shortname=filename1, from_cache=caching)
    
    346
    +    overlay2 = load_yaml_file(file2, cache_path=tmpdir, shortname=filename2, from_cache=caching)
    
    326 347
     
    
    327 348
         _yaml.composite_dict(base, overlay1)
    
    328 349
         _yaml.composite_dict(base, overlay2)
    
    ... ... @@ -337,9 +358,9 @@ def test_list_composition_twice(datafiles, filename1, filename2,
    337 358
         #####################
    
    338 359
         # Round 2 - Fight !
    
    339 360
         #####################
    
    340
    -    base = _yaml.load(file_base, shortname='basics.yaml')
    
    341
    -    overlay1 = _yaml.load(file1, shortname=filename1)
    
    342
    -    overlay2 = _yaml.load(file2, shortname=filename2)
    
    361
    +    base = load_yaml_file(file_base, cache_path=tmpdir, shortname='basics.yaml', from_cache=caching)
    
    362
    +    overlay1 = load_yaml_file(file1, cache_path=tmpdir, shortname=filename1, from_cache=caching)
    
    363
    +    overlay2 = load_yaml_file(file2, cache_path=tmpdir, shortname=filename2, from_cache=caching)
    
    343 364
     
    
    344 365
         _yaml.composite_dict(overlay1, overlay2)
    
    345 366
         _yaml.composite_dict(base, overlay1)
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]