MCPcopy Create free account
hub / github.com/conda/constructor / copy_extra_files

Function copy_extra_files

constructor/preconda.py:362–398  ·  view source on GitHub ↗

Copy list of extra files to a working directory Args: extra_files: A path or a mapping workdir: Path to where extra files will be copied to. Raises: FileNotFoundError: Raises when the file isn't found. Returns: list[os.PathLike]: List of normalized path

(
    extra_files: list[os.PathLike | Mapping], workdir: os.PathLike
)

Source from the content-addressed store, hash-verified

360
361
362def copy_extra_files(
363 extra_files: list[os.PathLike | Mapping], workdir: os.PathLike
364) -> list[os.PathLike]:
365 """Copy list of extra files to a working directory
366
367 Args:
368 extra_files: A path or a mapping
369 workdir: Path to where extra files will be copied to.
370
371 Raises:
372 FileNotFoundError: Raises when the file isn't found.
373
374 Returns:
375 list[os.PathLike]: List of normalized paths of copied locations.
376 """
377
378 def validate_file_path(file_path: str) -> Path:
379 fpath = Path(file_path)
380 if not fpath.exists():
381 raise FileNotFoundError(f"File {file_path} does not exist.")
382 return fpath
383
384 if not extra_files:
385 return []
386 copied = []
387 for path in extra_files:
388 if isinstance(path, str):
389 orig_path = validate_file_path(path)
390 copied.append(shutil.copy(orig_path, workdir))
391 elif isinstance(path, dict):
392 assert len(path) == 1
393 origin, destination = next(iter(path.items()))
394 orig_path = validate_file_path(origin)
395 dest_path = Path(workdir) / destination
396 dest_path.parent.mkdir(parents=True, exist_ok=True)
397 copied.append(shutil.copy(orig_path, dest_path))
398 return copied

Callers 2

createFunction · 0.85
createFunction · 0.85

Calls 1

validate_file_pathFunction · 0.85

Tested by

no test coverage detected