Python Click CLI Application
When you use a Click library to build a Python CLI Application you can do this:
@click.version_option()
def cli():
'''
Main Entry Point to Click Interface
'''
to be able to do this:
[user@host]$ clickapp --version
Click Packaged in pex
But when I package it as a pex
file, every other argument, option, commands, sub-command of my click application works, except --version
.
When I run (clickapp is now a binary executable pex
file):
[user@host]$ ./clickapp --version
I get the following error:
Traceback (most recent call last):
File "/~/clickapp/.bootstrap/pex/pex.py", line 446, in execute
File "/~/clickapp/.bootstrap/pex/pex.py", line 378, in _wrap_coverage
File "/~/clickapp/.bootstrap/pex/pex.py", line 409, in _wrap_profiling
File "/~/clickapp/.bootstrap/pex/pex.py", line 508, in _execute
File "/~/clickapp/.bootstrap/pex/pex.py", line 610, in execute_entry
File "/~/clickapp/.bootstrap/pex/pex.py", line 626, in execute_pkg_resources
File "/~/.pex/installed_wheels/7bcb1b5bf49ca3f89c348c338d33c04e3d59dfc1/click-7.1.2-py2.py3-none-any.whl/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/~/.pex/installed_wheels/7bcb1b5bf49ca3f89c348c338d33c04e3d59dfc1/click-7.1.2-py2.py3-none-any.whl/click/core.py", line 781, in main
with self.make_context(prog_name, args, **extra) as ctx:
File "/~/.pex/installed_wheels/7bcb1b5bf49ca3f89c348c338d33c04e3d59dfc1/click-7.1.2-py2.py3-none-any.whl/click/core.py", line 700, in make_context
self.parse_args(ctx, args)
File "/~/.pex/installed_wheels/7bcb1b5bf49ca3f89c348c338d33c04e3d59dfc1/click-7.1.2-py2.py3-none-any.whl/click/core.py", line 1212, in parse_args
rest = Command.parse_args(self, ctx, args)
File "/~/.pex/installed_wheels/7bcb1b5bf49ca3f89c348c338d33c04e3d59dfc1/click-7.1.2-py2.py3-none-any.whl/click/core.py", line 1048, in parse_args
value, args = param.handle_parse_result(ctx, opts, args)
File "/~/.pex/installed_wheels/7bcb1b5bf49ca3f89c348c338d33c04e3d59dfc1/click-7.1.2-py2.py3-none-any.whl/click/core.py", line 1630, in handle_parse_result
value = invoke_param_callback(self.callback, ctx, self, value)
File "/~/.pex/installed_wheels/7bcb1b5bf49ca3f89c348c338d33c04e3d59dfc1/click-7.1.2-py2.py3-none-any.whl/click/core.py", line 123, in invoke_param_callback
return callback(ctx, param, value)
File "/~/.pex/installed_wheels/7bcb1b5bf49ca3f89c348c338d33c04e3d59dfc1/click-7.1.2-py2.py3-none-any.whl/click/decorators.py", line 295, in callback
raise RuntimeError("Could not determine version")
RuntimeError: Could not determine version
Details
The setup.py
file:
from setuptools import setup, find_namespace_packages
setup(
name='clickapp',
version='0.1.3',
author='Hamza M Zubair',
packages=find_namespace_packages(),
include_package_data=True,
package_data={
'': ['*.yaml'],
},
classifiers=[
'Programming Language :: Python :: 3',
'Operating System :: OS Independent',
'Natural Language :: English',
'License :: Other/Proprietary License',
],
python_requires='>=3.6',
install_requires=[
'click',
'pandas',
'sqlalchemy',
'jinjasql',
'pyyaml',
'joblib',
'python-dateutil',
'loguru',
'pymysql',
'xgboost',
'sklearn',
'wheel',
'importlib-resources'
],
entry_points='''
[console_scripts]
clickapp=clickapp.cli:cli
''',
)
The command used to create the pex
file:
[user@host]$ python setup.py bdist_pex --bdist-all
Tool Specs
I am building and running the pex file in different systems, using the following versions of libraries/packages. The target machine only has Python and no libraries, because pex file does not require libraries/virtualenv etc.
Build Machine OS: CentOS Linux release 7.8.2003 (Core)
Build Machine Python: 3.6.8
setuptools: 51.0.0
pex: 2.1.21
click: 7.1.2
Target Machine OS: CentOS Linus release 7.4.1708 (Core)
Target Machine Python: 3.6.8
What I tried
- I have tested the full functionality of my
clickapp
, and every other argument and command works perfectly.
Even this displays the help of my clickapp correctly.
[user@host]$ ./clickapp --help
- I tried re-building the package several times
- I have only tested this in Python3.6. I haven't tried different python versions, its slightly difficult to set it up in both the source and target systems.
- When I removed
@click.version_option()
I get the error:--version not implemented
, which is just as expected - I am yet to test it on a 2nd target system, in case some idiosyncrasies of my current target server is causing the error
More Info
What other information should I provide, for helping SO users?