-
Notifications
You must be signed in to change notification settings - Fork 306
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
Use red text when printing errors on command line #649
Conversation
Seems like doing something to what try:
import colorama
# Lots of different errors can come from this, including SystemError and
# ImportError.
except Exception:
colorama = None
if colorama:
... It would be nice to actually confirm these changes would be handled gracefully on Windows, I created #650 to explore testing against these platforms in CI.
I'd take a look at pypa/pip#8135 and see if we want to mimic the same flag here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this! I haven't tried it yet, but I'm looking forward to it. I've got some questions/suggestions before merging.
For extra credit, could you include an example screenshot?
Given the open questions and TODOs, I've converted this to a draft PR. |
@bhrutledge per your request, I included some example screenshots above of what it looks like |
d6a6926
to
5e26675
Compare
5e26675
to
9eb2281
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvements. I think there's still some work to do re: the --no-color
option.
Also, thanks for graciously accepting my earlier marking of the PR as a draft, and for marking it as "Ready For Review". In retrospect, I didn't need to do that, and can see how it might have been confusing/surprising.
05c78a9
to
e54201b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @callmecampos. Unfortunately, the Settings
approach here won't work. Feel free to ask questions.
twine/commands/check.py
Outdated
@@ -143,6 +148,7 @@ def check(dists: List[str], output_stream: IO[str] = sys.stdout) -> bool: | |||
|
|||
def main(args: List[str]) -> bool: | |||
parser = argparse.ArgumentParser(prog="twine check") | |||
settings.Settings.register_argparse_arguments(parser) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Settings
class is currently only for upload
and register
settings, so this approach won't work, because it adds all of those options to check
:
$ twine check --help
usage: twine check [-h] [-r REPOSITORY] [--repository-url REPOSITORY_URL] [-s]
[--sign-with SIGN_WITH] [-i IDENTITY] [-u USERNAME]
[-p PASSWORD] [--non-interactive] [-c COMMENT]
[--config-file CONFIG_FILE] [--skip-existing] [--cert path]
[--client-cert path] [--verbose] [--disable-progress-bar]
[--no-color]
dist [dist ...]
Compared to the current:
$ twine check --help
usage: twine check [-h] dist [dist ...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bhrutledge How do you propose we share commands like --no-color
between multiple sub-commands instead? In #659, @sigmavirus24 said that the Settings
object should be used for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far we've needed thse arguments for all the commands and check
was implemented while I was not paying attention. Otherwise, we'd have resolved this sooner. I think separate classmethods for things that don't want need all of those arguments is the way to go. Then register_argparse_arguments
can call those and then add its own arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that check
sort of skirted this issue and should eventually be fixed.
I think separate classmethods for things that don't want need all of those arguments is the way to go.
Can you elaborate on this? This kind of sounds like what #659 could solve with class composition/inheritance. Do you mean extra classmethods on the Settings
class instead? Something like Settings._add_register_and_upload_arguments
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on this?
Sure.
This kind of sounds like what #659 could solve with class composition/inheritance.
Except that the TwineCommand class would never be part of the public API the way Settings would be as an escape hatch from the high-level porcelain API planned.
I'm thinking of breaking up registration into class methods based on relationship:
Settings.register_repository_arguments(...)
Settings.register_gpg_arguments(...)
Settings.register_identity_arguments(...)
And those are called by
class Settings:
@classmethod
def register_upload_arguments(cls, ...):
cls.register_repository_arguments(...)
cls.register_gpg_arguments(...)
cls.register_identity_arguments(...)
# plus anything specific to upload
Likewise for check and register. I doubt register should have --comment
or --skip-existing
, so those would be specific to upload. This would give us logical groupings that are more explicit than what we have no and allow commands to register what they thematically need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sigmavirus24 would you like @callmecampos to move forward with that in this PR? Should it come before this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be worried about that blocking this PR. As a transitory state, we could have check
use all the options and in @callmecampos's next PR they could "fix" it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: adding class methods to Settings
, I support that in theory, but not as part of this PR. I also note that there are number of pending issues to improve check
, which makes me wonder if the Settings
restructuring could be part of that work, and maybe released as Twine 4.0, to give us some flexibility on the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and maybe released as Twine 4.0, to give us some flexibility on the API.
Why as 4.0? Also perhaps this isn't the best place to have this long-winded discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also worried about how we're approaching this. We don't seem focused or aligned on a goal right now and instead we're bandying about solutions and focusing on those.
What are our goals and constraints for the solution beyond "Can disable color?"
d217e43
to
e683bff
Compare
Move --no-color to base command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for accepting my proposal. :)
@callmecampos This was released in 3.2.0. Thanks again for your work on this. |
Per discussion in #511, when twine emits error messages on the command line, we now print them in red.
Here are a couple examples from my terminal on macOS Catalina (v10.15.4):
Before merging, I want to address some of the following:
Gracefully handle colorama not being available(only necessary in pip/logging.py since they've vendored colorama)And an example with the
--no-color
flag: