project_config package
Reproducible configuration across projects.
- class project_config.ActionsContext(fix: bool)[source]
Bases:
tuple
Context of global data passed to rule verbs.
- _asdict()
Return a new dict which maps field names to their values.
- _field_defaults = {}
- _field_types = {'fix': ForwardRef('bool')}
- _fields = ('fix',)
- _fields_defaults = {}
- classmethod _make(iterable)
Make a new ActionsContext object from a sequence or iterable
- _replace(**kwds)
Return a new ActionsContext object replacing specified fields with new values
- class project_config.Tree(rootdir: str)[source]
Bases:
object
Files cache used by the linter in checking processes.
It represents the tree of files and directories starting at the root directory of the project.
Instances of
project_config.tree.Tree
can be iterated with:for fpath, fcontent in tree.files: if fcontent is None: # file does not exist ... elif not isinstance(fcontent, str): # file is a directory # # so `fcontent` is another Tree instance here for nested_fpath, nested_fcontent in fcontent.files: ...
If you want to get the serialialized version of the file you can use the method
project_config.tree.Tree.serialize_file()
:instance = fpath, tree.serialize_file(fpath)
If you are not inside a context were you have the content of the files (a common scenario for conditional actions) you can get them calling the method
project_config.tree.Tree.get_file_content()
:fcontent = tree.get_file_content(fpath)
This class caches the files contents along with their serialized versions, so subsequent access to the same files in the project tree are fast.
- Parameters
rootdir (str) – Root directory of the project.
- cache_files(fpaths: List[str]) None [source]
Cache a set of files given their paths.
- Parameters
fpaths (list) – Paths to the files to store in cache.
- fetch_file(url: str) Any [source]
Fetch a file from online or offline sources given a url or path.
This method is a convenient cache wrapper for
project_config.fetchers.fetch()
. Used by plugin actions which need an object-serialized version of files to perform operations against them, like the jmespath one.
- property files: List[Tuple[str, str]]
Returns an array of the current cached files for a rule action.
- Returns
- Array of tuples with the relative path to the file
rootdir
as the first item and the content of the file as the second one.
- Return type
- get_file_content(fpath: str) str [source]
Returns the content of a file given his relative path.
This method is tipically used by
if
plugin action conditionals to get the content of the files that are not defined infiles
subject rules fields.- Parameters
fpath (str) – Path to the file relative to the root directory.
- normalize_path(fpath: str) str [source]
Normalize a path given his relative path to the root directory.
- serialize_file(fpath: str) Any [source]
Returns the object-serialized version of a file.
This method is a convenient cache wrapper for
project_config.serializers.serialize_for_url()
. Is used by plugin actions which need an object-serialized version of files to perform operations against them, like the jmespath one.