MCPcopy
hub / github.com/dlt-hub/dlt / _clone

Method _clone

dlt/extract/resource.py:748–797  ·  view source on GitHub ↗

Creates a deep copy of a current resource, optionally renaming the resource. The clone will not be part of the source and will not include the custom resource metrics.

(
        self, *, new_name: str = None, new_section: str = None, with_parent: bool = False
    )

Source from the content-addressed store, hash-verified

746 return self
747
748 def _clone(
749 self, *, new_name: str = None, new_section: str = None, with_parent: bool = False
750 ) -> Self:
751 """Creates a deep copy of a current resource, optionally renaming the resource.
752 The clone will not be part of the source and will not include the custom resource metrics.
753 """
754 pipe = self._pipe
755 if pipe and not pipe.is_empty:
756 pipe = pipe._clone(new_name=new_name)
757 # assign new instance id
758 pipe.instance_id = uniq_id()
759
760 # incremental and parent are already in the pipe (if any)
761 incremental = self.incremental
762 if isinstance(incremental, IncrementalResourceWrapper):
763 incremental_from_hints: Optional[bool] = incremental._from_hints
764 else:
765 incremental_from_hints = None
766 cloned_r = self.__class__(
767 pipe,
768 self._clone_hints(self._hints),
769 selected=self.selected,
770 section=new_section or self.section,
771 args_bound=self._args_bound,
772 )
773
774 # keep the parent
775 cloned_r._parent = self._parent
776 # also clone parent if requested
777 if with_parent and cloned_r._parent and not cloned_r._parent._pipe.is_empty:
778 parent_new_name = new_name
779 # if we are renaming the resource, then also rename the parent
780 if new_name:
781 # if original names contained common element, then continue that pattern
782 if self.name in self._parent.name:
783 parent_new_name = cloned_r._parent.name.replace(self.name, new_name)
784 else:
785 parent_new_name = f"{self._parent.name}_{new_name}"
786
787 cloned_r._parent = cloned_r._parent._clone(
788 new_name=parent_new_name, new_section=new_section, with_parent=with_parent
789 )
790 cloned_r._pipe.parent = cloned_r._parent._pipe
791
792 # try to eject and then inject configuration and incremental wrapper when resource is cloned
793 # this makes sure that a take config values from a right section and wrapper has a separated
794 # instance in the pipeline
795 if cloned_r._eject_config():
796 cloned_r._inject_config(incremental_from_hints_override=incremental_from_hints)
797 return cloned_r
798
799 def _update_wrapper(self) -> None:
800 """Update wrapper from callable pipe gen to behave as functools wrapper"""

Callers 2

with_nameMethod · 0.95
__call__Method · 0.95

Calls 4

uniq_idFunction · 0.90
_clone_hintsMethod · 0.80
_eject_configMethod · 0.80
_inject_configMethod · 0.80

Tested by

no test coverage detected