MCPcopy Index your code
hub / github.com/CodeClash-ai/CodeClash / copy_to_container

Function copy_to_container

codeclash/utils/environment.py:102–132  ·  view source on GitHub ↗

Copy a file or directory from the local filesystem to a Docker container. The copy operation is recursive for directories. Be extremely careful with trailing slashes in src_path and dest_path, the behavior of docker cp is also different depending on whether the destination exists.

(
    container: DockerEnvironment,
    src_path: str | Path,
    dest_path: str | Path,
)

Source from the content-addressed store, hash-verified

100
101
102def copy_to_container(
103 container: DockerEnvironment,
104 src_path: str | Path,
105 dest_path: str | Path,
106):
107 """
108 Copy a file or directory from the local filesystem to a Docker container.
109
110 The copy operation is recursive for directories.
111
112 Be extremely careful with trailing slashes in src_path and dest_path, the behavior
113 of docker cp is also different depending on whether the destination exists.
114 """
115 if not str(dest_path).startswith("/"):
116 # If not an absolute path, assume relative to container's cwd
117 dest_path = f"{container.config.cwd}/{dest_path}"
118 cmd = [
119 "docker",
120 "cp",
121 str(src_path),
122 f"{container.container_id}:{dest_path}",
123 ]
124 print(f"Copy to container: cmd={cmd}")
125 # Ensure destination folder exists
126 assert_zero_exit_code(container.execute(f"mkdir -p {Path(dest_path).parent}"))
127 result = subprocess.run(cmd, check=False, capture_output=True, text=True)
128 if result.returncode != 0:
129 raise RuntimeError(
130 f"Failed to copy {src_path} to {container.container_id}:{dest_path}: {result.stdout}{result.stderr}"
131 )
132 return result
133
134
135def copy_from_container(

Callers 4

runMethod · 0.90
run_edit_phaseMethod · 0.90
run_training_roundMethod · 0.90
create_file_in_containerFunction · 0.85

Calls 3

assert_zero_exit_codeFunction · 0.85
executeMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected