summaryrefslogtreecommitdiff
path: root/buildstream/utils.py
Commit message (Collapse)AuthorAgeFilesLines
* Use deterministic umask when staging sources.Valentin David2018-08-121-1/+10
| | | | | | This fix is applied to plugins bzr, git, patch. Fixes #543 #544 #555.
* utils.py: add getmtime() and magic_timestampJim MacArthur2018-08-011-5/+13
| | | | | magic_timestamp is moved into file scope so other classes can use it.
* _context.py: Cache size is now restricted to available disk spaceQinusty/491Josh Smith2018-07-271-0/+21
| | | | | | | | | | | | This address issue #491. When attempting to run buildstream with a configuration specifying a cache quota larger than your available disk space, buildstream will alert the user and exit. Note: This takes into consideration your current cache usage and therefore restricts the overall size of your artifact cache folder.
* Move _ALIAS_SEPARATOR into utilsJonathan Maw2018-07-271-0/+4
| | | | The separator is useful in source files other than _project.py
* Add cache_quota to user configTristan Maat2018-07-181-0/+70
|
* utils.py: Allow `list_relative_paths` to list directoriesTristan Maat2018-07-181-6/+8
|
* Remove shebangs from python filesGökçen Nurlu2018-06-191-1/+0
| | | | Fixes #424
* Handle missing tags in git repositories correctlyTristan Maat2018-06-111-0/+4
| | | | Fixes issue #380
* utils.py: Correcting a typo in safe_remove's commentPhillip Smyth2018-06-051-1/+1
|
* Use versioneer instead of setuptools_scmTristan Van Berkom2018-04-261-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using setuptools_scm had a couple of bad problems: o Unexpected versioning semantics, setuptools_scm would increment the micro version by itself in the case that we derive a version number from something that is not a tag, making the assumption that we are "leading up to" the next micro version. People mostly dont expect this. o When installing in developer mode, i.e. with `pip3 install --user -e .`, then we were always picking the generated version at install time and never again dynamically resolving it. Many of our users install this way and update through git, so it's important that we report more precise versions all the time. This commit needs to make a series of changes at the same time: o Adds versioneer.py to the toplevel, this is used by setup.py for various activities. This is modified only to inform the linter to skip o Adds buildstream/_version.py, which is generated by versioneer and gives us the machinery to automatically derive the correct version This is modified only to inform the linter to skip o Adds a .gitattributes file which informs git to substitute the buildstream/_version.py file, this is just to ensure that the versioning output would work if ever we used `git archive` to release a tarball. o Modifies setup.py and setup.cfg for versioneer o Modifies utils.py and _frontend/cli.py such as to avoid importing the derived version when running bash completion mode, we dont derive the version at completion time because this can result in running a subprocess (when running in developer install mode) and is an undesirable overhead. o Updates tests/frontend/version.py to expect changed version output
* buildstream/utils.py: Fixing unused variablesTristan Van Berkom2018-04-191-2/+2
|
* utils.py: Added _is_main_process()Tristan Van Berkom2018-04-101-0/+12
| | | | | A helper function to identify if we are running in the main process or not.
* Allow 'None' as a default_value for _yaml.node_getTristan Maat2018-04-071-0/+5
|
* Allow stage_artifact to update mtimesTristan Maat2018-03-271-0/+12
|
* pylint - dealt with redefined-outer-name and redefined-built in warningsJames Ennis2018-03-141-1/+1
|
* pylint - dealt with unnecessary-pass warningJames Ennis2018-03-141-1/+1
|
* pylint - dealt with anomalous-backslash-in-string warningJames Ennis2018-03-141-1/+2
|
* utils.py: Wrap calls to os.path.realpath() in an LRU cacheSam Thursfield2018-02-121-9/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | The os.path.realpath() function is expensive and we call it many times, to the point that os.path.realpath() calls make up around 40% of the total time spent in Element.stage_artifact(). The cleanest way to fix this is with a `functools.lru_cache()` wrapper that caches recently used values. None of the code in question can be removed (as the tests added in the previous commit will demonstrate). I tested this by running `bst shell base/base-system.bst true` in the GNOME modulesets project. o Without this patch there are 240,019 calls os.path.realpath() o With this patch there are 10,379 calls to os.path.realpath() o If we increase the cache size to 128 items, there are 10,359 calls to os.path.realpath(). o If we reduce the cache size to 32 items, there are 10,426 calls. o In all cases the number of *unique* calls is 10,327. This fixes issue #174.
* Get version number w/o pkg_resourcesGökçen Nurlu2018-01-311-3/+2
| | | | | | | | | | | | This removes most of the usages of pkg_resources from the codebase, helping the goal of getting rid of that completely. With this change, version number is generated during install and embedded into `__version__` which is then imported by root level `__init__`. From there, it is used by other parts of the codebase when needed. Generated `__version__` file is ignored and not tracked by git to prevent unnecessary 'changes' messages and accidental commits of that file.
* buildstream/utils.py: remove unused import 'pickle'Angelos Evripiotis2018-01-241-1/+0
|
* Update copyright years of files I have touchedSam Thursfield2018-01-111-1/+1
|
* Add support for multiple remote cachesSam Thursfield2018-01-111-0/+30
| | | | | | | | | | | | | | | | | | | | | | This extends the 'artifacts' configuration block such that a list of `url` mappings can be given instead of a single entry. For example: artifacts: - url: http://example.com/artifacts1 - url: ssh://ostree@example.com/artifacts2 The OSTreeCache class is updated to set up multiple remotes and query remote refs from all of them. There are no automated tests for this yet. Empty URLs ('') now raise an exception. They cause breakages internally if we allow them through, and they can only occur if the user or our tests are misconfiguring things somehow. We report failure to fetch from the cache by printing a message to stderr for now. This is because BuildStream's actual logging functionality can't be used during frontend init -- see issue #168.
* utils.py: Make list_relative_paths() report sorted paths.Tristan Van Berkom2018-01-101-15/+26
| | | | | | | | | | | This is needed because plugins make use of this function to generate a cache key which must be stable. In addition to the above, this patch also mitigates the performance hit of sorting, and allows _process_list() to function to iterate through the generator when additional sorting is not needed. This patch is an enhanced version of Sam Thursfield's patch on MR !216
* Move utils._generate_key() into a new 'cachekey' moduleSam Thursfield2018-01-041-19/+1
| | | | | This avoids a circular dependency between the 'utils' and '_yaml' modules.
* utils.py: Add save_file_atomic() helperSam Thursfield2018-01-041-0/+58
| | | | | | | | | | | | This is a context manager that can be used to divert file writes into a temporary file, which is then renamed into place once writing is complete. It is primarily intended for use by source plugins which download files, so they can ensure that their downloads appear atomic and there is no risk of leaving half-downloaded files in the cache. So far this is not used in the core, but it is needed by the Docker source plugin that is proposed for the bst-external plugins repo. See: https://gitlab.com/BuildStream/bst-external/merge_requests/9
* Exceptions refactoringTristan Van Berkom2017-12-291-3/+5
| | | | | | | | | | | | | | | Outline of changes to exceptions: o Now BstError base class has a `domain` and `reason` member, reason members are optional. o All derived error classes now specify their `domain` o For LoadError, LoadErrorReason defines the error's `reason` o Now the scheduler `job` class takes care of sending the error reason and domain back to the main process where the last exception which caused a child task to fail can be discretely stored.
* utils._call: rm unused assignments to exit_codeAngelos Evripiotis2017-12-221-2/+1
|
* utils._call: fix race condition on 'process' varAngelos Evripiotis2017-12-221-0/+2
| | | | | | | | | | Tested by inflating the chance of hitting the race. First, insert a sleep between opening the terminator context and starting the process, then: python3 -c 'import buildstream.utils; import os; \ buildstream.utils._call(["echo", "hello"], True); \ print(os.getpid())' & sleep 1; kill $!
* utils._call: fix doc typoAngelos Evripiotis2017-12-221-1/+1
|
* utils.py: Add UtilErrorTristan Van Berkom2017-12-201-38/+82
| | | | | | | | | | | | | | | | | Report UtilError instead of OSError and similar python errors. Also ensure we catch system errors and raise UtilError with descriptive text instead; for the user experience; this is the difference between: o A FAILURE message with a description as to what went wrong (exception handled with UtilError) o A BUG message with the unhandled system error printed with a stack trace (exception left unhandled) Also, UtilsError and ProgramNotFoundError are now public exceptions declared in utils.py, where they will appear in the documentation.
* utils._tempdir: don't leak on exceptionsAngelos Evripiotis2017-12-131-4/+5
|
* Remove unused importsGökçen Nurlu2017-12-071-12/+13
|
* utils.py: Removing safe_move() and move_files() APIsTristan Van Berkom2017-12-051-65/+0
| | | | | These are not used anywhere internally and are not really desirable to use, as usually you need only care about moving a toplevel directory.
* utils: Expand file copying to optionally report files writtenJonathan Maw2017-12-011-7/+23
|
* utils.py: Fix variable name typoGökçen Nurlu2017-11-171-1/+1
|
* Switch old-style string formattings to new '.format()'Gökçen Nurlu2017-11-171-8/+8
|
* utils.py: Make {copy,link,move}_files use keyword argsJonathan Maw2017-11-141-3/+3
|
* utils.py: Make safe copy/link/move use keyword argsJonathan Maw2017-11-141-3/+3
| | | | | | The 'result' field is optional, and currently used only by the internals of {copy,move,link}_files. I think it makes sense to mandate that it's called as a keyword arg in future.
* Refactoring: Move exceptions module to be privateTristan Van Berkom2017-11-061-1/+1
| | | | Hide all of buildstream's internal exceptions from the API surface.
* utils.list_relative_paths: Clarify empty dirs noteAngelos Evripiotis2017-10-301-1/+2
|
* utils.list_relative_paths: avoid os.path.relpathAngelos Evripiotis2017-10-301-6/+9
| | | | | | | | | | Profiling suggested that the cumulative time spent in os.path.relpath() was the dominant cost of utils.list_relative_paths(). Try to call this only once per directory walked. In Python 3.5, we can optimise further by using os.scandir() and maintaining relative paths as we go.
* utils.py: Fix regression, build directories not being removed.Tristan Van Berkom2017-10-211-3/+3
| | | | | utils._force_rmtree() was overwriting it's path directory, and then only recursively removing the last entry which was walked.
* Ensure that artifact file permissions are set in the right orderTristan Maat2017-10-131-5/+26
|
* utils.py: Fix missing psutil referenceTristan Maat2017-09-281-1/+1
|
* utils.py: Added sha256sum utilityTristan Van Berkom2017-09-121-0/+21
| | | | | This little bit of code was being repeated a bunch of times already throughout buildstream, looks sane enough to offer a utility.
* documentation: Set page titles manually in python modules.Tristan Van Berkom2017-08-311-0/+4
|
* utils.py: Added get_bst_version() APITristan Van Berkom2017-08-301-0/+15
| | | | Fetches the numeric major/minor version of the BuildStream package.
* utils.py: Document exceptions from file operationsTristan Van Berkom2017-07-131-1/+25
|
* utils.py: Fix _tempdir for python3.4Jonathan Maw2017-07-101-1/+1
| | | | | | | Support for prefix=None and suffix=None was added in python 3.5. The default for suffix happens to be "", and the prefix happens to be "tmp" (though that's an implementation detail), but it's sufficient, and simpler than writing conditionals that omit certain args.
* utils.py: Adding _tempdir() utility context managerTristan Van Berkom2017-07-091-0/+32
| | | | | A temporary directory context manager which cleans itself out on sigterm.