devops.files

Top level package for file operations in mstd checks.

class devops.files.FileType(*values)[source]

Bases: Enum

Enumeration of file types for mstd checks.

UNKNOWN = 0
CPPHeader = 1
CPPSource = 2
CMakeLists = 3
classmethod all_types()[source]

Get a set of all defined file types.

Returns:

set[FileType] – A set containing all file types.

Return type:

set[FileType]

classmethod cpp_types()[source]

Get a set of all CPP related file types.

Return type:

set[FileType]

classmethod is_cpp_type(file_type)[source]

Check if the given file type is a C++ related type.

Parameters:

file_type (FileType)

Return type:

bool

devops.files.determine_file_type(filename)[source]

Determine the file type based on the filename extension.

Parameters:

filename (str | Path) – The name of the file to check.

Returns:

FileType – The determined file type.

Return type:

FileType

devops.files.file_exist(file, *, throwing=False, throw_msg=None)[source]

Check if a file exists at the given path.

Parameters:
  • file (str | Path) – The path to the file to check.

  • throwing (bool) – Whether to raise an exception if the file does not exist.

  • throw_msg (str | None) – Custom message to use when raising an exception if the file does not exist.

Returns:

bool – True if the file exists, False otherwise.

Raises:

DevOpsFileNotFoundError – If the file does not exist and throwing is True.

Return type:

bool

devops.files.filter_cpp_files(files)[source]

Filter and return only C++ related files from the given list.

Parameters:

files (list[Path]) – The list of file paths to filter.

Returns:

list[Path] – The filtered list containing only C++ related files.

Return type:

list[Path]

devops.files.get_dirs_in_dir(directory='.')[source]

Get all directories in the specified directory.

Parameters:

directory (str | Path) – The path to the directory to search. Defaults to the current directory.

Returns:

list[Path] – List of directory paths found in the specified directory.

Return type:

list[Path]

devops.files.get_files_in_dirs(paths, exclude_dirs=None, exclude_files=None, max_recursion=20)[source]

Get all files in the specified directories.

Parameters:
  • paths (Iterable[Path]) – List of directory paths to search for files.

  • exclude_dirs (list[str] | None) – List of directory names to exclude from the search. Defaults to None.

  • exclude_files (list[str] | None) – List of file names to exclude from the search. Defaults to None.

  • max_recursion (int) – Number of maximum recursion through dirs to avoid infinite recursion, default 20

Returns:

list[Path] – List of file paths found in the specified directories.

Return type:

list[Path]

devops.files.get_staged_files()[source]

Get the list of staged files in the git repository.

Returns:

list[Path] – List of staged file paths.

Raises:

subprocess.CalledProcessError – If the git command fails.

Return type:

list[Path]

devops.files.open_file(file, mode='r')[source]

Read the content of a file.

Parameters:
  • file (str | Path) – The path to the file to read.

  • mode (str)

Yields:

typing.IO[str] – The opened file object.

Raises:

DevOpsFileNotFoundError – If the file does not exist.

Return type:

Generator[IO[str], None, None]

devops.files.write_text(file, content)[source]

Write text content to a file.

Parameters:
  • file (str | Path) – The path to the file to write.

  • content (str) – The text content to write to the file.

Return type:

None

Modules

files

Module for file operations in mstd checks.

update_changelog

Module for updating the changelog file.