Skip to content

Move package to src/package #173

Closed

Description

@sverhoeven

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.

Activity

  1. added
    generated-packageRelated to the generated package, i.e. after running cookiecutter
    on Apr 16, 2021
  2. jspaaks commented on Apr 21, 2021

    @jspaaks

    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 #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

  3. self-assigned this
    on Apr 21, 2021
  4. sverhoeven commented on Apr 22, 2021

    @sverhoeven
    MemberAuthor

    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.

  5. jspaaks commented on Apr 22, 2021

    @jspaaks

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

  6. removed their assignment
    on Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

generated-packageRelated to the generated package, i.e. after running cookiecutter

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions