Skip to content

Add a --show flag for usethis badge#605

Merged
nathanjmcdougall merged 4 commits into
usethis-python:mainfrom
Z-Fran:424-add-show-for-badge
May 8, 2025
Merged

Add a --show flag for usethis badge#605
nathanjmcdougall merged 4 commits into
usethis-python:mainfrom
Z-Fran:424-add-show-for-badge

Conversation

@Z-Fran
Copy link
Copy Markdown
Contributor

@Z-Fran Z-Fran commented May 6, 2025

Implementation of #424.

Use cases:

  1. only use --show flag:
usethis badge pypi --show 

image

It will print the badge to the console and add the badge.

  1. use --show and --quiet at the same time:
    It will still print the badge to the console.

  2. use --show and --remove at the same time:
    It will print the badge to the console and remove the badge.

If anything doesn’t meet expectations, please let me know and I’ll make the changes.

Comment thread src/usethis/_interface/badge.py Outdated
@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

Hi @Z-Fran!

Nice to meet you the other day, and thank you so much for your contribution.

First step, please configure pre-commit for local development. I realized this been documented anywhere so apologies (opened #606 for this). Just do this with usethis tool pre-commit and it will install the pre-commit hooks in your git repo. This is the reason the GitHub Actions pipeline is failing at the moment.

Also, I'm going to want to add some tests for this code. If you don't want to add them, I'd be happy to add them myself - just let me know.

One naming change I've flagged above and then regarding your points:

  1. At the moment, the --show flag will not prevent the badge from be added. However, my preference is that the --show parameter, when used, would prevent both badge removal and badge addition.

  2. That's fine for now. In the long run, I'd like the --quiet flag to always take effect, even when the --show command is used, i.e. no output should be displayed. There are a few reasons for this, but basically it boils down to the fact that you really want to be able to trust the --quiet flag. Arguably it also makes the architecture simpler. What I'd say is don't worry about this, we'll resolve it via Never use simple print #610.

  3. Same as point 1 - I would like to change this behaviour so that if the --show parameter is used, then the --remove option is completely ignored.

Thanks for taking the time to work on this issue.

Comment thread src/usethis/_interface/badge.py Outdated
@Z-Fran
Copy link
Copy Markdown
Contributor Author

Z-Fran commented May 7, 2025

Hi @Z-Fran!

Nice to meet you the other day, and thank you so much for your contribution.

First step, please configure pre-commit for local development. I realized this been documented anywhere so apologies (opened #606 for this). Just do this with usethis tool pre-commit and it will install the pre-commit hooks in your git repo. This is the reason the GitHub Actions pipeline is failing at the moment.

Also, I'm going to want to add some tests for this code. If you don't want to add them, I'd be happy to add them myself - just let me know.

One naming change I've flagged above and then regarding your points:

  1. At the moment, the --show flag will not prevent the badge from be added. However, my preference is that the --show parameter, when used, would prevent both badge removal and badge addition.
  2. That's fine for now. In the long run, I'd like the --quiet flag to always take effect, even when the --show command is used, i.e. no output should be displayed. There are a few reasons for this, but basically it boils down to the fact that you really want to be able to trust the --quiet flag. Arguably it also makes the architecture simpler. What I'd say is don't worry about this, we'll resolve it via Never use simple print #610.
  3. Same as point 1 - I would like to change this behaviour so that if the --show parameter is used, then the --remove option is completely ignored.

Thanks for taking the time to work on this issue.

Hi @nathanjmcdougall , I have made some changes:

  1. rename _modify_badge to _badge_effect

  2. ignore --remove and don't add badges when setting --show

  3. add some simple tests
    I want to use assert result.output == get_pypi_badge().markdown to test, but an error occurred when I tried to import get_pypi_badge().
    If you have a better test, please modify it!

  4. code has passed pre-commit hooks.

  5. I don't resolve the --quiet flag.

Comment thread tests/usethis/_interface/test_interface_badge.py
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 7, 2025

CodSpeed Performance Report

Merging #605 will not alter performance

Comparing Z-Fran:424-add-show-for-badge (c311175) with main (6a77f3f)

Summary

✅ 1 untouched benchmarks

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.54%. Comparing base (fd41170) to head (c311175).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #605   +/-   ##
=======================================
  Coverage   97.54%   97.54%           
=======================================
  Files         102      102           
  Lines        4439     4444    +5     
=======================================
+ Hits         4330     4335    +5     
  Misses        109      109           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nathanjmcdougall nathanjmcdougall merged commit dd31162 into usethis-python:main May 8, 2025
17 checks passed
@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

Thanks @Z-Fran !

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@Z-Fran I've just released this new feature in v0.11.0. Thank you again.

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