Skip to content

Transfer

CpDef dataclass

CpDef(src: Path, dst: Path, mv: list[str], dry_run: bool = False, escalate: bool = False, cls_defs: bool = False, func_defs: bool = False, verbose: bool = False, _copy_mode: bool = True)

Bases: MvDef

Copy function definitions from one file to another, and any necessary associated import statements along with them.

Option Description Type Default —————————— —————————————————————————————————————————— ——————————— ——————— • src source file to copy definitions from Path - • dst destination file (may not exist) Path - • mv names to copy from the source file list[str] - • dry_run whether to only preview the change diffs bool False • escalate whether to raise an error upon failure bool False • cls_defs whether to use only class definitions bool False • func_defs whether to use only function definitions bool False • verbose whether to log anything bool False

diffs

diffs(print_out: bool = False) -> str

Calls Agenda.populate_agenda() explicitly for the src file, and implicitly for the dst file by Agenda.unidiff(), and returns a single diff string for dst.

Source code in src/mvdef/transfer/copy.py
def diffs(self, print_out: bool = False) -> str:
    """
    Calls `Agenda.populate_agenda()` explicitly for the src file, and implicitly for
    the dst file by `Agenda.unidiff()`, and returns a single diff string for dst.
    """
    # Necessary to populate the Agenda to set up its Checker (becomes `source_ref`)
    if self.src_diff.agenda.empty:
        self.src_diff.populate_agenda()
    dst_unidiff = self.dst_diff.unidiff()
    if print_out:
        print(dst_unidiff)
    return dst_unidiff

LsDef dataclass

LsDef(src: Path, match: list[str] = lambda: ['*'](), dry_run: bool = False, list: bool = False, escalate: bool = False, cls_defs: bool = False, func_defs: bool = False, verbose: bool = False)

Bases: MvDefBase

List function definitions in a given file.

Option Description Type Default —————————— —————————————————————————————————————————— ——————————— ——————— • src source file to list definitions from Path - • match name regex to list from the source file list[str] ['*'] • dry_run whether to print the all diff bool False • list whether to print the list of names bool False • escalate whether to raise an error upon failure bool False • cls_defs whether to use only class definitions bool False • func_defs whether to use only function definitions bool False • verbose whether to log anything bool False

manif

manif(print_out: bool = False) -> str

Calls Agenda.populate_agenda() explicitly if not yet created, and returns a single diff string.

Source code in src/mvdef/transfer/list.py
def manif(self, print_out: bool = False) -> str:
    """
    Calls `Agenda.populate_agenda()` explicitly if not yet created,
    and returns a single diff string.
    """
    if self.src_manifest.agenda.empty:
        self.src_manifest.populate_agenda()
    src_manif = self.src_manifest.fill()
    if print_out:
        print(src_manif)
    return src_manif

MvDef dataclass

MvDef(src: Path, dst: Path, mv: list[str], dry_run: bool = False, escalate: bool = False, cls_defs: bool = False, func_defs: bool = False, verbose: bool = False, _copy_mode: bool = False)

Bases: MvDefBase

Move function definitions from one file to another, moving/copying any necessary associated import statements along with them.

Option Description Type Default —————————— —————————————————————————————————————————— ——————————— ——————— • src source file to take definitions from Path - • dst destination file (may not exist) Path - • mv names to move from the source file list[str] - • dry_run whether to only preview the change diffs bool False • escalate whether to raise an error upon failure bool False • cls_defs whether to use only class definitions bool False • func_defs whether to use only function definitions bool False • verbose whether to log anything bool False

diffs

diffs(print_out: bool = False) -> tuple[str, str]

Calls Agenda.populate_agenda() implicitly by Agenda.unidiff() and returns 2 diff strings for src and dst respectively. If only copying (not editing src), just populates the agenda and returns a single diff string.

Source code in src/mvdef/transfer/move.py
def diffs(self, print_out: bool = False) -> tuple[str, str]:
    """
    Calls `Agenda.populate_agenda()` implicitly by `Agenda.unidiff()` and returns 2
    diff strings for src and dst respectively. If only copying (not editing src),
    just populates the agenda and returns a single diff string.
    """
    if self._copy_mode and self.src_diff.agenda.empty:
        # Must populate the Agenda to set up associated Checker ("ref")... I think?
        self.src_diff.populate_agenda()
        src_unidiff = ""
    else:
        src_unidiff = self.src_diff.unidiff()
    dst_unidiff = self.dst_diff.unidiff()
    if print_out:
        for diff in filter(None, [src_unidiff, dst_unidiff]):
            print(diff)
    return dst_unidiff if self._copy_mode else src_unidiff, dst_unidiff

move

move() -> None

Execute diffs

Source code in src/mvdef/transfer/move.py
def move(self) -> None:
    """Execute diffs"""
    if not self.dry_run:
        if not self._copy_mode:
            self.src_diff.execute()
        self.dst_diff.execute()
    return

base

MvDefBase dataclass

MvDefBase()

Bases: FailableMixIn

Common methods (allowing LsDef to have a different signature to MvDef/CpDef)

Implementation note: :attr:_check_kw and :attr:_diff_kw are stored as class attributes (by virtue of being un-type annotated, due to how dataclasses work). They are single-underscore prefixed to avoid name clash with the properties of the same [but unprefixed] names.

all_defs property

all_defs: bool

If neither exclusively classdefs or exclusively funcdefs, use both.

clsvar_fetch classmethod

clsvar_fetch(name: str) -> list[bool]

Fetch the sum list of the named classvar on all ancestors, by walking the MRO down to MvDefBase, skipping any classes without the classvar explicitly set.

Source code in src/mvdef/transfer/base.py
@classmethod
def clsvar_fetch(cls, name: str) -> list[bool]:
    """
    Fetch the sum list of the named classvar on all ancestors, by walking the MRO
    down to `MvDefBase`, skipping any classes without the classvar explicitly set.
    """
    cls_name = getattr(cls, name)
    if is_not_base_cls := (super().__thisclass__ is not cls):
        parent_cls_name = getattr((parent_cls := cls.mro()[1]), name)
        add = [] if cls_name == parent_cls_name else cls_name  # skip if falls thru
        result = parent_cls.clsvar_fetch(name=name) + add
    return result if is_not_base_cls else cls_name

check

check() -> CheckFailure | None

Returns None if check succeeds, or returns the CheckFailure for the first blocker found upon checking that the file parses correctly (the function will raise errors rather than returning them in 'escalate' mode, to help debugging).

Source code in src/mvdef/transfer/base.py
def check(self) -> CheckFailure | None:
    """
    Returns None if check succeeds, or returns the `CheckFailure` for the first
    blocker found upon checking that the file parses correctly (the function will
    raise errors rather than returning them in 'escalate' mode, to help debugging).
    """
    raise NotImplementedError("Implemented on subclass")

copy

CpDef dataclass

CpDef(src: Path, dst: Path, mv: list[str], dry_run: bool = False, escalate: bool = False, cls_defs: bool = False, func_defs: bool = False, verbose: bool = False, _copy_mode: bool = True)

Bases: MvDef

Copy function definitions from one file to another, and any necessary associated import statements along with them.

Option Description Type Default —————————— —————————————————————————————————————————— ——————————— ——————— • src source file to copy definitions from Path - • dst destination file (may not exist) Path - • mv names to copy from the source file list[str] - • dry_run whether to only preview the change diffs bool False • escalate whether to raise an error upon failure bool False • cls_defs whether to use only class definitions bool False • func_defs whether to use only function definitions bool False • verbose whether to log anything bool False

diffs

diffs(print_out: bool = False) -> str

Calls Agenda.populate_agenda() explicitly for the src file, and implicitly for the dst file by Agenda.unidiff(), and returns a single diff string for dst.

Source code in src/mvdef/transfer/copy.py
def diffs(self, print_out: bool = False) -> str:
    """
    Calls `Agenda.populate_agenda()` explicitly for the src file, and implicitly for
    the dst file by `Agenda.unidiff()`, and returns a single diff string for dst.
    """
    # Necessary to populate the Agenda to set up its Checker (becomes `source_ref`)
    if self.src_diff.agenda.empty:
        self.src_diff.populate_agenda()
    dst_unidiff = self.dst_diff.unidiff()
    if print_out:
        print(dst_unidiff)
    return dst_unidiff

list

LsDef dataclass

LsDef(src: Path, match: list[str] = lambda: ['*'](), dry_run: bool = False, list: bool = False, escalate: bool = False, cls_defs: bool = False, func_defs: bool = False, verbose: bool = False)

Bases: MvDefBase

List function definitions in a given file.

Option Description Type Default —————————— —————————————————————————————————————————— ——————————— ——————— • src source file to list definitions from Path - • match name regex to list from the source file list[str] ['*'] • dry_run whether to print the all diff bool False • list whether to print the list of names bool False • escalate whether to raise an error upon failure bool False • cls_defs whether to use only class definitions bool False • func_defs whether to use only function definitions bool False • verbose whether to log anything bool False

manif

manif(print_out: bool = False) -> str

Calls Agenda.populate_agenda() explicitly if not yet created, and returns a single diff string.

Source code in src/mvdef/transfer/list.py
def manif(self, print_out: bool = False) -> str:
    """
    Calls `Agenda.populate_agenda()` explicitly if not yet created,
    and returns a single diff string.
    """
    if self.src_manifest.agenda.empty:
        self.src_manifest.populate_agenda()
    src_manif = self.src_manifest.fill()
    if print_out:
        print(src_manif)
    return src_manif

move

MvDef dataclass

MvDef(src: Path, dst: Path, mv: list[str], dry_run: bool = False, escalate: bool = False, cls_defs: bool = False, func_defs: bool = False, verbose: bool = False, _copy_mode: bool = False)

Bases: MvDefBase

Move function definitions from one file to another, moving/copying any necessary associated import statements along with them.

Option Description Type Default —————————— —————————————————————————————————————————— ——————————— ——————— • src source file to take definitions from Path - • dst destination file (may not exist) Path - • mv names to move from the source file list[str] - • dry_run whether to only preview the change diffs bool False • escalate whether to raise an error upon failure bool False • cls_defs whether to use only class definitions bool False • func_defs whether to use only function definitions bool False • verbose whether to log anything bool False

diffs

diffs(print_out: bool = False) -> tuple[str, str]

Calls Agenda.populate_agenda() implicitly by Agenda.unidiff() and returns 2 diff strings for src and dst respectively. If only copying (not editing src), just populates the agenda and returns a single diff string.

Source code in src/mvdef/transfer/move.py
def diffs(self, print_out: bool = False) -> tuple[str, str]:
    """
    Calls `Agenda.populate_agenda()` implicitly by `Agenda.unidiff()` and returns 2
    diff strings for src and dst respectively. If only copying (not editing src),
    just populates the agenda and returns a single diff string.
    """
    if self._copy_mode and self.src_diff.agenda.empty:
        # Must populate the Agenda to set up associated Checker ("ref")... I think?
        self.src_diff.populate_agenda()
        src_unidiff = ""
    else:
        src_unidiff = self.src_diff.unidiff()
    dst_unidiff = self.dst_diff.unidiff()
    if print_out:
        for diff in filter(None, [src_unidiff, dst_unidiff]):
            print(diff)
    return dst_unidiff if self._copy_mode else src_unidiff, dst_unidiff

move

move() -> None

Execute diffs

Source code in src/mvdef/transfer/move.py
def move(self) -> None:
    """Execute diffs"""
    if not self.dry_run:
        if not self._copy_mode:
            self.src_diff.execute()
        self.dst_diff.execute()
    return