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

fix: bool

Alias for field number 0

class project_config.Rule(*args, **kwargs)[source]

Bases: dict

Style rule.

files: List[str]
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_file(fpath: str) str[source]

Cache a file normalizing its path.

Parameters

fpath (str) – Relative path from root directory.

Returns

Normalized absolute path.

Return type

str

_generator(fpaths: Union[Iterator[str], List[str]]) Iterable[Tuple[str, Optional[str]]][source]
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.

edit_serialized_file(fpath: str, new_content: Any) bool[source]

Edit a file in the cache.

Parameters
  • fpath (str) – Path to the file to edit.

  • new_content (object) – New content for the file.

Returns

True if the file content has changed, False otherwise.

Return type

bool

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.

Parameters

url (str) – Url or path to the file to fetch.

Returns

Object-serialized version of the file.

Return type

object

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

list

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 in files 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.

Parameters

fpath (str) – Path to the file relative to the root directory.

Returns

Normalized absolute path.

Return type

str

rootdir: str
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.

Parameters

fpath (str) – Path to the file to serialize.

Returns

Object-serialized version of the file.

Return type

object

Subpackages

Submodules