Skip to content

Commit

Permalink
Add pylint to ci
Browse files Browse the repository at this point in the history
Currently every current pylint issue is exempted.

Excemptions (disables) in .pylintrc are to be removed one-by-one in
upcoming PRs.

Solve selected pylint issues
  • Loading branch information
berland committed Jan 11, 2023
1 parent d1beced commit c3a4e71
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 52 deletions.
8 changes: 4 additions & 4 deletions komodo/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def cmake(
builddir,
makeopts,
jobs,
cmake="cmake",
*args,
cmake="cmake",
**kwargs,
):
bdir = f"{pkg}-{ver}-build"
Expand Down Expand Up @@ -150,7 +150,7 @@ def download(pkg, ver, pkgpath, data, prefix, *args, **kwargs):
if not url.startswith("https"):
raise ValueError(f"{url} does not use https:// protocol")

hash_type, hash = kwargs["hash"].split(":")
hash_type, hash_value = kwargs["hash"].split(":")
if hash_type != "sha256":
raise NotImplementedError(
f"Hash type {hash_type} given - only sha256 implemented"
Expand All @@ -175,7 +175,7 @@ def download(pkg, ver, pkgpath, data, prefix, *args, **kwargs):
file_handle.write(chunk)
sha256.update(chunk)

if sha256.hexdigest() != hash:
if sha256.hexdigest() != hash_value:
raise ValueError(
f"Hash of downloaded file ({sha256.hexdigest()}) "
"not equal to expected hash."
Expand All @@ -188,7 +188,7 @@ def download(pkg, ver, pkgpath, data, prefix, *args, **kwargs):
)


def pip_install(pkg, ver, pkgpath, data, prefix, dlprefix, pip="pip", *args, **kwargs):
def pip_install(pkg, ver, pkgpath, data, prefix, dlprefix, *args, pip="pip", **kwargs):
ver = strip_version(ver)
if ver == LATEST_PACKAGE_ALIAS:
ver = latest_pypi_version(pkg)
Expand Down
3 changes: 1 addition & 2 deletions komodo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import yaml as yml

import komodo.local as local
import komodo.switch as switch
from komodo import local, switch
from komodo.build import make
from komodo.data import Data
from komodo.fetch import fetch
Expand Down
6 changes: 3 additions & 3 deletions komodo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def grab(path, filename=None, version=None, protocol=None, pip="pip"):
raise NotImplementedError(f"Unknown protocol {protocol}")


def fetch(pkgs, repo, outdir, pip="pip"):
def fetch(pkgs, repo, outdir, pip="pip") -> dict:
missingpkg = [pkg for pkg in pkgs if pkg not in repo]
missingver = [
pkg for pkg, ver in pkgs.items() if pkg in repo and ver not in repo[pkg]
Expand All @@ -64,14 +64,14 @@ def fetch(pkgs, repo, outdir, pip="pip"):
)

if missingpkg or missingver:
return
return {}

if not outdir:
raise ValueError(
"The value of `outdir`, the cache location for pip and other "
"tools, cannot be None or the empty string."
)
elif not os.path.exists(outdir):
if not os.path.exists(outdir):
os.mkdir(outdir)

pypi_packages = []
Expand Down
12 changes: 5 additions & 7 deletions komodo/insert_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ def load_yaml_from_repo(filename, repo, ref):
def main():
args = parse_args()
repo = _get_repo(os.getenv("GITHUB_TOKEN"), args.git_fork, args.git_repo)
status = insert_proposals(
insert_proposals(
repo, args.base, args.target, args.git_ref, args.jobname, args.joburl
)
if status is not None:
raise status


def insert_proposals(repo, base, target, git_ref, jobname, joburl):
def insert_proposals(repo, base, target, git_ref, jobname, joburl) -> None:
year = target.split(".")[0]
month = target.split(".")[1]
tmp_target = target + ".tmp"
Expand All @@ -87,21 +85,21 @@ def insert_proposals(repo, base, target, git_ref, jobname, joburl):
except github.GithubException:
pass
else:
return ValueError(f"Branch {target} exists already")
raise ValueError(f"Branch {target} exists already")

try:
repo.get_branch(tmp_target)
except github.GithubException:
pass
else:
return ValueError(f"Branch {tmp_target} exists already")
raise ValueError(f"Branch {tmp_target} exists already")

# create contents of new release
proposal_yaml = load_yaml_from_repo("upgrade_proposals.yml", repo, git_ref)
upgrade_key = f"{year}-{month}"
upgrade = proposal_yaml.get(upgrade_key)
if upgrade_key not in proposal_yaml:
return ValueError(
raise ValueError(
f"No section for this release ({upgrade_key}) in upgrade_proposals.yml"
)
base_file = f"releases/matrices/{base}.yml"
Expand Down
3 changes: 2 additions & 1 deletion komodo/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def lint_version_numbers(pkgs, repo):
# A warning coincides with finding "Legacy" in repr(v)
if "Legacy" in repr(v): # don't know if possible to check otherwise
__reg_version_err(errs, pkg, ver, maintainer)
except: # noqa
except: # pylint: disable=bare-except # noqa
# Log any exception:
__reg_version_err(errs, pkg, ver, maintainer)
return errs

Expand Down
2 changes: 1 addition & 1 deletion komodo/prettier.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def prettified_yaml(filepath, check_only=True):


def write_to_string(repository, check_type=True):
if type(repository) == dict:
if isinstance(repository, dict):
repository = ordereddict(sorted(repository.items(), key=lambda t: t[0]))
repository = ruamel.yaml.comments.CommentedMap(repository)
return prettier(repository, check_type)
Expand Down
12 changes: 6 additions & 6 deletions komodo/release_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def build_matrix_file(release_base, release_folder, builtins):
)
compiled = {}

for p in all_packages:
if p in builtins:
compiled[p] = builtins[p]
for package in all_packages:
if package in builtins:
compiled[package] = builtins[package]
continue

if len(set([files[key].get(p) for key in files])) == 1:
compiled[p] = next(iter(files.values()))[p]
if len({files[key].get(package) for key in files}) == 1:
compiled[package] = next(iter(files.values()))[package]
else:
compiled[p] = {key: files[key].get(p) for key in py_keys}
compiled[package] = {key: files[key].get(package) for key in py_keys}

write_to_file(compiled, f"{release_base}.yml", False)

Expand Down
6 changes: 3 additions & 3 deletions komodo/reverse_dep_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ def _dump_dot(reverse, pkg, version, out):
def _dump_dot_dep(reverse, pkg, version, out, seen):
if pkg in seen:
return
id = pkg.lower().replace("-", "_")
out.write(f' {id} [label="{pkg}-{version}"];\n')
_id = pkg.lower().replace("-", "_")
out.write(f' {_id} [label="{pkg}-{version}"];\n')
if pkg in reverse:
seen.add(pkg)
for rev_dep, rev_version in reverse[pkg]:
rev_id = rev_dep.lower().replace("-", "_")
out.write(f" {id} -> {rev_id};\n")
out.write(f" {_id} -> {rev_id};\n")
_dump_dot_dep(reverse, rev_dep, rev_version, out, seen)


Expand Down
12 changes: 4 additions & 8 deletions komodo/snyk_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
import sys
from typing import Any, Dict, List

if sys.version_info >= (3, 7):
from snyk import SnykClient
from snyk.managers import OrganizationManager
from snyk.models import Vulnerability
else:
OrganizationManager = Any
Vulnerability = Any
from snyk import SnykClient
from snyk.managers import OrganizationManager
from snyk.models import Vulnerability

from komodo.yaml_file_type import ReleaseDir, ReleaseFile, YamlFile

Expand Down Expand Up @@ -89,7 +85,7 @@ def find_vulnerabilities(
repository: Dict[str, Any],
org: OrganizationManager,
) -> Dict[str, List[Vulnerability]]:
result = dict()
result = {}

for release_name, packages in releases.items():
pip_packages = filter_pip_packages(packages=packages, repository=repository)
Expand Down
11 changes: 0 additions & 11 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,35 @@ max-line-length = 88

[pylint.message]
disable = bad-inline-option,
bare-except,
broad-except,
consider-using-dict-items,
consider-using-f-string,
consider-using-from-import,
consider-using-set-comprehension,
consider-using-sys-exit,
consider-using-with,
deprecated-pragma,
duplicate-code,
expression-not-assigned,
file-ignored,
fixme,
inconsistent-return-statements,
invalid-name,
keyword-arg-before-vararg,
line-too-long,
literal-comparison,
locally-disabled,
logging-not-lazy,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
missing-timeout,
no-else-raise,
no-else-return,
protected-access,
raise-missing-from,
raw-checker-failed,
redefined-builtin,
redefined-outer-name,
suppressed-message,
too-few-public-methods,
too-many-arguments,
too-many-branches,
too-many-locals,
too-many-statements,
unidiomatic-typecheck,
unnecessary-comprehension,
unnecessary-lambda,
unnecessary-pass,
Expand All @@ -49,9 +40,7 @@ disable = bad-inline-option,
unused-import,
unused-variable,
use-a-generator,
use-dict-literal,
use-implicit-booleaness-not-comparison,
use-symbolic-message-instead,
used-before-assignment,
useless-object-inheritance,
wrong-import-position,
7 changes: 5 additions & 2 deletions tests/test_insert_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ def create_pull(self, title, body, head, base):
)
def test_insert_proposals(base, target, repo_files, changed_files, prs, return_type):
repo = MockRepo(files=repo_files)
status = insert_proposals(repo, base, target, "git_ref", "jobname", "joburl")

assert isinstance(status, return_type)
if isinstance(return_type(), Exception):
with pytest.raises(return_type):
insert_proposals(repo, base, target, "git_ref", "jobname", "joburl")
else:
insert_proposals(repo, base, target, "git_ref", "jobname", "joburl")

assert len(changed_files) == len(repo.updated_files)
for file, content in changed_files.items():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_link_io_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_read_folder_structure(tmpdir):

output_dict = read_link_structure(os.getcwd())

assert type(output_dict) == dict
assert isinstance(output_dict, dict)
assert equal_links(output_dict, expected_result)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_lint_package_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_malformed_visibility():
malformed_visibility = {
"package_a": {"visibility": "privat3"},
"package_b": {"visibility": "publ1c"},
"package_c": dict(),
"package_c": {},
}
with pytest.raises(SystemExit) as exit_info:
lint_package_status.run(malformed_visibility, REPO)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_post_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ def test_get_messages():
scripts, messages, inline = get_messages_and_scripts(release, motd_db)
assert "script1" in scripts
assert "message1" not in messages
assert inline is not []
assert inline != []

release = "2020.01.01-py36-rhel6"
scripts, messages, inline = get_messages_and_scripts(release, motd_db)
assert "script1" not in scripts
assert "message1" in messages
assert inline is not []
assert inline != []


def test_main_success(tmpdir):
Expand Down

0 comments on commit c3a4e71

Please sign in to comment.