[Tutor] Packaging questions
Cameron Simpson
cs at cskk.id.au
Mon Dec 13 18:10:20 EST 2021
On 13Dec2021 09:43, Julius Hamilton <juliushamilton100 at gmail.com> wrote:
>It seems like there are many ways to do this.
I think Alan and I have outlined the 2 main ways.
Alan's suggestion is standard for modules which can themselves be
meaningfully run as a command. I do it all the time. Even if I haven't
made a command line mode, the __main__ thing might run some tests.
The entry_points thing is the standard way to have the package install
(run by "pip install") create a command script in the environment where
the install is happening, typically a virtualenv.
>I did one tutorial that I
>didn’t quite fully understand but they put a script called “module-run.py”
>in the directory, which was the command line execution version.
That's fiddly, unless they expect you to modify "module-run.py" in some
way. Do Alan's __main__ thing, then you can just go:
python -m your_module command line args here ...
to run it.
>I don’t
>remember what they did to make it easy to execute though.
Well, you could just go:
python module-run.py command line args here ...
with no special actions. If you want "module-run.py" as a command (a) it
needs execute permission and (b) it needs to be in your $PATH (on
UNIXlike systems).
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Tutor
mailing list