I'm working on a project with the following directory structure:
project/
package1/
module1.py
module2.py
package2/
module1.py
module2.py
main1.py
main2.py
main3.py
...
mainN.py
where each mainX.py
file is an executable Python script that imports modules from either package1
, package2
, or both. package1
and package2
are subpackages meant to be distributed along with the rest of the project (not independently).
The standard thing to do is to put your entry point in the top-level directory. I have N entry points, so I put them all in the top-level directory. The trouble is that N keeps growing, so my top-level directory is getting flooded with entry points.
I could move the mainX.py
files to a sub-directory (say, project/run
), but then all of the package1
and package2
imports would break. I could extract package1
and package2
to a separate repository and just expect it to be installed on the system (i.e., in the system / user python path), but that would complicate installation. I could modify the Python path as a precondition or during runtime, but that's messy and could introduce unintended consequences. I could write a single main.py
entry point script with argument subparsers respectively pointing to run/main1.py, ..., run/mainN.py
, but that would introduce coupling between main.py
and each of the run/mainX.py
files.
What's the standard, "Pythonic" solution to this issue?