Actions

Actions encapsulate behavior of how to change a file.

Absent

class rcmt.package.action.Absent(target)

Deletes a file or directory.

Parameters

target (str) – Path to the file or directory to delete.

Example

# Delete the file config.yaml at the root of a repository.
Absent(target="config.yaml")

DeleteKey

class rcmt.package.action.DeleteKey(key, target)

Delete a key in a file. The file has to be in a format supported by Encodings.

Parameters
  • key (str) – Path to the key in the data structure.

  • target (str) – Path to the file to modify.

Example

# Delete key "bar" in dict "foo" in file config.json.
DeleteKey(key="foo.bar", target="config.json")

DeleteLineInFile

class rcmt.package.action.DeleteLineInFile(line, selector)

DeleteLineInFile deletes a line in a file if the file contains the line.

Parameters
  • line (str) – Line to search for. This is a regular expression. Input gets wrapped with ^ and $.

  • selector (str) – Glob selector to find the files to modify.

Example

DeleteLineInFile(line="The Line", selector="file.txt")

Exec

class rcmt.package.action.Exec(exec_path, selector, timeout=120)

Exec calls an executable and passes matching files in a repository to it. The executable can then modify each file.

The executable should expect the path of a file as its only positional argument.

Parameters
  • exec_path (str) – Path to the executable.

  • selector (str) – Glob selector to find the files to modify.

  • timeout (int) – Maximum runtime of the executable, in seconds.

Example

# Find all Python files in a repository recursively and pass each path to /opt/the-binary.
Exec(exec_path="/opt/the-binary", selector="**/*.py")

LineInFile

class rcmt.package.action.LineInFile(line, selector)

LineInFile ensures that a line exists in a file. It adds the line if it does not exist.

Parameters
  • line (str) – Line to search for.

  • selector (str) – Glob selector to find the files to modify.

Example

LineInFile(line="The Line", selector="file.txt")

Merge

class rcmt.package.action.Merge(selector, source, merge_strategy='replace')

Merge merges the content of a file in a repository with the content of a file from a package.

It supports merging of various file formats through Encodings.

Parameters
  • selector (str) – Glob selector to find the files to merge.

  • source (str) – Path to the file that contains the source data.

  • merge_strategy (str) – Strategy to use when merging data. replace replaces a key if it already exists. additive combines collections, e.g. list or set.

Example

# Ensure that pyproject.toml contains specific keys.
Merge(selector="pyproject.toml", source="pyproject.toml")

Own

class rcmt.package.action.Own(target, source)

Own ensures that a file in a repository stays the same.

It always overwrites the data in the file with the data from a package.

Parameters
  • target (str) – Path to the file in a repository to own.

  • source (str) – Path to the file in the package that contains the source data.

Example

# Ensure that .flake8 looks the same across all repositories.
Own(target=".flake8", source=".flake8")

Seed

class rcmt.package.action.Seed(target, source)

Seed ensures that a file in a repository is present.

It does not modify the file again if the file is present in a repository.

Parameters
  • target (str) – Path to the file in a repository to seed.

  • source (str) – Path to the file in the package that contains the source data.

Example

# Ensure that the default Makefile is present.
Seed(target="Makefile", source="Makefile")

Templating

Some Actions support templating.

rcmt renders a Template string and passes the following variables to it:

  • $repo_name - The name of the repository, e.g. rcmt.

  • $repo_project - The name of the owner, org or project, e.g. wndhydrnt.

  • $repo_source - The address of the source that hosts the repository, e.g. github.com.

Take a look at the templating example for how to use these variables.