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

feat: add --no-version-check cmdline option #139

Merged
merged 3 commits into from
Dec 4, 2023
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
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: python
dist: focal
git:
depth: false
services:
Expand All @@ -17,12 +18,10 @@ deploy:
repo: IBM/detect-secrets
matrix:
include:
- env: TOXENV=py37
python: 3.7.13
dist: xenial # Required for Python >= 3.7 (travis-ci/travis-ci#9069), the GitHub Travis build will use Python 3.7.1 by default if you provide 3.7 without a patch version and the build will fail with AttributeError: 'str' object has no attribute 'name'
- env: TOXENV=py38
python: 3.8
dist: xenial # Required for Python >= 3.7 (travis-ci/travis-ci#9069)
python: 3.8.18
- env: TOXENV=py39
python: 3.9.18
before_install:
- echo -e "machine github.com\n login $GH_ACCESS_TOKEN" >> ~/.netrc # Login to GitHub
- echo -e "machine github.ibm.com\n login $GHE_ACCESS_TOKEN" >> ~/.netrc # Login to GitHub Enterprise
Expand Down
2 changes: 1 addition & 1 deletion detect_secrets/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '0.13.1+ibm.61.dss'
VERSION = '0.13.1+ibm.62.dss'
16 changes: 15 additions & 1 deletion detect_secrets/core/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def add_no_verify_flag(parser):
)


def add_no_version_check_flag(parser):
parser.add_argument(
'--no-version-check',
action='store_true',
help='Disables detect-secrets up-to-date version check.',
)


def add_output_verified_false_flag(parser):
parser.add_argument(
'--output-verified-false',
Expand Down Expand Up @@ -75,7 +83,9 @@ def __init__(self):
self.add_default_arguments()

def add_default_arguments(self):
self._add_verbosity_argument()._add_version_argument()
self._add_no_version_check_flag()\
._add_verbosity_argument()\
._add_version_argument()

def add_pre_commit_arguments(self):
self._add_filenames_argument()\
Expand Down Expand Up @@ -160,6 +170,10 @@ def _add_no_verify_flag(self):
add_no_verify_flag(self.parser)
return self

def _add_no_version_check_flag(self):
add_no_version_check_flag(self.parser)
return self

def _add_output_verified_false_flag(self):
add_output_verified_false_flag(self.parser)
return self
Expand Down
6 changes: 3 additions & 3 deletions detect_secrets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ def parse_args(argv, parserBuilder):


def main(argv=None):

version_check()

if len(sys.argv) == 1: # pragma: no cover
sys.argv.append('-h')

Expand All @@ -30,6 +27,9 @@ def main(argv=None):
if args.verbose: # pragma: no cover
log.set_debug_level(3)

if not args.no_version_check:
version_check()

if args.action == 'scan':
automaton = None
word_list_hash = None
Expand Down
4 changes: 3 additions & 1 deletion detect_secrets/pre_commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ def parse_args(argv):


def main(argv=None):
version_check()
args = parse_args(argv)
if args.verbose: # pragma: no cover
log.set_debug_level(3)

if not args.no_version_check:
version_check()

try:
# If baseline is provided, we first want to make sure
# it's valid, before doing any further computation.
Expand Down
14 changes: 13 additions & 1 deletion detect_secrets/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@
from packaging.version import parse

from detect_secrets import VERSION
from detect_secrets.core.log import get_logger

log = get_logger(format_string='%(message)s')


def version_check():
# check if running latest version, if not print warning
# get latest version from GHE
yellow = '\033[93m'
end_yellow = '\033[0m'

current_version = parse(VERSION)
log.debug(
'detect-secrets: checking if up-to-date: version=%s',
current_version,
)
try:
resp = requests.get(
(
Expand All @@ -24,7 +33,10 @@ def version_check():
)
resp.raise_for_status()
latest_version = parse(resp.text)
current_version = parse(VERSION)
log.debug(
'detect-secrets: latest_version=%s up-to-date=%r',
latest_version, current_version >= latest_version,
)
if current_version < latest_version:
print(
yellow +
Expand Down
10 changes: 1 addition & 9 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
project = detect_secrets
# These should match the travis env list
envlist = py{36,37,38,39}
envlist = py{38,39}
skip_missing_interpreters = true
# disabling this option until latest venv-update version is compatible with pip v21
# tox_pip_extensions_ext_venv_update = true
Expand All @@ -18,14 +18,6 @@ commands =
coverage report --show-missing --include=detect_secrets/* --fail-under 97
pre-commit run --all-files --show-diff-on-failure

[testenv:py37]
commands =
coverage erase
coverage run -m pytest tests
coverage report --show-missing --include=tests/* --fail-under 100
coverage report --show-missing --include=detect_secrets/* --fail-under 97
# Skip pre-commit hook for py37 since flake8 requires Python >= 3.8.1.

[testenv:venv]
envdir = venv
commands =
Expand Down