cli.fix.move_unnecessary_dependencies package¶
Module contents¶
Compatibility wrapper.
- This package was migrated from a flat module (move_unnecessary_dependencies.py) to a package layout:
move_unnecessary_dependencies/__main__.py contains the original implementation.
We re-export the public API so existing imports keep working.
- class cli.fix.move_unnecessary_dependencies.CommentedMap(*args: Any, **kw: Any)¶
Bases:
ordereddict,CommentedBase- copy() a shallow copy of od¶
- get(key: Any, default: Any = None) Any¶
Return the value for key if key is in the dictionary, else default.
- insert(pos: Any, key: Any, value: Any, comment: Any | None = None) None¶
insert key value into given position, as defined by source YAML attach comment if provided
- items() a set-like object providing a view on D's items¶
- keys() a set-like object providing a view on D's keys¶
- mlget(key: Any, default: Any = None, list_ok: Any = False) Any¶
multi-level get that expects dicts within dicts
- pop(key[, default]) v, remove specified key and return the corresponding value.¶
If the key is not found, return the default if given; otherwise, raise a KeyError.
- update([E, ]**F) None. Update D from dict/iterable E and F.¶
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values¶
- class cli.fix.move_unnecessary_dependencies.CommentedSeq(*args: Any, **kw: Any)¶
Bases:
MutableSliceableSequence,list,CommentedBase- sort(key: Any = None, reverse: bool = False) None¶
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).
If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.
The reverse flag can be set to sort in descending order.
- class cli.fix.move_unnecessary_dependencies.SingleQuotedScalarString(value: Text, anchor: Any = None)¶
Bases:
ScalarString- style = "'"¶
- class cli.fix.move_unnecessary_dependencies.YAML(*, typ: List[str] | str | None = None, pure: Any = False, output: Any = None, plug_ins: Any = None)¶
Bases:
object- Xdump_all(documents: Any, stream: Any, *, transform: Any = None) Any¶
Serialize a sequence of Python objects into a YAML stream.
- compose(stream: Path | StreamTextType) Any¶
Parse the first YAML document in a stream and produce the corresponding representation tree.
- compose_all(stream: Path | StreamTextType) Any¶
Parse all YAML documents in a stream and produce corresponding representation trees.
- emit(events: Any, stream: Any) None¶
Emit YAML parsing events into a stream. If stream is None, return the produced string instead.
- get_constructor_parser(stream: StreamTextType) Any¶
the old cyaml needs special setup, and therefore the stream
- load(stream: Path | StreamTextType) Any¶
at this point you either have the non-pure Parser (which has its own reader and scanner) or you have the pure Parser. If the pure Parser is set, then set the Reader and Scanner, if not already set. If either the Scanner or Reader are set, you cannot use the non-pure Parser,
so reset it to the pure parser and set the Reader resp. Scanner if necessary
- official_plug_ins() Any¶
search for list of subdirs that are plug-ins, if __file__ is not available, e.g. single file installers that are not properly emulating a file-system (issue 324) no plug-ins will be found. If any are packaged, you know which file that are and you can explicitly provide it during instantiation:
yaml = ruamel.yaml.YAML(plug_ins=[‘ruamel/yaml/jinja2/__plug_in__’])
- register_class(cls: Any) Any¶
register a class for dumping/loading - if it has attribute yaml_tag use that to register, else use class name - if it has methods to_yaml/from_yaml use those to dump/load else dump attributes
as mapping
- serialize(node: Any, stream: StreamType | None) Any¶
Serialize a representation tree into a YAML stream. If stream is None, return the produced string instead.
- serialize_all(nodes: Any, stream: StreamType | None) Any¶
Serialize a sequence of representation trees into a YAML stream. If stream is None, return the produced string instead.
- property version: Tuple[int, int] | None¶
- cli.fix.move_unnecessary_dependencies.build_include_block_yaml(consumer_role: str, moved_deps: List[str]) List[dict]¶
Build a guarded block that includes one or many roles. This block will be prepended to tasks/01_core.yml or tasks/main.yml.
- cli.fix.move_unnecessary_dependencies.build_providers_index(all_roles: List[str]) Dict[str, Tuple[Set[str], Set[str]]]¶
Map role_name -> (provided_vars, handler_names)
- cli.fix.move_unnecessary_dependencies.collect_role_defined_vars(role_dir: str) Set[str]¶
Vars a role ‘provides’: defaults/vars keys + set_fact keys in tasks.
- cli.fix.move_unnecessary_dependencies.collect_role_handler_names(role_dir: str) Set[str]¶
Handler names defined by a role (for notify detection).
- cli.fix.move_unnecessary_dependencies.dependency_is_unnecessary(consumer_dir: str, consumer_name: str, producer_name: str, provider_vars: Set[str], provider_handlers: Set[str]) bool¶
Apply heuristic to decide if we can move this dependency.
- cli.fix.move_unnecessary_dependencies.dump_yaml_rt(data, path: str)¶
- cli.fix.move_unnecessary_dependencies.find_notify_offsets_for_handlers(text: str, handler_names: Set[str]) List[int]¶
Heuristic: for each handler name, find occurrences where ‘notify’ appears within the preceding ~200 chars. Works for single string or list-style notify blocks.
- cli.fix.move_unnecessary_dependencies.find_var_positions(text: str, varname: str) List[int]¶
Return byte offsets for occurrences of varname (word-ish boundary).
- cli.fix.move_unnecessary_dependencies.first_include_offset_for_role(text: str, producer_role: str) int | None¶
Find earliest include/import of a given role in this YAML text. Handles compact dict and block styles.
- cli.fix.move_unnecessary_dependencies.first_var_use_offset_in_text(text: str, provided_vars: Set[str]) int | None¶
- cli.fix.move_unnecessary_dependencies.flatten_keys(data) Set[str]¶
- cli.fix.move_unnecessary_dependencies.gather_yaml_files(base: str, patterns: List[str]) List[str]¶
- cli.fix.move_unnecessary_dependencies.iter_role_dirs(project_root: str) List[str]¶
- cli.fix.move_unnecessary_dependencies.load_yaml_rt(path: str)¶
- cli.fix.move_unnecessary_dependencies.main()¶
- cli.fix.move_unnecessary_dependencies.parse_meta_dependencies(role_dir: str) List[str]¶
- cli.fix.move_unnecessary_dependencies.path_if_exists(*parts) str | None¶
- cli.fix.move_unnecessary_dependencies.prepend_tasks(tasks_path: str, new_tasks, dry_run: bool)¶
Prepend new_tasks (CommentedSeq) to an existing tasks YAML list while preserving comments. If the file does not exist, create it with new_tasks.
- cli.fix.move_unnecessary_dependencies.process_role(role_dir: str, providers_index: Dict[str, Tuple[Set[str], Set[str]]], only_role: str | None, dry_run: bool) bool¶
Returns True if any change suggested/made for this role.
- cli.fix.move_unnecessary_dependencies.read_text(path: str) str¶
- cli.fix.move_unnecessary_dependencies.role_name_from_dir(role_dir: str) str¶
- cli.fix.move_unnecessary_dependencies.roles_root(project_root: str) str¶
- cli.fix.move_unnecessary_dependencies.sanitize_run_once_var(role_name: str) str¶
Generate run_once variable name from role name. Example: ‘sys-front-inj-logout’ -> ‘run_once_sys_front_inj_logout’
- cli.fix.move_unnecessary_dependencies.sq(v: str)¶
Return a single-quoted scalar (ruamel) for consistent quoting.
- cli.fix.move_unnecessary_dependencies.update_meta_remove_deps(meta_path: str, remove: List[str], dry_run: bool)¶
Remove entries from meta.dependencies while leaving the rest of the file intact. Quotes, comments, key order, and line breaks are preserved. Returns True if a change would be made (or was made when not in dry-run).