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

Setup basic logging functionality(existing output) with 1 level of verbosity #670

Merged
merged 4 commits into from
Jul 15, 2020

Conversation

VikramJayanthi17
Copy link
Contributor

As suggested by @bhrutledge in #669, I created a new branch and have replicated existing verbose functionality(distribution names, signatures,Etc.) using stdlib. The goal is to use this logging system and potentially add multiple levels of verbosity and consequently more detailed output(as mentioned in #381).

@bhrutledge
Copy link
Contributor

@VikramJayanthi17 Thanks for submitting this. I'm aiming to review in the next day or two.

Copy link
Contributor

@bhrutledge bhrutledge left a comment

Choose a reason for hiding this comment

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

This is great! I found it much easier to review, and I think it lays a good foundation for adding more output to -v. I think it needs just a few small structural changes, and of course I have some nitpicks.

Comment on lines -30 to +29
import importlib.metadata as importlib_metadata
from importlib import metadata as importlib_metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

What prompted this change?

Copy link
Contributor Author

@VikramJayanthi17 VikramJayanthi17 Jul 8, 2020

Choose a reason for hiding this comment

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

tox -e format actually did this automatically. Will change it back.

Edit:

It fails to pass the linting test if I change this back. Any advice on how to proceed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right, isort just had a major version upgrade. I restored this in 8eabc53. I'll plan to followup up with some isort tweaking in a separate PR.

tests/test_upload.py Outdated Show resolved Hide resolved
tests/test_upload.py Outdated Show resolved Hide resolved
tests/test_settings.py Outdated Show resolved Hide resolved
tests/test_settings.py Outdated Show resolved Hide resolved
twine/commands/upload.py Outdated Show resolved Hide resolved
twine/settings.py Outdated Show resolved Hide resolved
twine/utils.py Outdated Show resolved Hide resolved
twine/settings.py Outdated Show resolved Hide resolved
twine/settings.py Outdated Show resolved Hide resolved
Copy link
Contributor

@bhrutledge bhrutledge left a comment

Choose a reason for hiding this comment

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

@VikramJayanthi17 Thanks for the changes. I took the liberty of pushing one more structural change (described in a comment) to address a gotcha, figuring it'd be easy to revert if necessary. What do you think?

Comment on lines -30 to +29
import importlib.metadata as importlib_metadata
from importlib import metadata as importlib_metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right, isort just had a major version upgrade. I restored this in 8eabc53. I'll plan to followup up with some isort tweaking in a separate PR.

Comment on lines +153 to +163
@property
def verbose(self) -> bool:
return self._verbose

@verbose.setter
def verbose(self, verbose: bool) -> None:
"""Initialize a logger based on the --verbose option."""
self._verbose = verbose
root_logger = logging.getLogger("twine")
root_logger.addHandler(logging.StreamHandler(sys.stdout))
root_logger.setLevel(logging.INFO if verbose else logging.WARNING)
Copy link
Contributor

@bhrutledge bhrutledge Jul 9, 2020

Choose a reason for hiding this comment

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

Seeing the switch from capsys to caplog in test_upload.py made me realize that we weren't actually testing that verbose messages were printed to stdout.

captured = caplog.text
assert captured.count(f"{filename} ({expected_size})") == 1
assert captured.count(f"Signed with {signed_filename}") == 1

Furthermore, the tests were still setting Settings.verbose directly, which wouldn't actually set up logging:

upload_settings.sign = True
upload_settings.verbose = True
package = upload._make_package(filename, signatures, upload_settings)

To keep the existing API, avoid rewriting all of the upload tests, and avoid similar gotchas in the future, I made Settings.verbose a @property and moved the logging setup there in 1fd2f58.

Comment on lines +276 to +281
@pytest.mark.parametrize(
"verbose", [True, False],
)
def test_check_status_code_for_missing_status_code(
capsys, repo_url, verbose, make_settings
):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this test should have been parameterized when it was written.

@VikramJayanthi17
Copy link
Contributor Author

@bhrutledge That change makes a lot of sense, it looks good to me! Thanks for the help.

@VikramJayanthi17
Copy link
Contributor Author

@sigmavirus24 Do you have any additional input on this PR? I can't seem to add you as a reviewer.

@di di self-requested a review July 13, 2020 19:33
@bhrutledge
Copy link
Contributor

Unless @sigmavirus24 has any additional comments, I'll merge this tomorrow morning.

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.

3 participants