Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package name example shows "-" but errors if used #65

Open
1 of 3 tasks
Dominic-Duke opened this issue Mar 7, 2025 · 2 comments
Open
1 of 3 tasks

Package name example shows "-" but errors if used #65

Dominic-Duke opened this issue Mar 7, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@Dominic-Duke
Copy link
Contributor

What happened?

In step 7 of setup under package_name there are examples given that include - characters (adding arup- for example), but when a name with a - is used, this errors once having completed all 20 steps. This is particularly annoying when using a repo name which includes a - as it defaults to the same for package_name when it appears this is an invalid input (and yes I realise I could've just pressed enter instead of typing out the name again).

Image

Image

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

Version

v0.2.0

Relevant log output

ERROR: The package name (dubai-parking) is not a valid Python module name. Please do not use a `-` and use `_` instead
Stopping generation because pre_gen_project hook script didn't exit successfully
╭───────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────╮
│ C:\Users\Dominic.Duke\AppData\Local\miniforge3\envs\cookiecutter\Lib\site-packages\cruft\_cli.py:115 in create       │
│                                                                                                                      │
│   112 │   │   None, "--skip", show_default=False, help="Default files/pattern to skip on updat                       │
│   113 │   ),                                                                                                         │
│   114 ) -> None:                                                                                                     │
│ ❱ 115 │   _commands.create(                                                                                          │
│   116 │   │   template_git_url,                                                                                      │
│   117 │   │   output_dir=output_dir,                                                                                 │
│   118 │   │   config_file=config_file,                                                                               │
│                                                                                                                      │
│ ╭───────────────────────────────────── locals ─────────────────────────────────────╮                                 │
│ │            checkout = None                                                       │                                 │
│ │         config_file = None                                                       │                                 │
│ │      default_config = False                                                      │                                 │
│ │           directory = None                                                       │                                 │
│ │       extra_context = '{}'                                                       │                                 │
│ │  extra_context_file = None                                                       │                                 │
│ │            no_input = False                                                      │                                 │
│ │          output_dir = WindowsPath('.')                                           │                                 │
│ │ overwrite_if_exists = False                                                      │                                 │
│ │                skip = None                                                       │                                 │
│ │    template_git_url = 'https://github.com/arup-group/cookiecutter-pypackage.git' │                                 │
│ ╰──────────────────────────────────────────────────────────────────────────────────╯                                 │
│                                                                                                                      │
│ C:\Users\Dominic.Duke\AppData\Local\miniforge3\envs\cookiecutter\Lib\site-packages\cruft\_commands\utils\__init__.py │
│ :14 in wrapper                                                                                                       │
│                                                                                                                      │
│   11 │   │   def decorator(f):                                                                                       │
│   12 │   │   │   @wraps(f)                                                                                           │
│   13 │   │   │   def wrapper(*args, **kwargs):                                                                       │
│ ❱ 14 │   │   │   │   return f(*args, **kwargs)                                                                       │
│   15 │   │   │                                                                                                       │
│   16 │   │   │   return wrapper                                                                                      │
│   17                                                                                                                 │
│                                                                                                                      │
│ ╭──────────────────────────────── locals ────────────────────────────────╮                                           │
│ │   args = ('https://github.com/arup-group/cookiecutter-pypackage.git',) │                                           │
│ │ kwargs = {                                                             │                                           │
│ │          │   'output_dir': WindowsPath('.'),                           │                                           │
│ │          │   'config_file': None,                                      │                                           │
│ │          │   'default_config': False,                                  │                                           │
│ │          │   'extra_context': {},                                      │                                           │
│ │          │   'extra_context_file': None,                               │                                           │
│ │          │   'no_input': False,                                        │                                           │
│ │          │   'directory': None,                                        │                                           │
│ │          │   'checkout': None,                                         │                                           │
│ │          │   'overwrite_if_exists': False,                             │                                           │
│ │          │   'skip': None                                              │                                           │
│ │          }                                                             │                                           │
│ ╰────────────────────────────────────────────────────────────────────────╯                                           │
│                                                                                                                      │
│ C:\Users\Dominic.Duke\AppData\Local\miniforge3\envs\cookiecutter\Lib\site-packages\cruft\_commands\create.py:50 in   │
│ create                                                                                                               │
│                                                                                                                      │
│   47 │   │   │   )                                                                                                   │
│   48 │   │                                                                                                           │
│   49 │   │   project_dir = Path(                                                                                     │
│ ❱ 50 │   │   │   generate_files(                                                                                     │
│   51 │   │   │   │   repo_dir=cookiecutter_template_dir,                                                             │
│   52 │   │   │   │   context=context,                                                                                │
│   53 │   │   │   │   overwrite_if_exists=overwrite_if_exists,                                                        │
│                                                                                                                      │
│ ╭───────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────╮ │
│ │                      checkout = None                                                                             │ │
│ │                   config_file = None                                                                             │ │
│ │                       context = OrderedDict({'cookiecutter': OrderedDict({'full_name': 'Dominic Duke', 'email':  │ │
│ │                                 '[email protected]', 'github_username': 'Dominic-Duke', 'repository_owner':  │ │
│ │                                 'arup-group', 'project_title': 'Dubai Parking Dashboard', 'repository_name':     │ │
│ │                                 'dubai-parking', 'package_name': 'dubai-parking', 'module_name':                 │ │
│ │                                 'dubai-parking', 'project_short_description': 'Dashboard to display outputs from │ │
│ │                                 the Dubai Parking model', 'project_visibility': 'internal',                      │ │
│ │                                 'upload_pip_package': 'n', 'upload_conda_package': 'n', 'upload_aws_image': 'n', │ │
│ │                                 'conda_channel': 'https://packages.arup.com/conda', 'command_line_interface':    │ │
│ │                                 'n', 'create_docker_file': 'y', 'create_author_file': 'n',                       │ │
│ │                                 'create_jupyter_notebook_directory': 'y', 'check_docs_accessibility_in_CI': 'n', │ │
│ │                                 'open_source_license': 'Not open source', '_template':                           │ │
│ │                                 'https://github.com/arup-group/cookiecutter-pypackage.git', '_commit':           │ │
│ │                                 '08077fd17e4d12082ccd1b686518c8a69ecfbbab'})})                                   │ │
│ │     cookiecutter_template_dir = WindowsPath('C:/Users/DOMINI~1.DUK/AppData/Local/Temp/tmp_x0_pugk')              │ │
│ │ cookiecutter_template_dir_str = 'C:\\Users\\DOMINI~1.DUK\\AppData\\Local\\Temp\\tmp_x0_pugk'                     │ │
│ │                default_config = False                                                                            │ │
│ │                     directory = None                                                                             │ │
│ │                 extra_context = {}                                                                               │ │
│ │            extra_context_file = None                                                                             │ │
│ │                   last_commit = '08077fd17e4d12082ccd1b686518c8a69ecfbbab'                                       │ │
│ │                      no_input = False                                                                            │ │
│ │                    output_dir = WindowsPath('.')                                                                 │ │
│ │           overwrite_if_exists = False                                                                            │ │
│ │                          repo = <git.repo.base.Repo                                                              │ │
│ │                                 'C:\\Users\\DOMINI~1.DUK\\AppData\\Local\\Temp\\tmp_x0_pugk\\.git'>              │ │
│ │                          skip = None                                                                             │ │
│ │              template_git_url = 'https://github.com/arup-group/cookiecutter-pypackage.git'                       │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                      │
│ C:\Users\Dominic.Duke\AppData\Local\miniforge3\envs\cookiecutter\Lib\site-packages\cookiecutter\generate.py:342 in   │
│ generate_files                                                                                                       │
│                                                                                                                      │
│   339 │   delete_project_on_failure = output_directory_created and not keep_project_on_failure                       │
│   340 │                                                                                                              │
│   341 │   if accept_hooks:                                                                                           │
│ ❱ 342 │   │   run_hook_from_repo_dir(                                                                                │
│   343 │   │   │   repo_dir, 'pre_gen_project', project_dir, context, delete_project_on_failure                       │
│   344 │   │   )                                                                                                      │
│   345                                                                                                                │
│                                                                                                                      │
│ ╭───────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────╮ │
│ │              accept_hooks = True                                                                                 │ │
│ │                   context = OrderedDict({'cookiecutter': OrderedDict({'full_name': 'Dominic Duke', 'email':      │ │
│ │                             '[email protected]', 'github_username': 'Dominic-Duke', 'repository_owner':      │ │
│ │                             'arup-group', 'project_title': 'Dubai Parking Dashboard', 'repository_name':         │ │
│ │                             'dubai-parking', 'package_name': 'dubai-parking', 'module_name': 'dubai-parking',    │ │
│ │                             'project_short_description': 'Dashboard to display outputs from the Dubai Parking    │ │
│ │                             model', 'project_visibility': 'internal', 'upload_pip_package': 'n',                 │ │
│ │                             'upload_conda_package': 'n', 'upload_aws_image': 'n', 'conda_channel':               │ │
│ │                             'https://packages.arup.com/conda', 'command_line_interface': 'n',                    │ │
│ │                             'create_docker_file': 'y', 'create_author_file': 'n',                                │ │
│ │                             'create_jupyter_notebook_directory': 'y', 'check_docs_accessibility_in_CI': 'n',     │ │
│ │                             'open_source_license': 'Not open source', '_template':                               │ │
│ │                             'https://github.com/arup-group/cookiecutter-pypackage.git', '_commit':               │ │
│ │                             '08077fd17e4d12082ccd1b686518c8a69ecfbbab'})})                                       │ │
│ │ delete_project_on_failure = True                                                                                 │ │
│ │                       env = <cookiecutter.environment.StrictEnvironment object at 0x00000202273CA710>            │ │
│ │   keep_project_on_failure = False                                                                                │ │
│ │                output_dir = '.'                                                                                  │ │
│ │  output_directory_created = True                                                                                 │ │
│ │       overwrite_if_exists = False                                                                                │ │
│ │               project_dir = 'C:\\Users\\Dominic.Duke\\OneDrive - Arup\\Programming\\github-repos\\dubai-parking' │ │
│ │                  repo_dir = WindowsPath('C:/Users/DOMINI~1.DUK/AppData/Local/Temp/tmp_x0_pugk')                  │ │
│ │       skip_if_file_exists = False                                                                                │ │
│ │              template_dir = WindowsPath('C:/Users/DOMINI~1.DUK/AppData/Local/Temp/tmp_x0_pugk/{{cookiecutter.re… │ │
│ │            unrendered_dir = '{{cookiecutter.repository_name}}'                                                   │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                      │
│ C:\Users\Dominic.Duke\AppData\Local\miniforge3\envs\cookiecutter\Lib\site-packages\cookiecutter\hooks.py:157 in      │
│ run_hook_from_repo_dir                                                                                               │
│                                                                                                                      │
│   154 │   """
│   155 │   with work_in(repo_dir):                                                                                    │
│   156 │   │   try:                                                                                                   │
│ ❱ 157 │   │   │   run_hook(hook_name, project_dir, context)                                                          │
│   158 │   │   except (                                                                                               │
│   159 │   │   │   FailedHookException,                                                                               │
│   160 │   │   │   UndefinedError,                                                                                    │
│                                                                                                                      │
│ ╭───────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────╮ │
│ │                   context = OrderedDict({'cookiecutter': OrderedDict({'full_name': 'Dominic Duke', 'email':      │ │
│ │                             '[email protected]', 'github_username': 'Dominic-Duke', 'repository_owner':      │ │
│ │                             'arup-group', 'project_title': 'Dubai Parking Dashboard', 'repository_name':         │ │
│ │                             'dubai-parking', 'package_name': 'dubai-parking', 'module_name': 'dubai-parking',    │ │
│ │                             'project_short_description': 'Dashboard to display outputs from the Dubai Parking    │ │
│ │                             model', 'project_visibility': 'internal', 'upload_pip_package': 'n',                 │ │
│ │                             'upload_conda_package': 'n', 'upload_aws_image': 'n', 'conda_channel':               │ │
│ │                             'https://packages.arup.com/conda', 'command_line_interface': 'n',                    │ │
│ │                             'create_docker_file': 'y', 'create_author_file': 'n',                                │ │
│ │                             'create_jupyter_notebook_directory': 'y', 'check_docs_accessibility_in_CI': 'n',     │ │
│ │                             'open_source_license': 'Not open source', '_template':                               │ │
│ │                             'https://github.com/arup-group/cookiecutter-pypackage.git', '_commit':               │ │
│ │                             '08077fd17e4d12082ccd1b686518c8a69ecfbbab'})})                                       │ │
│ │ delete_project_on_failure = True                                                                                 │ │
│ │                 hook_name = 'pre_gen_project'                                                                    │ │
│ │               project_dir = 'C:\\Users\\Dominic.Duke\\OneDrive - Arup\\Programming\\github-repos\\dubai-parking' │ │
│ │                  repo_dir = WindowsPath('C:/Users/DOMINI~1.DUK/AppData/Local/Temp/tmp_x0_pugk')                  │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                      │
│ C:\Users\Dominic.Duke\AppData\Local\miniforge3\envs\cookiecutter\Lib\site-packages\cookiecutter\hooks.py:140 in      │
│ run_hook                                                                                                             │
│                                                                                                                      │
│   137 │   │   return                                                                                                 │
│   138 │   logger.debug('Running hook %s', hook_name)                                                                 │
│   139 │   for script in scripts:                                                                                     │
│ ❱ 140 │   │   run_script_with_context(script, project_dir, context)                                                  │
│   141                                                                                                                │
│   142                                                                                                                │
│   143 def run_hook_from_repo_dir(                                                                                    │
│                                                                                                                      │
│ ╭───────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────╮ │
│ │     context = OrderedDict({'cookiecutter': OrderedDict({'full_name': 'Dominic Duke', 'email':                    │ │
│ │               '[email protected]', 'github_username': 'Dominic-Duke', 'repository_owner': 'arup-group',      │ │
│ │               'project_title': 'Dubai Parking Dashboard', 'repository_name': 'dubai-parking', 'package_name':    │ │
│ │               'dubai-parking', 'module_name': 'dubai-parking', 'project_short_description': 'Dashboard to        │ │
│ │               display outputs from the Dubai Parking model', 'project_visibility': 'internal',                   │ │
│ │               'upload_pip_package': 'n', 'upload_conda_package': 'n', 'upload_aws_image': 'n', 'conda_channel':  │ │
│ │               'https://packages.arup.com/conda', 'command_line_interface': 'n', 'create_docker_file': 'y',       │ │
│ │               'create_author_file': 'n', 'create_jupyter_notebook_directory': 'y',                               │ │
│ │               'check_docs_accessibility_in_CI': 'n', 'open_source_license': 'Not open source', '_template':      │ │
│ │               'https://github.com/arup-group/cookiecutter-pypackage.git', '_commit':                             │ │
│ │               '08077fd17e4d12082ccd1b686518c8a69ecfbbab'})})                                                     │ │
│ │   hook_name = 'pre_gen_project'                                                                                  │ │
│ │ project_dir = 'C:\\Users\\Dominic.Duke\\OneDrive - Arup\\Programming\\github-repos\\dubai-parking'               │ │
│ │      script = 'C:\\Users\\DOMINI~1.DUK\\AppData\\Local\\Temp\\tmp_x0_pugk\\hooks\\pre_gen_project.py'            │ │
│ │     scripts = ['C:\\Users\\DOMINI~1.DUK\\AppData\\Local\\Temp\\tmp_x0_pugk\\hooks\\pre_gen_project.py']          │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                      │
│ C:\Users\Dominic.Duke\AppData\Local\miniforge3\envs\cookiecutter\Lib\site-packages\cookiecutter\hooks.py:123 in      │
│ run_script_with_context                                                                                              │
│                                                                                                                      │
│   120 │   │   output = template.render(**context)                                                                    │
│   121 │   │   temp.write(output.encode('utf-8'))                                                                     │
│   122 │                                                                                                              │
│ ❱ 123 │   run_script(temp.name, cwd)                                                                                 │
│   124                                                                                                                │
│   125                                                                                                                │
│   126 def run_hook(hook_name, project_dir, context):                                                                 │
│                                                                                                                      │
│ ╭───────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────╮ │
│ │           _ = 'C:\\Users\\DOMINI~1.DUK\\AppData\\Local\\Temp\\tmp_x0_pugk\\hooks\\pre_gen_project'               │ │
│ │    contents = '"""Hooks to run before baking the project from the template."""\n\nimport re\nimpor'+1243         │ │
│ │     context = OrderedDict({'cookiecutter': OrderedDict({'full_name': 'Dominic Duke', 'email':                    │ │
│ │               '[email protected]', 'github_username': 'Dominic-Duke', 'repository_owner': 'arup-group',      │ │
│ │               'project_title': 'Dubai Parking Dashboard', 'repository_name': 'dubai-parking', 'package_name':    │ │
│ │               'dubai-parking', 'module_name': 'dubai-parking', 'project_short_description': 'Dashboard to        │ │
│ │               display outputs from the Dubai Parking model', 'project_visibility': 'internal',                   │ │
│ │               'upload_pip_package': 'n', 'upload_conda_package': 'n', 'upload_aws_image': 'n', 'conda_channel':  │ │
│ │               'https://packages.arup.com/conda', 'command_line_interface': 'n', 'create_docker_file': 'y',       │ │
│ │               'create_author_file': 'n', 'create_jupyter_notebook_directory': 'y',                               │ │
│ │               'check_docs_accessibility_in_CI': 'n', 'open_source_license': 'Not open source', '_template':      │ │
│ │               'https://github.com/arup-group/cookiecutter-pypackage.git', '_commit':                             │ │
│ │               '08077fd17e4d12082ccd1b686518c8a69ecfbbab'})})                                                     │ │
│ │         cwd = 'C:\\Users\\Dominic.Duke\\OneDrive - Arup\\Programming\\github-repos\\dubai-parking'               │ │
│ │         env = <cookiecutter.environment.StrictEnvironment object at 0x0000020227492490>                          │ │
│ │   extension = '.py'                                                                                              │ │
│ │        file = <_io.TextIOWrapper                                                                                 │ │
│ │               name='C:\\Users\\DOMINI~1.DUK\\AppData\\Local\\Temp\\tmp_x0_pugk\\hooks\\pre_gen_project.py'       │ │
│ │               mode='r' encoding='utf-8'>                                                                         │ │
│ │      output = '"""Hooks to run before baking the project from the template."""\n\nimport re\nimpor'+1061         │ │
│ │ script_path = 'C:\\Users\\DOMINI~1.DUK\\AppData\\Local\\Temp\\tmp_x0_pugk\\hooks\\pre_gen_project.py'            │ │
│ │        temp = <tempfile._TemporaryFileWrapper object at 0x00000202273D42F0>                                      │ │
│ │    template = <Template memory:20227523930>                                                                      │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                      │
│ C:\Users\Dominic.Duke\AppData\Local\miniforge3\envs\cookiecutter\Lib\site-packages\cookiecutter\hooks.py:94 in       │
│ run_script                                                                                                           │
│                                                                                                                      │
│    91 │   │   proc = subprocess.Popen(script_command, shell=run_thru_shell, cwd=cwd)  # nosec                        │
│    92 │   │   exit_status = proc.wait()                                                                              │
│    93 │   │   if exit_status != EXIT_SUCCESS:                                                                        │
│ ❱  94 │   │   │   raise FailedHookException(                                                                         │
│    95 │   │   │   │   f'Hook script failed (exit status: {exit_status})'                                             │
│    96 │   │   │   )                                                                                                  │
│    97 │   except OSError as err:                                                                                     │
│                                                                                                                      │
│ ╭────────────────────────────────────────────────── locals ───────────────────────────────────────────────────╮      │
│ │            cwd = 'C:\\Users\\Dominic.Duke\\OneDrive - Arup\\Programming\\github-repos\\dubai-parking'       │      │
│ │    exit_status = 1                                                                                          │      │
│ │           proc = <Popen: returncode: 1 args: ['C:\\Users\\Dominic.Duke\\AppData\\Local\\minif...>           │      │
│ │ run_thru_shell = True                                                                                       │      │
│ │ script_command = [                                                                                          │      │
│ │                  │   'C:\\Users\\Dominic.Duke\\AppData\\Local\\miniforge3\\envs\\cookiecutter\\python.exe', │      │
│ │                  │   'C:\\Users\\DOMINI~1.DUK\\AppData\\Local\\Temp\\tmprqym0r97.py'                        │      │
│ │                  ]                                                                                          │      │
│ │    script_path = 'C:\\Users\\DOMINI~1.DUK\\AppData\\Local\\Temp\\tmprqym0r97.py'                            │      │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
FailedHookException: Hook script failed (exit status: 1)
@Dominic-Duke Dominic-Duke added the bug Something isn't working label Mar 7, 2025
@Dominic-Duke
Copy link
Contributor Author

Dominic-Duke commented Mar 7, 2025

The docs also use a - in the package name example of the tutorial, as below:

Image

https://arup-group.github.io/cookiecutter-pypackage/latest/tutorial/#setting-up-your-project

@Dominic-Duke
Copy link
Contributor Author

When re-running the process, I've noticed that step 8 mentions that the module_name should typically be the same as package_name but is defaulting to the repository_name instead.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant