audreyfeldroy / cookiecutter-pypackage

Cookiecutter template for a Python package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change the name of a newly created project folder to not use the module_name

vemonet opened this issue · comments

  • Date you used Cookiecutter PyPackage: 2022-11-07
  • Cookiecutter version used, if any: 2.1.1
  • Python version, if any: 3.9
  • Operating System: Linux Fedora

Description

Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.

I want to create a new project for a package named "toasty-cooky" (for example), with the module named "toasty_cooky", and I want the root folder to be named "toasty-cooky" (with the - and not the _)

But currently cookiecutter is automatically using the module name with _ to create the folder name

Which is not recommended by the PEP-8 recommendations if you are used to naming your git repo the same as your package: https://peps.python.org/pep-0008/#package-and-module-names (module should use _, package names should use -, and usually I name the folder and git repository after the package, not the module)

What I Did

To reproduce:

cookiecutter https://github.com/MaastrichtU-IDS/cookiecutter-python-package

And provide "toasty_cooky" as module name: this creates a folder named "toasty_cooky"

I guess there might be a manipulation to to either in the pre or post gen hooks. But I am not sure what would be the recommended way to do so and I could not find any example of people doing so

I just realized that I could do this easily directly in the folder name {{cookiecutter.package_name}} (which is actually the module name with _) and replace it for the package slug variable that uses -