Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project structure for python projects with maven

Tags:

python

maven

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.

like image 739
priya Avatar asked Apr 03 '12 18:04

priya


People also ask

What is the best project structure for a Python application?

Python doesn't have a distinction between /src , /lib , and /bin like Java or C has. Since a top-level /src directory is seen by some as meaningless, your top-level directory can be the top-level architecture of your application. I recommend putting all of this under the "name-of-my-product" directory.

What is the structure of maven project?

maven-project/src/main – contains source code and resources that become part of the artifact. maven-project/src/test – holds all the test code and resources. maven-project/src/it – usually reserved for integration tests used by the Maven Failsafe Plugin.

Can I use maven for Python?

You can use maven-exec-plugin to execute python script using maven.


1 Answers

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.

like image 88
Anthony Kong Avatar answered Sep 22 '22 07:09

Anthony Kong