click-contrib / click-man

Automate generation of man pages for python click applications :star:
MIT License
163 stars 35 forks source link

Remove dependency on disutils Command? #15

Closed waylan closed 6 years ago

waylan commented 6 years ago

By requiring a disutils Command to run click-man, you are also requiring that the user has a setup.py file and an uninstalled package available locally. However, many (most?) packages these days document installation with pip install packagename. And more and more packages are being distributed as wheels, which don't even contain a setup.py script. Naturally, a disutls Command does not work in these settings.

Therefore, click-man should provide its own command line tool (presumably implemented with click, which would need to be installed anyway). Then the tool could be pointed at either an already installed package (perhaps using whatever would be passed to python -m) or a distribution package (whl/tar.gz) to generate man pages.

Then, using an installed package, the user would do something like this:

pip install foo
click-man --target path/to/man/pages foo

Of course, the foo lib would need to support python -m foo to run foo's commands for click-man foo to work.

Or, if the user has a downloaded distribution file, then this would work:

click-man --target path/to/man/pages path/to/foo-1.0.0-py2.py3-none-any.whl

Presumably, click-man would look for foo/__main__.py within the whl file.

waylan commented 6 years ago

A couple notes on my initial proposal.

  1. I had missed that the README specifically states:

    click-man will generate one man page per command of your click CLI application specified in console_scripts in your setup.py.

    That being the case, the command click-man foo should look for the console-script entry point named foo among installed packages. That actually makes more sense than assuming foo.__main__ and solves the problem of defining which object in foo.__main__ should be used (i.e. foo.__main__:cli) as that would already be defined by the console_script entry point (a detail I missed in my proposal above).

  2. After reviewing PEP 427, specifically the answer to Is it possible to import Python code directly from a wheel file?, it seems likely that while passing a .whl file to click-man might work for most pure-python packages, there is no guarantee it will work for all packages. That being the case, perhaps it makes sense to leave the click-man command to only work with installed packages. After all, it would be odd to generate a man-page for a package that is not installed.