priya priya - 1 month ago 17
Python Question

Project structure for python projects

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 projects.

Answer

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.

Comments