python-template icon indicating copy to clipboard operation
python-template copied to clipboard

Move package to src/package

Open sverhoeven opened this issue 3 years ago • 3 comments

On https://packaging.python.org/tutorials/packaging-projects/ the package is put in a src/ sub-directory. On https://blog.ionelmc.ro/2014/05/25/python-packaging/ there are arguments why this is a good idea.

sverhoeven avatar Apr 16 '21 12:04 sverhoeven

I tried moving the template directory to under src/, but then I couldn't generate a project anymore due to a cookiecutter.exceptions.NonTemplatedInputDirException.

I subsequently looked at a bunch of cookiecutter-template repos to see how they did it. Hardly any use the src or src-like patttern. Here's one https://github.com/better-go/cookiecutter-go. From its readme, I was able to run our template using an extra argument --directory

cookiecutter ~/github/nlesc/python-template --directory src

I also had to move hooks and cookiecutter.json into src for it to work but that's ok i guess.

Sidenote: the config from setup.cfg suggested at https://packaging.python.org/tutorials/packaging-projects/#configuring-metadata didn't seem to matter much when running with cookiecutter <template dir>. Maybe it would work better if you're using cookiecutter as a library from python code.

image

See result here https://github.com/NLeSC/python-template/pull/203

Overall, this isn't worth it to me, I prefer to stick to what we had before, i.e. the template directory in the root of this project

jspaaks avatar Apr 21 '21 06:04 jspaaks

I did not explain myself well enough. At the moment in this repo we have

{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__init__.py 

to use the structure of https://packaging.python.org/tutorials/packaging-projects/ it would have to be changed to

{{cookiecutter.project_name}}/src/{{cookiecutter.package_name}}/__init__.py 

So when a project (for example named my_python_package) is generated, its files would be:

  • my_python_package/README.md
  • my_python_package/setup.cfg
  • my_python_package/src/my_python_package/init.py

See for example https://github.com/cjolowicz/cookiecutter-hypermodern-python/blob/main/%7B%7Bcookiecutter.project_name%7D%7D/src/%7B%7Bcookiecutter.package_name%7D%7D/init.py, however it does not use setuptools, but poetry so can not be copied fully.

sverhoeven avatar Apr 22 '21 06:04 sverhoeven

ok, I'll see if I can make some changes

jspaaks avatar Apr 22 '21 09:04 jspaaks