migrate setup.py 'scripts=' to entry points
I'd like to make use of someone else's python utility, foobartools , whose native environment is linux. Foobartools is pure python so there's no reason it can't be used on Windows, where I am.
In their setup.py they're using the older style scripts=['bin/foobar'],
Running pip install -e b:\code\foobar creates a file called foobar in %pythonhome%\Scripts , but Windows doesn't know about it even though Scripts is in PATH. To use it I need to make a @python %pythonhome%\scripts\fooba r batch file. This works but is non-optimal ( ctrl-c handling is ugly for instance).
I know that if I add the newer and recommended entry_points syntax to setup.py pip will automatically create Scripts\foobar.exe on Windows (and I can ditch the batch file). On Linux Scripts\foobar remains unchanged, and everybody is happy.
entry_points = {
'console_scripts': ['foobar = foobartools:main'],
}
I don't know what to do with the right hand side of the equation, foobartools:main . How do make that call bin/foobar ? The foobartools module doesn't have a single callable function or module like that corresponds to the bin script, and the bin script is relatively complicated.
I want to make as few changes as possible to the project so that a) a patch submission has a better chance of getting accepted upstream, and b) if upstream remains uninterested there's less work for me to do to keep up with it.
The existing source tree structure:
foobartools/
bin/foobar
foobartools/
__init__.py
foo/
__init__.py
one.py
two.py
bar/
...
baz/
...
setup.py
From < https://stackoverflow.com/questions/30518806/python-migrate-setup-py-scripts-to-entry-points >
I got to a working Scripts\foobar.exe , but it changes more of the code than I wish. I was hoping to get by with just a couple of tweaks to setup.py, or at least something that doesn't mess around inside upstream modules. I don't know it well enough to be sure I'm not getting in the way somehow.
(1) move bin/foobar --> foobartools/foobar_cli.py
(2) In setup.py, comment out #scripts=... and add:
entry_points = {
'console_scripts': ['foobar = foobartools.foobar_cli:main'],
}
[later] A refinement of the same core idea, means I keep my fat feet out of the main business area:
(1) move ./bin/foobar --> ./foobar_cli/foobar.py (note extension as well as folder change)
(2) add an empty __init__.py to same folder
(3) console_scripts': ['foobar = foobar_cli.foorbar:main'],
From < https://stackoverflow.com/questions/30518806/python-migrate-setup-py-scripts-to-entry-points >