-
Notifications
You must be signed in to change notification settings - Fork 547
Various small improvements #293
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b3559b4
:snake: Add version bumping script
KevinHock 0b5574a
:snake: `chmod +x` the scripts in scripts/
KevinHock ff6c4a5
:snake: Remove unnecessary `(object)` inheritance
KevinHock eac6919
:bug: Catch TypeError from `from_plugin_classname`
KevinHock 5ca1d7e
:snake: Remove all __future__ imports
KevinHock 74d3787
:performing_arts: Improve the performance of line regexes
KevinHock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| #!/usr/bin/python3 | ||
| from __future__ import print_function | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| #!/usr/bin/env python3 | ||
| """Bumps the detect-secrets version, | ||
| in both `detect_secrets/__init__.py` and `README.md`. | ||
|
|
||
| Then commits. | ||
| """ | ||
| import argparse | ||
| import pathlib | ||
| import subprocess | ||
| import sys | ||
|
|
||
|
|
||
| PROJECT_ROOT = pathlib.Path(__file__).absolute().parent.parent | ||
| INIT_FILE_PATH = PROJECT_ROOT.joinpath('detect_secrets/__init__.py') | ||
| README_FILE_PATH = PROJECT_ROOT.joinpath('README.md') | ||
|
|
||
|
|
||
| def _argparse_bump_type(value): | ||
| VALID_BUMP_TYPES = ('major', 'minor', 'patch') | ||
|
|
||
| if value in VALID_BUMP_TYPES: | ||
| return value | ||
|
|
||
| raise argparse.ArgumentTypeError( | ||
| f"Argument {value} must be one 'major', 'minor', 'patch'.", | ||
| ) | ||
|
|
||
|
|
||
| def parse_args(argv): | ||
| parser = argparse.ArgumentParser( | ||
| description=__doc__, | ||
| prog='bumpity', | ||
| ) | ||
| parser.add_argument( | ||
| '--bump', | ||
| help='the bump type, specified as one of {major, minor, patch}', | ||
| metavar='{major,minor,patch}', | ||
| type=_argparse_bump_type, | ||
| ) | ||
|
|
||
| return parser.parse_args(argv) | ||
|
|
||
|
|
||
| def get_current_version(): | ||
| with open(INIT_FILE_PATH) as init_file: | ||
| first_line = init_file.read().splitlines()[0] | ||
| # e.g. VERSION = '0.13.0' | ||
| _, semver = first_line.replace(' ', '').split('=') | ||
| return map( | ||
| int, | ||
| # e.g. '0.13.0' | ||
| semver.strip("'").split('.'), | ||
| ) | ||
|
|
||
|
|
||
| def update_init_file(new_version): | ||
| with open(INIT_FILE_PATH, 'w') as init_file: | ||
| init_file.write(f"VERSION = '{new_version}'\n") | ||
|
|
||
|
|
||
| def update_readme(old_version, new_version): | ||
| with open(README_FILE_PATH, 'r') as readme: | ||
| original_text = readme.read() | ||
| with open(README_FILE_PATH, 'w') as readme: | ||
| readme.write( | ||
| original_text.replace(old_version, new_version), | ||
| ) | ||
|
|
||
|
|
||
| def stage_and_commit(new_version): | ||
| # Stage files | ||
| subprocess.check_output( | ||
| ( | ||
| 'git', | ||
| 'add', | ||
| INIT_FILE_PATH, | ||
| README_FILE_PATH, | ||
| ), | ||
| ) | ||
|
|
||
| # Check they are the only ones staged | ||
| staged_files = subprocess.check_output( | ||
| ( | ||
| 'git', | ||
| 'diff', | ||
| '--staged', | ||
| '--name-only', | ||
| ), | ||
| ).splitlines() | ||
| if len(staged_files) != 2: | ||
| raise RuntimeWarning('More files staged than __init__.py and README.md') | ||
|
|
||
| # Make the commit | ||
| subprocess.check_output( | ||
| ( | ||
| 'git', | ||
| 'commit', | ||
| '--message', | ||
| f':fist: Bumping version to {new_version}', | ||
| INIT_FILE_PATH, | ||
| README_FILE_PATH, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def main(argv=sys.argv[1:]): | ||
| if not argv: | ||
| argv.append('--help') | ||
| args = parse_args(argv) | ||
|
|
||
| major, minor, patch = get_current_version() | ||
| old_version = f'{major}.{minor}.{patch}' | ||
|
|
||
| if args.bump == 'major': | ||
| major += 1 | ||
| minor = 0 | ||
| patch = 0 | ||
| elif args.bump == 'minor': | ||
| minor += 1 | ||
| patch = 0 | ||
| else: | ||
| patch += 1 | ||
|
|
||
| new_version = f'{major}.{minor}.{patch}' | ||
| update_init_file(new_version) | ||
| update_readme(old_version, new_version) | ||
| stage_and_commit(new_version) | ||
| print("Don't forget to update CHANGELOG.md too!") | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| #!/usr/bin/env python3 | ||
| from __future__ import print_function | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a test for this? I thought you needed to wrap the
X for X in Ysyntax in an array, but I might be wrong.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.
There is a test π
detect-secrets/tests/plugins/high_entropy_strings_test.py
Lines 97 to 133 in ca266b1