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

Add support for Python 3.12 #810

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ['3.8', '3.9', '3.10', '3.11']
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python: ['3.8', '3.9', '3.10', '3.11']
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
12 changes: 9 additions & 3 deletions detect_secrets/core/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,19 @@ def _is_filtered_out(required_filter_parameters: Iterable[str], **kwargs: Any) -
try:
if call_function_with_arguments(filter_fn, **kwargs):
if 'secret' in kwargs:
debug_msg = f'Skipping "{kwargs["secret"]}" due to `{filter_fn.path}`.'
debug_msg = f'Skipping "{0}" due to `{1}`.'.format(
kwargs['secret'],
filter_fn.path,
)
elif list(kwargs.keys()) == ['filename']:
# We want to make sure this is only run if we're skipping files (as compared
# to other filters that may include `filename` as a parameter).
debug_msg = f'Skipping "{kwargs["filename"]}" due to `{filter_fn.path}`'
debug_msg = 'Skipping "{0}" due to `{1}`'.format(
kwargs['filename'],
filter_fn.path,
)
else:
debug_msg = f'Skipping secret due to `{filter_fn.path}`.'
debug_msg = 'Skipping secret due to `{0}`.'.format(filter_fn.path)

log.info(debug_msg)
return True
Expand Down
4 changes: 2 additions & 2 deletions detect_secrets/pre_commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ def pretty_print_diagnostics(secrets: SecretsCollection, width: int = 80) -> Non
)
for suggestion in [
'For information about putting your secrets in a safer place, '
f'please ask {os.environ.get("DETECT_SECRETS_SECURITY_TEAM", "in #security")}',
'please ask {0}'.format(os.environ.get('DETECT_SECRETS_SECURITY_TEAM', 'in #security')),

'Mark false positives with an inline '
f'`{color.colorize("pragma: allowlist secret", color.AnsiColor.BOLD)}` comment',
'`{0}` comment'.format(color.colorize('pragma: allowlist secret', color.AnsiColor.BOLD)),
]:
print(wrapper.fill(suggestion))

Expand Down
18 changes: 12 additions & 6 deletions tests/audit/report_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,24 @@ def create_file_with_content(content):
@pytest.fixture
def baseline_file():
# Create our own SecretsCollection manually, so that we have fine-tuned control.
first_content = textwrap.dedent(f"""
first_content = textwrap.dedent(
f"""
url = {url_format.format(first_secret)}
example = {url_format.format(random_secret)}
link = {url_format.format(first_secret)}
""")[1:]
second_content = textwrap.dedent(f"""
""",
)[1:]
second_content = textwrap.dedent(
f"""
url = {url_format.format(second_secret)}
example = {url_format.format(random_secret)}
""")[1:]
third_content = textwrap.dedent(f"""
""",
)[1:]
third_content = textwrap.dedent(
f"""
aws_access_key = {aws_secret}
""")[1:]
""",
)[1:]

with create_file_with_content(first_content) as first_file, \
create_file_with_content(second_content) as second_file, \
Expand Down
2 changes: 1 addition & 1 deletion tests/core/upgrades/upgrade_to_v1_0_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_custom_plugins_does_not_pollute_settings():
assert new_baseline['plugins_used'] == [
{
'name': 'HippoDetector',
'path': f'file://{os.path.abspath("testing/plugins.py")}',
'path': 'file://{0}'.format(os.path.abspath('testing/plugins.py')),
},
]
with pytest.raises(TypeError):
Expand Down
2 changes: 1 addition & 1 deletion tests/core/usage/plugins_usage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_success(parser):

parser.parse_args(['--baseline', f.name])
assert get_settings().plugins['HippoDetector'] == {
'path': f'file://{os.path.abspath("testing/plugins.py")}',
'path': 'file://{0}'.format(os.path.abspath('testing/plugins.py')),
}
assert plugins.initialize.from_plugin_classname('HippoDetector')

Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/aws_key_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def counter(*args, **kwargs):
self.example_key,
get_code_snippet(
[
f'false_secret = {"TEST" * 10}',
f'real_secret = {EXAMPLE_SECRET}',
'false_secret = {0}'.format('TEST' * 10),
'real_secret = {0}'.format(EXAMPLE_SECRET),
],
1,
),
Expand Down
14 changes: 9 additions & 5 deletions tests/transformers/yaml_transformer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ def test_multiline_block_scalar_folded_style(block_chomping):
# However, "folded" style may be used to keep a certain line limit with very long secrets,
# so we should probably handle that.
file = mock_file_object(
textwrap.dedent(f"""
textwrap.dedent(
f"""
multiline: |{block_chomping} # example
this is
a basic multiline string
""")[1:-1],
""",
)[1:-1],
)

assert YAMLTransformer().parse_file(file) == [
Expand Down Expand Up @@ -195,12 +197,14 @@ def test_basic():
def test_multi_line(block_scalar_style, block_chomping):
# NOTE: Referenced https://yaml-multiline.info/ for the many ways to do multi line strings
file = mock_file_object(
textwrap.dedent(f"""
textwrap.dedent(
f"""
key: {block_scalar_style}{block_chomping} # comment
multi
#line
# line
string
""")[1:-1],
""",
)[1:-1],
)

assert [item.line for item in YAMLFileParser(file)] == [
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
project = detect_secrets
# These should match the ci python env list
envlist = py{38,39,310,311},mypy
envlist = py{38,39,310,311,312},mypy
skip_missing_interpreters = true

[testenv]
Expand Down
Loading