MCPcopy Index your code
hub / github.com/RustPython/RustPython / _copy_single

Function _copy_single

scripts/update_lib/cmd_copy_lib.py:19–46  ·  view source on GitHub ↗

Copy a single file or directory.

(
    src_path: pathlib.Path,
    lib_path: pathlib.Path,
    verbose: bool = True,
)

Source from the content-addressed store, hash-verified

17
18
19def _copy_single(
20 src_path: pathlib.Path,
21 lib_path: pathlib.Path,
22 verbose: bool = True,
23) -> None:
24 """Copy a single file or directory."""
25 # Remove existing file/directory
26 if lib_path.exists():
27 if lib_path.is_dir():
28 if verbose:
29 print(f"Removing directory: {lib_path}")
30 shutil.rmtree(lib_path)
31 else:
32 if verbose:
33 print(f"Removing file: {lib_path}")
34 lib_path.unlink()
35
36 # Copy
37 if src_path.is_dir():
38 if verbose:
39 print(f"Copying directory: {src_path} -> {lib_path}")
40 lib_path.parent.mkdir(parents=True, exist_ok=True)
41 shutil.copytree(src_path, lib_path)
42 else:
43 if verbose:
44 print(f"Copying file: {src_path} -> {lib_path}")
45 lib_path.parent.mkdir(parents=True, exist_ok=True)
46 shutil.copy2(src_path, lib_path)
47
48
49def copy_lib(

Callers 4

test_copies_fileMethod · 0.90
test_copies_directoryMethod · 0.90
copy_libFunction · 0.85

Calls 5

printFunction · 0.50
existsMethod · 0.45
is_dirMethod · 0.45
unlinkMethod · 0.45
mkdirMethod · 0.45

Tested by 3

test_copies_fileMethod · 0.72
test_copies_directoryMethod · 0.72