Skip to content

Conversation

@jspaaks
Copy link

@jspaaks jspaaks commented Apr 14, 2021

In this PR:

  • simplified templating expressions by using a hook to change user input to their safe equivalents, e.g. MY python Project becomes my-python-project
  • changed project_short_description to package_short_description
  • changed project_slug to package_name
  • changed open_source_license to just license
  • Updated the table with explanations a bit
  • got rid of using the package name for naming the module at the deepest level of nesting, renamed that file to my_module.py(i.e. without any templating)
  • dashes are now allowed in the project name
  • changed the order of questions: package first, project later

Refs: #152

Works except for the top level directory for some reason because cookiecutter first creates the top level directory, then runs the hooks/pre_gen_project.py hook. That means any updates you do to the project_name from the pre_gen_project hook come too late. This might be fixable by adding a post hook that renames the directory afterwards. But anyway, this behavior is not worse than what we had before.

To test (assuming you have cookiecutter already installed in user space):

cd $(mktemp -d --tmpdir python-template.XXXXXX)
git clone https://github.com/NLeSC/python-template
cd python-template
git checkout 152-derived-cookiecutter-properties
cd ..
cookiecutter python-template
# (accept defaults)

Here is the tree after running cookiecutter with the defaults:

my-python-project/
├── CHANGELOG.rst
├── CITATION.cff
├── CODE_OF_CONDUCT.rst
├── CONTRIBUTING.rst
├── docs
│   ├── conf.py
│   ├── index.rst
│   ├── make.bat
│   ├── Makefile
│   ├── _static
│   │   └── theme_overrides.css
│   └── _templates
├── LICENSE
├── MANIFEST.in
├── my_python_package
│   ├── __init__.py
│   ├── my_module.py
│   └── __version__.py
├── NOTICE
├── project_setup.md
├── README.rst
├── setup.cfg
├── setup.py
└── tests
    ├── __init__.py
    └── test_my_module.py

Now check the generated package:

cd my-python-project
# create a virtual environment and install all dependencies in it including dev deps
python3 -m venv env
source env/bin/activate
pip install --upgrade pip wheel setuptools
pip install .[dev]

# should pass and print a coverage report to the terminal (3 tests total)
pytest tests/

# test if you can build the documentation
cd docs
make html

@jspaaks jspaaks marked this pull request as ready for review April 15, 2021 07:35
Co-authored-by: Faruk D. <fdiblen@users.noreply.github.com>
Co-authored-by: Faruk D. <fdiblen@users.noreply.github.com>
Co-authored-by: Faruk D. <fdiblen@users.noreply.github.com>
Co-authored-by: Faruk D. <fdiblen@users.noreply.github.com>
Co-authored-by: Faruk D. <fdiblen@users.noreply.github.com>
Co-authored-by: Faruk D. <fdiblen@users.noreply.github.com>
Co-authored-by: Faruk D. <fdiblen@users.noreply.github.com>
Copy link
Member

@fdiblen fdiblen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a big relief after reviewing and approving this PR. 🍬

@jspaaks
Copy link
Author

jspaaks commented Apr 19, 2021

Thank you Faruk for the review and your code contributions!

@jspaaks jspaaks merged commit 2812bc6 into main Apr 19, 2021
@jspaaks jspaaks deleted the 152-derived-cookiecutter-properties branch April 19, 2021 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants