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

Updating exclude signatures to use either one of the formats #290

Merged
merged 11 commits into from
Dec 9, 2021

Conversation

mayuriesha
Copy link
Contributor

To help us get this pull request reviewed and merged quickly, please be sure to include the following items:

  • Tests (if applicable)
  • Documentation (if applicable)
  • Changelog entry
  • A full explanation here in the PR description of the work done

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Tests
  • Other

Backward Compatibility

Is this change backward compatible with the most recently released version? Does it introduce changes which might change the user experience in any way? Does it alter the API in any way?

  • Yes (backward compatible)
  • No (breaking changes)

Issue Linking

What's new?

  • Updating exclude signatures to use either old or new format

…xcluded_signatures instead of global_options.exclude_signatures
tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tests/test_base_scanner.py Show resolved Hide resolved
Copy link
Contributor

@rbailey-godaddy rbailey-godaddy left a comment

Choose a reason for hiding this comment

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

A few quick impressions as I look at this first thing on my return... ;-) I'm assuming you'll have a few more commits coming and I'll re-review at that point.

pyproject.toml Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/types.py Show resolved Hide resolved
Copy link
Contributor

@rbailey-godaddy rbailey-godaddy left a comment

Choose a reason for hiding this comment

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

I think this has the same basic problem as the other PR, in the sense that we want to process the global and local lists separately so they are allowed to have different representations. You should be able to use the same approach to disconnect them.

And, although not strictly necessary, I would advocate changing the return from a tuple to a set (but leave it alone if @tarkatronic or anybody else thinks this would be problematic).

@mayuriesha
Copy link
Contributor Author

mayuriesha commented Dec 7, 2021

@rbailey-godaddy I have created an issue to address the last few review comment as part of another PR after 3.0 is released

tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tests/test_git_repo_scanner.py Outdated Show resolved Hide resolved
tests/test_git_repo_scanner.py Outdated Show resolved Hide resolved
tests/test_git_repo_scanner.py Outdated Show resolved Hide resolved
Copy link
Contributor

@rbailey-godaddy rbailey-godaddy left a comment

Choose a reason for hiding this comment

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

This layers on top of @tarkatronic 's comments, mostly in eliminating dangling use of removed variables and preserving exception semantics.

tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
tartufo/scanner.py Outdated Show resolved Hide resolved
Copy link
Contributor

@rbailey-godaddy rbailey-godaddy left a comment

Choose a reason for hiding this comment

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

I'm lukewarm on the unnecessary type thrashing but okay with this as-is if you just want to get it out and quit fiddling around. ;-)

Comment on lines 358 to 362
signatures = tuple(
signature["signature"]
for signature in cast(List[Dict[str, str]], signatures)
]
self._excluded_signatures = tuple(cast(List[str], signatures))
for signature in cast(Tuple[Dict[str, str]], signatures)
)
self._excluded_signatures = tuple(set(signatures))
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes no sense to me. Why use a tuple comprehension, and then convert it to a set, and then convert it back to a tuple -- instead of starting with a set comprehension and then converting it once? If we're worried about mutating the type of signatures, then just eliminate the intermediate variable and store directly into the destination.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah... I had very similar thoughts. And had your words echoing in my head as I did it. I just didn't want to have to think about all the other places that might be depending on a tuple vs a set. In theory it shouldn't matter. But... you never know.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rbailey-godaddy Since it's already getting to dinner time, I'm happy to leave this stewing overnight in case you want to take a moment in the morning to un-thrashify this code. 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

But, also want to keep in mind that we're more than a week overdue for 3.0 now, so... limiting scope is good.

Copy link
Contributor

Choose a reason for hiding this comment

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

I pushed a commit that makes me moderately happy. (Well, two because pylint is so anal.) For "proper" usage, this makes no changes that are visible outside of the modified property function. Changes in behavior:

  • If you mix old and new style specifications, it now works. (Fixed unit test to confirm this.) This does not affect whether or not you can -- or should -- actually mix styles in your configuration files, only that we aren't artificially restricting things ourselves.
  • If you pass new-style entry that is missing signature key, it tells you that explicitly. Previously it would raise an unhandled KeyError.
  • If you (somehow) pass an entry that's neither old-style nor new-style, it tells you that explicitly. Previously such alien input would be treated as "old-style" and inserted directly into the return value tuple, where it probably would be ignored.

As a matter of taste, "tells you explicitly" means "raises meaningful exception and aborts" rather than "whines, ignores the erroneous entry, and continues." I feel if you have b0rked configuration files, you should fix them.

Also, I marked all of the conversations above "resolved" where they discussed outdated code.

* No changes to input or output types
* Remove intermediate churning and explicit casting
* Sanely report missing new-style key (by aborting rather than skipping
  the malformed expression -- matter of taste)
* Sanely report bizarre input (neither new nor old style)
* As side effect, remove prohibition against mixing styles, although
  whether or not TOML support will puke if you try it is another story
* Unit test updated to verify mix-n-match behavior
Comment on lines +355 to +357
for signature in tuple(
self.global_options.exclude_signatures or []
) + tuple(self.config_data.get("exclude_signatures", [])):
Copy link
Contributor

Choose a reason for hiding this comment

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

>>> () + []
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate tuple (not "list") to tuple
>>>

Careful of the mixture of lists and tuples here. That was part of the cause for the previous type thrashing. 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

That's why both of them are being explicitly converted from lists to tuples here. Also, I played with this extensively last night and python definitely thinks both self.global_options.exclude_signatures and self.config_data["exclude_signatures"] are lists, which is why I used empty lists for defaults -- to maintain type consistency.

This is strangely bizarre in the sense that self.global_options.exclude_signatures pretty clearly appears to be defined as a tuple rather than a list, but if you try removing either of the tuple conversions you get errors complaining that they are lists and that you aren't allowed to concatenate lists this way (or combine a list and a tuple, as the case may be).

I didn't have enough ambition to trace down where the actual content is coming from to understand why mypy isn't whining about some assignment somewhere that is putting a list into a tuple type... Unless it's happening under the covers in click.

@tarkatronic tarkatronic merged commit 7603d79 into godaddy:v3.x Dec 9, 2021
rbailey-godaddy pushed a commit to mayuriesha/tartufo that referenced this pull request Dec 9, 2021
Clean up `included_paths` and `excluded_paths` with basically the same
logic used for godaddy#290.
tarkatronic pushed a commit that referenced this pull request Dec 9, 2021
… table of tables (#289)

* Supporting table of contents for include and exclude path patterns

* Updating unit tests and documentation

* Updating logic for inlcude and exclude paths to use two different formats

* Adding try catch

* Minor wording changes

* Updating Changelog

* Addressing review comments on deprecation message

* Processing the patterns added in the config as well

* Updating unit tests to verify patterns are processed from config and global options

* Updating include-path-patterns

* Update path processing

Clean up `included_paths` and `excluded_paths` with basically the same
logic used for #290.

* reformat merged test file with black

Co-authored-by: Scott Bailey <scott.bailey@godaddy.com>
Co-authored-by: Scott Bailey <72747501+rbailey-godaddy@users.noreply.github.com>
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.

None yet

4 participants