Skip to content

Commit

Permalink
Update for CookieCutter v2.4.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Oct 8, 2023
1 parent 8e3c0be commit c18c0bc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ See also git tags: https://github.com/jedie/manageprojects/tags
[comment]: <> (✂✂✂ auto generated history start ✂✂✂)

* [**dev**](https://github.com/jedie/manageprojects/compare/v0.15.0...main)
* 2023-10-08 - Update for CookieCutter v2.4.0 changes
* 2023-10-08 - Autogenerate history via https://github.com/jedie/cli-base-utilities
* 2023-09-24 - apply migrations
* 2023-09-24 - Update requirements
Expand Down
9 changes: 4 additions & 5 deletions manageprojects/cookiecutter_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

from bx_py_utils.path import assert_is_dir
from cli_base.cli_tools.git import Git
from cookiecutter import generate
from cookiecutter.config import get_user_config
from cookiecutter.main import cookiecutter
from cookiecutter.repository import determine_repo_dir

from manageprojects.utilities.cookiecutter_utils import CookieCutterHookHandler
from manageprojects.utilities.cookiecutter_utils import GenerateFilesWrapper
from manageprojects.utilities.log_utils import log_func_call


Expand Down Expand Up @@ -87,8 +86,8 @@ def execute_cookiecutter(
password=password,
config_file=config_file,
)
run_hook = CookieCutterHookHandler(origin_run_hook=generate.run_hook)
with patch.object(generate, 'run_hook', run_hook):
generate_files_wrapper = GenerateFilesWrapper()
with patch('cookiecutter.main.generate_files', generate_files_wrapper):
destination = log_func_call(
logger=logger,
func=cookiecutter,
Expand All @@ -102,7 +101,7 @@ def execute_cookiecutter(
password=password,
config_file=config_file,
)
cookiecutter_context = run_hook.context
cookiecutter_context = generate_files_wrapper.context
logger.info('Cookiecutter context: %r', cookiecutter_context)
destination_path = Path(destination)
assert_is_dir(destination_path)
Expand Down
20 changes: 10 additions & 10 deletions manageprojects/utilities/cookiecutter_utils.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import logging

from cookiecutter.generate import generate_files


logger = logging.getLogger(__name__)


class CookieCutterHookHandler:
class GenerateFilesWrapper:
"""
Capture the effective Cookiecutter Template Context via injecting the Cookiecutter hooks.
Capture the effective Cookiecutter Template Context
"""

def __init__(self, origin_run_hook):
self.origin_run_hook = origin_run_hook
self.context = {}
def __init__(self):
self.context = None

def __call__(self, hook_name, project_dir, context):
logger.debug('Hook %r for %r context: %r', hook_name, project_dir, context)
origin_hook_result = self.origin_run_hook(hook_name, project_dir, context)
self.context.update(context)
return origin_hook_result
def __call__(self, **kwargs):
logger.debug('GenerateFilesWrapper called with: %s', kwargs)
self.context = kwargs['context']
return generate_files(**kwargs)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
]
requires-python = ">=3.9,<4"
dependencies = [
"cookiecutter", # https://github.com/cookiecutter/cookiecutter
"cookiecutter>=2.4.0", # https://github.com/cookiecutter/cookiecutter
"tomlkit",
"EditorConfig", # https://github.com/editorconfig/editorconfig-core-py

Expand Down

0 comments on commit c18c0bc

Please sign in to comment.