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

ANSI rendering of rst markup. #24

Merged
merged 1 commit into from
Mar 7, 2017
Merged

ANSI rendering of rst markup. #24

merged 1 commit into from
Mar 7, 2017

Conversation

anntzer
Copy link
Owner

@anntzer anntzer commented Mar 1, 2017

See #22. Note that this PR depends on #20 (the first few commits are from that PR).

@anntzer
Copy link
Owner Author

anntzer commented Mar 4, 2017

Rebased.

@@ -5,4 +5,4 @@ universal=1
source=defopt

[coverage:report]
fail_under=98
fail_under=97
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you need to change this? I don't think your changes reduced coverage.

Copy link
Owner Author

Choose a reason for hiding this comment

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

The return in

    if not isinstance(tag, str) and tag is not None:
        return

doesn't get exercised (and I don't think it's worth writing a test to specifically test it -- it comes straight from the upstream implementation). That's enough for dropping the coverage.

@@ -19,12 +19,13 @@
install_requires=[
'docutils',
'sphinxcontrib-napoleon>=0.5.1',
'funcsigs;python_version<"3"',
'funcsigs;python_version<"3.3"',
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the record, I don't intend to support 3.0-3.2, but I don't have a problem with changing this.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't plan to use them either, but that's just a more convenient way to say "function signatures were introduced in 3.3"

defopt.py Outdated
def _itertext_ansi(node):
# Implementation modified from `ElementTree.Element.itertext`.
tag = node.tag
if not isinstance(tag, str) and tag is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is basestring in the Python 2 version of itertext. We should account for that.

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

defopt.py Outdated
except ImportError: # pragma: no cover
pass
else:
colorama.init() # pragma: no cover
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this is the way colorama tells you to use it, but since defopt promises to not modify the functions given, I think it's also reasonable to expect it to have no side effects (especially when you're not even using the CLI). Instead, I think we should use colorama.colorama_text to wrap just the call to parser.parse_args inside run.

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

defopt.py Outdated
tag = node.tag
if not isinstance(tag, str) and tag is not None:
return
ansi_code = {"emphasis": "\033[1m", "strong": "\033[3m"}.get(tag, "")
Copy link
Collaborator

Choose a reason for hiding this comment

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

You have these reversed - 1 is bold, 3 is italic.

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

@evanunderscore
Copy link
Collaborator

Thanks for your work. Overall the implementation is great, there are just a few things I'd like to get cleaned up before I merge this in.

defopt.py Outdated
def _itertext_ansi(node):
# Implementation modified from `ElementTree.Element.itertext`.
tag = node.tag
if (not isinstance(tag, (basestring if sys.version_info < (3,) else str))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry to keep getting you to change this, but this is a bit cluttered for my taste. Can you instead add a definition for basestring at the top with the rest of the compatibility stuff?

defopt.py Outdated
@@ -12,6 +12,7 @@
from argparse import (SUPPRESS, ArgumentParser, RawTextHelpFormatter,
ArgumentDefaultsHelpFormatter)
from collections import defaultdict, namedtuple, OrderedDict
import contextlib
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are split into separate subgroups for import x and from x import y. I was aiming for what you get from isort, though I'm not actually running the tool so this may differ slightly.

colorama catches the raw ANSI **strong** code and handles it properly
on Windows, but does not expose *emphasis* (because the Windows console
cannot render it -- it will remove still remove it from the stream
though, so there isn't any garbled output).  So we directly use raw ANSI
codes.
@anntzer
Copy link
Owner Author

anntzer commented Mar 7, 2017

done

@evanunderscore
Copy link
Collaborator

Perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants