[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

WedWonder: Scripts and Modules

On 12Sep2019 08:24, DL Neil <PythonList at DancesWithMice.info> wrote:
>In this day-and-age do you have a script in live/production-use, 
>which is also a module? What is the justification/use case?

Many. Many many.

1: Many of my modules run their unit tests if invoked as the main 

2: Several modules are their own utility programme. I've got a heap of 
these - anything that provides useful access to something can often be 
usefully used from the command line.

A quick grep from my bin directory shows stuff like this:

 [~/hg/css/bin(hg:default)]fleet*> grep ' -m cs.' *
 beyonwiz:exec python3 -m cs.app.beyonwiz ${1+"$@"}
 calibre:exec py3 -m cs.app.calibre ${1+"$@"}
 haproxy-tool:exec python2 -m cs.app.haproxy ${1+"$@"}
 iphoto:exec python3 -m cs.app.osx.iphoto ${1+"$@"}
 maildb:exec python3 -m cs.app.maildb ${1+"$@"}
 mailfiler:exec python3 -m cs.app.mailfiler ${1+"$@"}
 mklinks:exec python -m cs.app.mklinks ${1+"$@"}
 myke:exec python3 -m cs.app.myke ${1+"$@"}
 nodedb:exec python -m cs.nodedb.__init__ "$CS_NODEDB_URL" "$op" ${1+"$@"}
 pilfer:exec python3 -m cs.app.pilfer ${1+"$@"}
 portfwd:exec python3 -m cs.app.portfwd ${1+"$@"}
 s3-clone-website:  set -- python3 -m cs.app.aws s3 "$s3bucket" sync-up -D -% .
 svcd:exec python3 -m cs.app.svcd ${1+"$@"}
 vbox:exec python -m cs.app.virtualbox ${1+"$@"}
 vt:exec python3 -m cs.vt ${1+"$@"}
 wol:exec python -m cs.wol ${1+"$@"}

Consider: if you write a package, would it have a __main__.py?

Well, if the answer is ever "yes" then the same applies to ordinary 
modules, simple enough to not be worth splitting onto a package.

So, yes, for me this is really really common.

Even for my current client project, which is largely a package, 
several of the individual modules within the package have their own 
main programmes for testing and for various utility tasks dealing 
solely with that particular subsystem. There's an overarching shell 
script to set up the environment and then do various things from the 
command line, and it directly invokes particular modules for some 
operations that act only on one subsystem.

Cameron Simpson <cs at cskk.id.au>