Skip to content

Cookiecutter fails to get config if the .cookiecutterrc is an empty file #1994

@apirogov

Description

@apirogov
  • Cookiecutter version: 2.5.0
  • Python version: 3.8
  • Operating System: Linux

Description:

When using get_user_config(), the method fails with an exception instead of returning default values, if the .cookiecutterrc file exists, but is empty.

Stacktrace:

>>> get_user_config()
Traceback (most recent call last):
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/fair-python-cookiecutter-Y_dY9N1_-py3.8/lib/python3.8/site-packages/cookiecutter/config.py", line 115, in get_user_config
    env_config_file = os.environ['COOKIECUTTER_CONFIG']
  File "/local/home/a.pirogov/.pyenv/versions/3.8.17/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'COOKIECUTTER_CONFIG'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/fair-python-cookiecutter-Y_dY9N1_-py3.8/lib/python3.8/site-packages/cookiecutter/config.py", line 121, in get_user_config
    return get_config(USER_CONFIG_PATH)
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/fair-python-cookiecutter-Y_dY9N1_-py3.8/lib/python3.8/site-packages/cookiecutter/config.py", line 69, in get_config
    config_dict = merge_configs(DEFAULT_CONFIG, yaml_dict)
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/fair-python-cookiecutter-Y_dY9N1_-py3.8/lib/python3.8/site-packages/cookiecutter/config.py", line 44, in merge_configs
    for k, v in overwrite.items():
AttributeError: 'NoneType' object has no attribute 'items'

What I've run:

Just have an empty .cookiecutterrc and run get_user_config().

Expected behavior:

This exception should not happen, a missing .cookiecutterrc should be treated the same as an empty one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions