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

Re: Application libraries private, Distutils metadata available for console scripts and introspection



On Nov 27, 2015, at 09:56 AM, Ben Finney wrote:

>Python's import mechanism makes it infeasible to have a module file
>named without a suffix; this makes it infeasible to name a command file
>by Unix conventions of having no suffix for the implementation language.
>
>There are many approaches to address this, which I won't detail here,
>but suffice it to say that none of them work smoothly.

I agree that it makes sense to separate the importable module from the
executable script file, but I'd argue that's good practice anyway for ease of
development, use, and testing.  And there are good tools and techniques to
take advantage of that, including setuptools entry points, or shim-scripts
with only an import and an `__name__` conditional.

I've found it good to minimize the logic in executable scripts because they
are harder to test.  If essentially all your script does is import your main()
and then call it, you can more easily incorporate a unit test for main().
Entry points make this a no-brainer; you don't even have to write the shim,
although to invoke it you need to build the package, so either use
`$python -m` or tox to create the shim in the tox-managed venv.

(I don't personally like application private library directories, but if you
do, you will have to fiddle with sys.path somehow to make your main()
importable.)

Cheers,
-Barry


Reply to: