Skip to content
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

[>=1.9.1] Fix output for --help #236

Merged
merged 1 commit into from
Jan 12, 2024
Merged

Conversation

nehaljwani
Copy link
Contributor

The output for --help after #205 started to error out:

(dev) /t/s/1703528681 ❯❯❯ ansi2html -h
Traceback (most recent call last):
  File "/private/tmp/scratch.nwani/1703528681/dev/bin/ansi2html", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/private/tmp/scratch.nwani/1703528681/dev/lib/python3.11/site-packages/ansi2html/converter.py", line 783, in main
    opts = parser.parse_args()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 1869, in parse_args
    args, argv = self.parse_known_args(args, namespace)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 1902, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 2114, in _parse_known_args
    start_index = consume_optional(start_index)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 2054, in consume_optional
    take_action(action, args, option_string)
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 1978, in take_action
    action(self, namespace, argument_values, option_string)
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 1119, in __call__
    parser.print_help()
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 2601, in print_help
    self._print_message(self.format_help(), file)
                        ^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 2585, in format_help
    return formatter.format_help()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 286, in format_help
    help = self._root_section.format_help()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 217, in format_help
    item_help = join([func(*args) for func, args in self.items])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 217, in <listcomp>
    item_help = join([func(*args) for func, args in self.items])
                      ^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 217, in format_help
    item_help = join([func(*args) for func, args in self.items])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 217, in <listcomp>
    item_help = join([func(*args) for func, args in self.items])
                      ^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 543, in _format_action
    help_text = self._expand_help(action)
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 640, in _expand_help
    return self._get_help_string(action) % params
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
TypeError: %d format: a real number is required, not dict

With this patch, the output is sane:

(dev) /t/s/1703528681 ❯❯❯ ansi2html --help
usage:
    $ ls --color=always | ansi2html > directories.html
    $ sudo tail /var/log/messages | ccze -A | ansi2html > logs.html
    $ task burndown | ansi2html > burndown.html


options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -p, --partial         Process lines as them come in.  No headers are produced.
  -L, --latex           Export as LaTeX instead of HTML.
  -i, --inline          Inline style without headers or template.
  -H, --headers         Just produce the <style> tag.
  -f SIZE, --font-size SIZE
                        Set the global font size in the output.
  -l, --light-background
                        Set output to 'light background' mode.
  -W, --no-line-wrap    Disable line wrapping.
  -a, --linkify         Transform URLs into <a> links.
  -u, --unescape        Do not escape XML tags found in the input.
  -m, --markup-lines    Surround lines with <span id='line-n'>..</span>.
  --input-encoding ENCODING
                        Specify input encoding
  --output-encoding ENCODING
                        Specify output encoding
  -s SCHEME, --scheme SCHEME
                        Specify color palette scheme. Default: ansi2html.
                        Choices: ['ansi2html', 'dracula', 'mint-terminal', 'osx', 'osx-basic', 'osx-solid-colors', 'solarized', 'xterm']
  -t OUTPUT_TITLE, --title OUTPUT_TITLE
                        Specify output title

@github-actions github-actions bot added the bug This issue/PR relates to a bug. label Dec 25, 2023
nehaljwani added a commit to regro-cf-autotick-bot/ansi2html-feedstock that referenced this pull request Dec 25, 2023
Copy link
Collaborator

@hartwork hartwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nehaljwani,

I confirm the issue, even with Python 3.9. For the fix, it is not clear to me why use of RawTextHelpFormatter is part of the fix when all I need locally is this:

--- a/src/ansi2html/converter.py
+++ b/src/ansi2html/converter.py
@@ -769,7 +769,7 @@ def main() -> None:
         default="ansi2html",
         choices=scheme_names,
         help=(
-            "Specify color palette scheme. Default: %%default. Choices: %s"
+            "Specify color palette scheme. Default: '%%(default)s'. Choices: %s"
             % scheme_names
         ),
     )

If you can make it that fix, I can merge it in no time.

Regarding RawTextHelpFormatter, please help me understand the idea. Even with the new formatter, the choices line is very long. Maybe let's separate fixing a crash from further improving the output.

Thanks!

@hartwork hartwork changed the title Fix output for --help [>=1.9.1] Fix output for --help Jan 11, 2024
@nehaljwani
Copy link
Contributor Author

Hi @hartwork, I've updated the PR with the proposed fix.

Copy link
Collaborator

@hartwork hartwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nehaljwani thank you!

@hartwork hartwork merged commit 9af0297 into pycontribs:main Jan 12, 2024
15 checks passed
@isidroas
Copy link

Could this fix be uploaded to pypi.org?

The last version is 1.9.1 from Dec 11, 2023

@hartwork
Copy link
Collaborator

@isidroas my hands are tied, this needs @ssbarnea

@phlummox
Copy link

@hartwork, is it possible to at least make a new release on GitHub? That makes it possible to do a pip install based on that release, which many might feel more comfortable with than just depending on the main branch. I'm not sure whether that would require @ssbarnea's intervention or not.

@hartwork
Copy link
Collaborator

@phlummox I lack permissions to…

  • push to main directly
  • merge or approach my own pull requests
  • upload to PyPI directly

…but it seems I can

  • approve and then merge pull requests of others
  • push Git tags
  • create GitHub releases
  • trigger PyPI release through pushing Git tags

With that it seems I managed to release 1.9.2 to both PyPI (through GitHub Actions) and GitHub releases now.

I should not that workflow push.yml is broken

broken_push_Screenshot_20240622_193940

…because the referenced target…

uses: ansible/devtools/.github/workflows/push.yml@main

…apparently no longer exists at that location. If you can help with a pull request to repair, I may be able to approve and merge it. Any chance?

nehaljwani added a commit to regro-cf-autotick-bot/ansi2html-feedstock that referenced this pull request Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants