Skip to content

Commit

Permalink
Add pylint to CI (ansible#575)
Browse files Browse the repository at this point in the history
* Add pylint to CI

Adding `pylint` to the CI linting tests.

The plan is to slowly enable individual checks until we get the number of errors down a bit. Disabled all checks for now except for `W0102 - dangerous-default-value`.

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde authored Jul 11, 2023
1 parent f10d2a9 commit 4ba7408
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@ requires = ["setuptools>=45, <=67.7.2", "setuptools-scm[toml]>=6.2, <=7.1.0"] #
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]

[tool.pylint.main]
output-format = "colorized"
max-line-length=120
disable = [
"all",

# Some codes we will leave disabled
"C0103", # invalid-name
"C0114", # missing-module-docstring
"C0116", # missing-function-docstring
"R0902", # too-many-instance-attributes
]

enable = [
"W0102", # dangerous-default-value
]
13 changes: 7 additions & 6 deletions src/ansible_builder/_target_scripts/introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def simple_combine(reqs):
return fancy_lines


def parse_args(args=sys.argv[1:]):
def parse_args(args=None):

parser = argparse.ArgumentParser(
prog='introspect',
Expand All @@ -217,14 +217,15 @@ def parse_args(args=sys.argv[1:]):
)
)

subparsers = parser.add_subparsers(help='The command to invoke.', dest='action')
subparsers.required = True
subparsers = parser.add_subparsers(
help='The command to invoke.',
dest='action',
required=True,
)

create_introspect_parser(subparsers)

args = parser.parse_args(args)

return args
return parser.parse_args(args)


def run_introspect(args, logger):
Expand Down
13 changes: 7 additions & 6 deletions src/ansible_builder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def add_container_options(parser):
'Integer values are also accepted (for example, "-v3" or "--verbosity 3"). Default is %(default)s.')


def parse_args(args=sys.argv[1:]):
def parse_args(args=None):

parser = argparse.ArgumentParser(
prog='ansible-builder',
Expand All @@ -208,14 +208,15 @@ def parse_args(args=sys.argv[1:]):
help='Print ansible-builder version and exit.'
)

subparsers = parser.add_subparsers(help='The command to invoke.', dest='action')
subparsers.required = True
subparsers = parser.add_subparsers(
help='The command to invoke.',
dest='action',
required=True,
)

add_container_options(subparsers)

args = parser.parse_args(args)

return args
return parser.parse_args(args)


class BuildArgAction(argparse.Action):
Expand Down
1 change: 1 addition & 0 deletions test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ types-jsonschema
types-pyyaml
tox
yamllint
pylint==2.17.4
34 changes: 34 additions & 0 deletions test/unit/test_introspect.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import pytest

from ansible_builder._target_scripts.introspect import process, process_collection, simple_combine, sanitize_requirements
from ansible_builder._target_scripts.introspect import parse_args


def test_multiple_collection_metadata(data_dir):
Expand Down Expand Up @@ -32,3 +34,35 @@ def test_single_collection_metadata(data_dir):

assert py_reqs == ['pyvcloud>=14']
assert sys_reqs == []


def test_parse_args_empty(capsys):
with pytest.raises(SystemExit):
parse_args()
dummy, err = capsys.readouterr()
assert 'usage: introspect' in err


def test_parse_args_default_action():
action = 'introspect'
user_pip = '/tmp/user-pip.txt'
user_bindep = '/tmp/user-bindep.txt'
write_pip = '/tmp/write-pip.txt'
write_bindep = '/tmp/write-bindep.txt'

parser = parse_args(
[
action, '--sanitize',
f'--user-pip={user_pip}',
f'--user-bindep={user_bindep}',
f'--write-pip={write_pip}',
f'--write-bindep={write_bindep}',
]
)

assert parser.action == action
assert parser.sanitize
assert parser.user_pip == user_pip
assert parser.user_bindep == user_bindep
assert parser.write_pip == write_pip
assert parser.write_bindep == write_bindep
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ commands =
yamllint --version
yamllint -s .
mypy src/ansible_builder
pylint src/ansible_builder

[testenv:unit{,-py39,-py310,-py311}]
description = Run unit tests
Expand Down

0 comments on commit 4ba7408

Please sign in to comment.