[Python-modules-commits] [cookiecutter] 01/12: Make the build reproducible by avoiding nondeterministic kwargs

Vincent Bernat bernat at moszumanska.debian.org
Tue Oct 25 07:12:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

bernat pushed a commit to branch master
in repository cookiecutter.

commit cc0a71fcdb9fcda5552eca0a7766c59fdda3ce34
Author: Chris Lamb <chris at chris-lamb.co.uk>
Date:   Sat Aug 20 00:08:07 2016 +0100

    Make the build reproducible by avoiding nondeterministic kwargs
    
    Whilst working on the Reproducible Builds effort [0], I noticed
    that cookiecutter could not be built reproducibly.
    
    As USER_CONFIG_PATH is pased on expanding ~ this varies between different
    systems, meaning that building the documentation on a different machine (or
    with a different $HOME) ends up with a different result:
    
     - [..] config_file=u'/nonexistent/first-build/.cookiecutterrc' [..]
     + [..] config_file=u'/nonexistent/second-build/.cookiecutterrc' [..]
    
    I would normally just change this to ``config_file=None`` and set it at
    runtime, but we need to be clever with NOT_PROVIDED to tell the difference
    between the case where we *actually* pass ``None`..
    
     [0] https://reproducible-builds.org/
    
    Signed-off-by: Chris Lamb <chris at chris-lamb.co.uk>
---
 cookiecutter/config.py | 7 ++++++-
 cookiecutter/main.py   | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/cookiecutter/config.py b/cookiecutter/config.py
index af9e83c..ff3556b 100755
--- a/cookiecutter/config.py
+++ b/cookiecutter/config.py
@@ -22,6 +22,7 @@ from .exceptions import InvalidConfiguration
 
 logger = logging.getLogger(__name__)
 
+NOT_PROVIDED = object()
 USER_CONFIG_PATH = os.path.expanduser('~/.cookiecutterrc')
 
 DEFAULT_CONFIG = {
@@ -68,7 +69,7 @@ def get_config(config_path):
     return config_dict
 
 
-def get_user_config(config_file=USER_CONFIG_PATH):
+def get_user_config(config_file=NOT_PROVIDED):
     """Retrieve the config from a file or return the defaults if None is
     passed. If an environment variable `COOKIECUTTER_CONFIG` is set up, try
     to load its value. Otherwise fall back to a default file or config.
@@ -77,6 +78,10 @@ def get_user_config(config_file=USER_CONFIG_PATH):
     if config_file is None:
         return copy.copy(DEFAULT_CONFIG)
 
+    # Differentiate between being passed ``None`` and the default.
+    if config_file is NOT_PROVIDED:
+        config_file = USER_CONFIG_PATH
+
     # Load the given config file
     if config_file and config_file is not USER_CONFIG_PATH:
         return get_config(config_file)
diff --git a/cookiecutter/main.py b/cookiecutter/main.py
index d8ff7b6..d946398 100755
--- a/cookiecutter/main.py
+++ b/cookiecutter/main.py
@@ -16,7 +16,7 @@ import logging
 import os
 import re
 
-from .config import get_user_config, USER_CONFIG_PATH
+from .config import get_user_config, USER_CONFIG_PATH, NOT_PROVIDED
 from .exceptions import InvalidModeException, RepositoryNotFound
 from .prompt import prompt_for_config
 from .generate import generate_context, generate_files
@@ -71,7 +71,7 @@ def expand_abbreviations(template, config_dict):
 def cookiecutter(
         template, checkout=None, no_input=False, extra_context=None,
         replay=False, overwrite_if_exists=False, output_dir='.',
-        config_file=USER_CONFIG_PATH):
+        config_file=NOT_PROVIDED):
     """
     API equivalent to using Cookiecutter at the command line.
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/cookiecutter.git



More information about the Python-modules-commits mailing list