Skip to content

Add tag_filter config option #69

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

Merged
merged 20 commits into from
Oct 31, 2022
Merged

Conversation

vortechs2000
Copy link

@vortechs2000 vortechs2000 commented Oct 25, 2022

tag_filter lets one specify either a regexp or a callback to filter which tags are considered. This is helpful in monorepos where many product tags exist.

Potential fix for #68

@vortechs2000
Copy link
Author

If this looks helpful, I'll make sure the formatting/docs/tests are fixed up.

@codecov
Copy link

codecov bot commented Oct 26, 2022

Codecov Report

Base: 93.19% // Head: 92.92% // Decreases project coverage by -0.26% ⚠️

Coverage data is based on head (1724aa7) compared to base (44e4136).
Patch coverage: 90.00% of modified lines in pull request are covered.

❗ Current head 1724aa7 differs from pull request most recent head 3cbb3ef. Consider uploading reports for the commit 3cbb3ef to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #69      +/-   ##
==========================================
- Coverage   93.19%   92.92%   -0.27%     
==========================================
  Files           1        1              
  Lines         382      410      +28     
  Branches       61       65       +4     
==========================================
+ Hits          356      381      +25     
- Misses         22       24       +2     
- Partials        4        5       +1     
Impacted Files Coverage Δ
setuptools_git_versioning.py 92.92% <90.00%> (-0.27%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@vortechs2000 vortechs2000 marked this pull request as ready for review October 26, 2022 20:11
@dolfinus
Copy link
Owner

Hi, thank you for your contribution!

I see here 2 ways to implement that:

  1. Pass prefix directly to git tag -l command (but this is not a regexp):
OPTIONS
       -l, --list
           List tags. With optional <pattern>..., e.g.  git tag --list 'v-*', list only the tags that match the pattern(s).

           Running "git tag" without arguments also lists all tags. The pattern is a shell wildcard (i.e., matched using fnmatch(3)). Multiple patterns may be given; if any of them matches, the tag is shown.
  1. Add tag_filter option which could be a regexp or a callback (like tag_formatter and branch_formatter), which allows users to discard tags not only by prefix, but by any logic they could implement

Also I'm not sure about implicit change of default value of tag_formatter according to tag_prefix.

@vortechs2000
Copy link
Author

@dolfinus do you have a preference between option 1 and option 2? I don't think the regexp is required anymore for what I'm trying to do, so option 1 would be sufficient for what I need. Option 2 is definitely more flexible.

I wasn't sure about the implicit default value change for tag_formatter either, but it definitely simplifies things for the user when it works. (and conversely, makes things more confusing if it doesn't!). I suppose rather than doing that, it could just be listed in the docs as a recommendation if you're using a simple tag_prefix.

@dolfinus
Copy link
Owner

I prefer option 2, it is more flexible, and also consistent with other options already present in the project.

Regarding tag_formatter, I think it will be enough to mention this option in the documentation of tag_filter. Actually, user can implement regexp or callback to be used in both options

@vortechs2000
Copy link
Author

I prefer option 2, it is more flexible, and also consistent with other options already present in the project.

Sounds good - I'll make the adjustments

@vortechs2000 vortechs2000 marked this pull request as draft October 27, 2022 19:58
@vortechs2000 vortechs2000 changed the title Add tag_prefix config option Add tag_filter config option Oct 27, 2022
The tag_filter option allows one to filter the list of tags
using either a regexp or a callback, similar to the tag_formatter
option.  This is helpful in monorepos where many product's tags exist.
@vortechs2000 vortechs2000 marked this pull request as ready for review October 27, 2022 20:26
None is a valid return value.
Also fix a couple spots that still had just `str` as the return type

Adjust docs
@vortechs2000
Copy link
Author

Squashed the history down to make this a bit cleaner - just the tag_filter changes in the commits now

filter_fxn -> filter_callback
If the date param is set, use it to set the GIT_COMMITTER_DATE
environment variable. This ensures the commit order when using the
`creatordate` sort order, and eliminates the need for the time.sleep(1)
in some of the tests.
Remove unnecessary time.sleep(1) calls - this speeds up the test
significantly.

Remove different asserts in `test_tag_sort_by_tag_date()` - with the
commit date set, the results are now consistent.
This just removes the tags that don't match from the
list of tags, which is how it was supposed to work originally.
Create tag in same loop as commit it test_tag_filter()

Use same function for filter and formatter in test_tag_filter_external()
@vortechs2000
Copy link
Author

Ok @dolfinus, see what you think of that changeset. Note that the time.sleep(1) calls in the test_tags.py tests are no longer required, so the tests should run a bit faster! 😁

Not sure what I was thinking before, but this needs to be just the
ISO 8601 formatted date string, not a ``--date`` option
Done while debugging, and forgot to revert
Test was busted because of the broken committer date fix in util.py.
Now that the committer date is fixed, this works again with the original,
correct code.
Fixed conflict on get_tags() in setuptools_git_versioning.py
load_callable -> _load_callable
Internal function prefixed with `_` now
@vortechs2000
Copy link
Author

@dolfinus - ok, addressed your comments on the latest patchset, and I think the code conforms to the changes you just made in master.

The code coverage fails because the tests don't hit the case in _load_filter_tag where the tag_filter passed in is already a direct callable. That code mirrors the code in the other _load_* functions that handle callables, so I think we want it there. Thoughts?

@dolfinus dolfinus merged commit 4c31a4b into dolfinus:master Oct 31, 2022
@dolfinus
Copy link
Owner

Thank you, I'll check what can be done with coverage

@vortechs2000 vortechs2000 deleted the add_tag_prefix branch October 31, 2022 21:48
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy