-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows "Usage" incorrect display and difficulty to get a command name correct displayed #365
Comments
You're looking for
I wonder what |
From the stdlib docs:
https://docs.python.org/3/library/sys.html#sys.argv I start to doubt that this bug is fixable. |
* workaround pallets/click#365 by suclassing click.Command.main() to force the prog_name to self.name. * also refactored the usage display for pallets/click#393
I guess I could overwrite main here: https://github.com/mitsuhiko/click/blob/fe2f525e720a6f71e8ac4079807b64df13063e8a/click/core.py#L611 |
This was a problem for me too when trying to activate bash completion because the magic environment variable is _<PROG_NAME>_COMPLETE by default. So I tried to work around it, hopefully without doing too much monkey-patching. In my case, the application name is "nx_tools". So _NX_TOOLS_SCRIPT.PY_COMPLETE=source nx_tools > complete.sh only to get an error: bash: _NX_TOOLS_SCRIPT.PY_COMPLETE=source: command not found Bash does not allow periods in variable names. All in all, not that big a deal, but it could be documented. Would you accept a PR on that? |
Adding a "me-too" on this issue. I was pointed to this bug report from my StackOverflow question. I will document this issue in the help text until the bug is resolved... |
Because it was mentioned in the SO thread: You can just call your
No need for overriding main... |
That works, as expected, also when |
I'm not sure if we can fix that easily unless someone has an idea how to autodetect it and magically fix it up. |
@untitaker wrote:
When doing so you might end up having to write some wrapper function to inject progname and use that instead as an entry point... only if you care about windows. but that becomes a solution for all OS which is not so nice. @mitsuhiko wrote:
The problem is only when using setup tools entry points on Windows. entry points are IMHO a great thing. One approach, since the This would be hackish, but simple enough. |
This definetly seems hackish because of the possibility that your actual program name ends with that string. A proper solution would be part of setuptools. On 16 September 2015 16:12:06 CEST, Philippe Ombredanne notifications@github.com wrote:
Sent from my phone. Please excuse my brevity. |
Not happy to just script |
@mitsuhiko The simplest thing that comes to mind since this is a windows only whart would be to detect if we are on windows, and we are using entry points and there is an XXX.exe and the command comes out as XXX-script.py, then use XXX instead. Not pretty but working in practice. |
@pombreda how do you detect if you were invoked from an entrypoint? |
@mitsuhiko
|
and @dstufft suggested this regex (flawed for now because it does not catch the .py case ) too : https://github.com/pypa/pip/blob/develop/pip/wheel.py#L410-L417 |
I think if the regex got updated in pip, then you wouldn't need to deal with it at all in click. |
@dstufft so your suggestion is to fix this in pip/setuptools instead? |
Yes, the purpose of that regex is to make it so that console wrappers have the same sys.argv[0] on both Windows and *nix. It's a bug that it currently isn't doing that. |
In that case I will close this here. |
excellent! much better! @dstufft Thank! |
@dstufft @mitsuhiko actually things are a tad more complex:
This is done here in pip:
This is done here in setuptools: There yet another launcher in @vsajip distlib, but that does not seem to apply here: |
Perhaps @jaraco would be open to adding the same regex to setuptools script wrappers. Sent from my iPhone
|
@dstufft I filed a bug in setuptools: https://bitbucket.org/pypa/setuptools/issues/459/incorrect-sysargv-0-for-generated-console and one in pip: pypa/pip#3233 |
This should be fixed soon: pypa/setuptools/pull/736 pypa/pip/pull/3918 |
Fixed in latest version of setuptools (*_^)/ |
When you create a command with a setuptools console_scripts entry_points (for instance named mycli) the Usage displayed on POSIX (Linux, Mac,...) when running mycli --help will be:
Usage: mycli
In contrast on Windows, I get the following:
Usage: mycli-script.py
This is annoying because the correct invocation on windows is to use mycli, not mycli-script.py.
The script is the same on all OSes, even though behind the scenes setuptools creates:
The obvious way to force this would be to use the name arg in click.command. ("This defaults to the function name."). But it does not default to the function name and always show the mycli-script.py instead of mycli.
It looks like this comes from Context.info_name which is computed somehow, but I could not find a way to get this info_name forced to something fixed.
The text was updated successfully, but these errors were encountered: