MCPcopy Index your code
hub / github.com/pyinvoke/invoke / transform

Method transform

invoke/collection.py:456–493  ·  view source on GitHub ↗

Transform ``name`` with the configured auto-dashes behavior. If the collection's ``auto_dash_names`` attribute is ``True`` (default), all non leading/trailing underscores are turned into dashes. (Leading/trailing underscores tend to get stripped elsewhere in the

(self, name: str)

Source from the content-addressed store, hash-verified

454 )
455
456 def transform(self, name: str) -> str:
457 """
458 Transform ``name`` with the configured auto-dashes behavior.
459
460 If the collection's ``auto_dash_names`` attribute is ``True``
461 (default), all non leading/trailing underscores are turned into dashes.
462 (Leading/trailing underscores tend to get stripped elsewhere in the
463 stack.)
464
465 If it is ``False``, the inverse is applied - all dashes are turned into
466 underscores.
467
468 .. versionadded:: 1.0
469 """
470 # Short-circuit on anything non-applicable, e.g. empty strings, bools,
471 # None, etc.
472 if not name:
473 return name
474 from_, to = "_", "-"
475 if not self.auto_dash_names:
476 from_, to = "-", "_"
477 replaced = []
478 end = len(name) - 1
479 for i, char in enumerate(name):
480 # Don't replace leading or trailing underscores (+ taking dotted
481 # names into account)
482 # TODO: not 100% convinced of this / it may be exposing a
483 # discrepancy between this level & higher levels which tend to
484 # strip out leading/trailing underscores entirely.
485 if (
486 i not in (0, end)
487 and char == from_
488 and name[i - 1] != "."
489 and name[i + 1] != "."
490 ):
491 char = to
492 replaced.append(char)
493 return "".join(replaced)
494
495 def _transform_lexicon(self, old: Lexicon) -> Lexicon:
496 """

Callers 8

__init__Method · 0.95
add_taskMethod · 0.95
add_collectionMethod · 0.95
task_with_configMethod · 0.95
subtask_nameMethod · 0.95
_transform_lexiconMethod · 0.95
serializedMethod · 0.95
from_moduleMethod · 0.80

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected