4

I have a directory I want to distribute to colleagues which has the following files:

__init__.py
common.py
file_downloader.py
builder.py
repo_setup.py

Right now, the file i have set up to be the main function is repo_setup.py as it has the def main(): i am looking for.

I normally would just run that file and everything works. It isnt quite intuitive to run that file though, and was curious what the standard is for the primary file to kick off everything

I was thinking to just create a main.py which would kick off everything and plausibly have a readme as well.

Is there a Python standard for developing a project with multiple files and distributing it though email or thumb drive?

I felt that leveraging setup.py isnt needed since it doesn't require any other packages to run. Maybe this is actually the best course of action though. My first look didn't see any run property which accepted a executable list to run in order after setup complex. Maybe executing setup.py would run a list of python files in order after all packages are installed?

Fallenreaper
  • 10,222
  • 12
  • 66
  • 129
  • Not really clear what you're trying to accomplish. A file that invokes other files? Isn't that what imports are for? – pvg Dec 22 '16 at 03:19
  • Possible duplicate of [Understanding the main method of python](http://stackoverflow.com/questions/22492162/understanding-the-main-method-of-python) – Ani Menon Dec 22 '16 at 03:22
  • I understand what the main method is for, but im trying to create an easy to use file structure. That way the user will get my directory, they just run a particular file. I wanted to try to follow the Python standards. Normally i just click and run a file and leverage the `__name__`, but i wasnt sure if there was a standard to running an application, given a list of files – Fallenreaper Dec 22 '16 at 03:26

1 Answers1

1

You could do part of what is done for IDLE with idlelib. Call the directory project. Add project.__main__ with

from project.repo_setup import main
main()

Put (unzip) the project directory (with its .py files) in .../lib/site-packages. This puts project on sys.path and makes it both importable and runnable (as a main module). Run from a command line with python -m project. (Or python3 depending of version and OS.)

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
  • so you are saying, create a file with the same name as the directory, then import the main from repo_setup, and run it? – Fallenreaper Dec 22 '16 at 03:38
  • Not quite. Add a file named `__main__.py` *in* the project directory, whatever you call it. For an example, look at a file listing for lib/idlelib. The option `-m` means 'run this (importable) file as the main module'. Just as importing a directory actually imports directory/__init__.py, running a directory actually runs __main__.py. In other words, `python -m import.name` is equivalent to `python somepath/import/name.py`, except that the the `-m` relieves the user of knowing `somepath`, which depends on the particular installation. – Terry Jan Reedy Dec 22 '16 at 03:48