Project structure for python projects

前端 未结 3 1441
庸人自扰
庸人自扰 2021-01-11 11:16

Are there any tools which generate a project layout for python specific projects, much similar to what maven accomplishes with mvn archetype:generate for java p

相关标签:
3条回答
  • 2021-01-11 11:23

    In Python (just as in any language) there are a lot of pieces to configure if you want to make all of them play nicely together. Documentation, testing, virtual envs, packaging, ...

    You can add those configuration along the way, when you actually need them, or when your project starts growing. Having a tool that can configure all that for you and just let you fill the blanks does help quite a bit.

    A few projects to look at:

    • Scaffold for Python
    • Cookiecutter
    • Pyckstart
    0 讨论(0)
  • 2021-01-11 11:36

    It is the good news: you do not need any tool. You can organise your source code in any way you want.

    Let recap why we need tools in the java world:

    In java you want to generate directories upfront because the namespace system dictates that each class must live in one file in a directory structure that reflects that package hierarchy. As a consequence you have a deep folder structure. Maven enforces an additional set of convention for file location. You want to have tools to automate this.

    Secondly, different artefacts require use of different goals and even additional maven projects (e.g. a ear project requires a few jars and war artefacts). There are so many files to create you want to have tools to automate this.

    The complexity makes tools like mvn archetype:generate not just helpful. It is almost indispensable.

    In python land, we just do not have these complexity in the language.

    If my project is small, I can put all my classes and functions in a single file (if it makes sense)

    If my project is of a bigger size (LOC or team size), it makes sense to group .py files into modules in whatever way makes sense to you and your peers.

    At the end of the days, it is about striking a balance between ease of maintenance and readability.

    0 讨论(0)
  • 2021-01-11 11:41

    The following few bash commands work pretty well for me:

    mkdir myproject
    cd myproject
    mkdir docs
    mkdir tests
    touch tests/__init__.py
    

    With python, unlike java or c, you generally don't need much more than this. See the answers to a related question. If you think you need more, you're going to have to be more specific about your requirements.

    0 讨论(0)
提交回复
热议问题