Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "refactor: replace distutils' copy_tree with shutil copytree" #1134

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions kapitan/initialiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,30 @@

import logging
import os
from pathlib import Path

from kapitan.utils import copy_tree
from distutils.dir_util import copy_tree

logger = logging.getLogger(__name__)


def initialise_skeleton(args):
"""Initialises a directory with a recommended skeleton structure and prints list of
copied files.

"""Initialises a directory with a recommended skeleton structure
Args:
args.directory (string): path which to initialise, directory is assumed to exist.
args.directory (string): path which to initialise, directory is assumed to exist
"""
templates = Path(__file__).resolve().parent.joinpath("inputs", "templates")
destination = Path(args.directory)
copied_files = copy_tree(source=templates, destination=destination, dirs_exist_ok=True)

current_pwd = os.path.dirname(__file__)
templates_directory = os.path.join(current_pwd, "inputs", "templates")
populated = copy_tree(templates_directory, args.directory)
logger.info("Populated %s with:", args.directory)
for directory, _, file_list in os.walk(args.directory):
for directory, subs, file_list in os.walk(args.directory):
# In order to avoid adding the given directory itself in listing.
if directory == args.directory:
continue
if any([path.startswith(directory) for path in copied_files]):
if any([path.startswith(directory) for path in populated]):
level = directory.replace(args.directory, "").count(os.sep) - 1
indent = " " * 4 * (level)
logger.info("%s%s", indent, os.path.basename(directory))
for fname in file_list:
if os.path.join(directory, fname) in copied_files:
if os.path.join(directory, fname) in populated:
sub_indent = " " * 4 * (level + 1)
logger.info("%s%s", sub_indent, fname)
19 changes: 0 additions & 19 deletions kapitan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
from distutils.file_util import _copy_file_contents
from functools import lru_cache, wraps
from hashlib import sha256
from pathlib import Path
from shutil import copytree
from typing import List
from zipfile import ZipFile

import jinja2
Expand Down Expand Up @@ -631,19 +628,3 @@ def safe_copy_tree(src, dst):
outputs.append(dst_name)

return outputs


def copy_tree(source: Path, destination: Path, dirs_exist_ok: bool = False) -> List[str]:
"""Recursively copy a given directory from `source` to `destination` using shutil.copytree
and return list of copied files. When `dirs_exist_ok` is set, the `FileExistsError` is
ignored when destination directory exists.
Args:
source (str): Path to a source directory
destination (str): Path to a destination directory
Returns:
list[str]: List of copied files
"""
inventory_before = list(destination.rglob("*"))
copytree(source, destination, dirs_exist_ok=dirs_exist_ok)
inventory_after = list(destination.rglob("*"))
return [str(d) for d in inventory_after if d not in inventory_before]
81 changes: 0 additions & 81 deletions tests/test_utils.py

This file was deleted.

Loading