Skip to content

Commit

Permalink
pydocstyle for utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dornheimer committed Dec 27, 2017
1 parent e70ec5a commit bbec552
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions cookiecutter/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# -*- coding: utf-8 -*-

"""
cookiecutter.utils
------------------
Helper functions used throughout Cookiecutter.
"""
"""Helper functions used throughout Cookiecutter."""

from __future__ import unicode_literals
import contextlib
Expand All @@ -22,33 +17,28 @@


def force_delete(func, path, exc_info):
"""
Error handler for `shutil.rmtree()` equivalent to `rm -rf`
"""Error handler for `shutil.rmtree()` equivalent to `rm -rf`.
Usage: `shutil.rmtree(path, onerror=force_delete)`
From stackoverflow.com/questions/1889597
"""

os.chmod(path, stat.S_IWRITE)
func(path)


def rmtree(path):
"""
Removes a directory and all its contents. Like rm -rf on Unix.
"""Remove a directory and all its contents. Like rm -rf on Unix.
:param path: A directory path.
"""

shutil.rmtree(path, onerror=force_delete)


def make_sure_path_exists(path):
"""
Ensures that a directory exists.
"""Ensure that a directory exists.
:param path: A directory path.
"""

logger.debug('Making sure path exists: {}'.format(path))
try:
os.makedirs(path)
Expand All @@ -61,9 +51,9 @@ def make_sure_path_exists(path):

@contextlib.contextmanager
def work_in(dirname=None):
"""
Context manager version of os.chdir. When exited, returns to the working
directory prior to entering.
"""Context manager version of os.chdir.
When exited, returns to the working directory prior to entering.
"""
curdir = os.getcwd()
try:
Expand All @@ -75,8 +65,7 @@ def work_in(dirname=None):


def make_executable(script_path):
"""
Makes `script_path` executable
"""Make `script_path` executable.
:param script_path: The file to change
"""
Expand All @@ -85,8 +74,8 @@ def make_executable(script_path):


def prompt_and_delete(path, no_input=False):
"""Ask the user whether it's okay to delete the previously-downloaded
file/directory.
"""
Ask user if it's okay to delete the previously-downloaded file/directory.
If yes, delete it. If no, checks to see if the old version should be
reused. If yes, it's reused; otherwise, Cookiecutter exits.
Expand Down

0 comments on commit bbec552

Please sign in to comment.