Path 1: 22 calls (0.96)

['a/b/__init__.py'] (5) ['a/b/__init__.py', 'a/c/__init__.py'] (4) ['a/b/c/__init__.py', 'a/d/__init__.py', 'a/e/f.py'] (3) ['a/pylintrc', 'a/b/__init...

'.' (21) '/private/var/folders/yp/qx0crmvd4sbck7chb52sws500000gn/T/tmp3xfxk5pi' (1)

1def create_files(paths: list[str], chroot: str = ".") -> None:
2    """Creates directories and files found in <path>.
3
4    :param list paths: list of relative paths to files or directories
5    :param str chroot: the root directory in which paths will be created
6
7    >>> from os.path import isdir, isfile
8    >>> isdir('/tmp/a')
9    False
10    >>> create_files(['a/b/foo.py', 'a/b/c/', 'a/b/c/d/e.py'], '/tmp')
11    >>> isdir('/tmp/a')
12    True
13    >>> isdir('/tmp/a/b/c')
14    True
15    >>> isfile('/tmp/a/b/c/d/e.py')
16    True
17    >>> isfile('/tmp/a/b/foo.py')
18    True
19    """
20    dirs, files = set(), set()
21    for path in paths:
22        path = os.path.join(chroot, path)
23        filename = os.path.basename(path)
24        # path is a directory path
25        if not filename:
26            dirs.add(path)
27        # path is a filename path
28        else:
29            dirs.add(os.path.dirname(path))
30            files.add(path)
31    for dirpath in dirs:
32        if not os.path.isdir(dirpath):
33            os.makedirs(dirpath)
34    for filepath in files:
35        with open(filepath, "w", encoding="utf-8"):
36            pass
            

Path 2: 1 calls (0.04)

['changing.py'] (1)

'/var/folders/yp/qx0crmvd4sbck7chb52sws500000gn/T/tmp69gv67af' (1)

1def create_files(paths: list[str], chroot: str = ".") -> None:
2    """Creates directories and files found in <path>.
3
4    :param list paths: list of relative paths to files or directories
5    :param str chroot: the root directory in which paths will be created
6
7    >>> from os.path import isdir, isfile
8    >>> isdir('/tmp/a')
9    False
10    >>> create_files(['a/b/foo.py', 'a/b/c/', 'a/b/c/d/e.py'], '/tmp')
11    >>> isdir('/tmp/a')
12    True
13    >>> isdir('/tmp/a/b/c')
14    True
15    >>> isfile('/tmp/a/b/c/d/e.py')
16    True
17    >>> isfile('/tmp/a/b/foo.py')
18    True
19    """
20    dirs, files = set(), set()
21    for path in paths:
22        path = os.path.join(chroot, path)
23        filename = os.path.basename(path)
24        # path is a directory path
25        if not filename:
26            dirs.add(path)
27        # path is a filename path
28        else:
29            dirs.add(os.path.dirname(path))
30            files.add(path)
31    for dirpath in dirs:
32        if not os.path.isdir(dirpath):
33            os.makedirs(dirpath)
34    for filepath in files:
35        with open(filepath, "w", encoding="utf-8"):
36            pass