Skip to content

Commit

Permalink
Check Python scripts with pylint.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Oct 6, 2022
1 parent b26fe31 commit 2a62dac
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
11 changes: 10 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ repos:
hooks:
- id: shellcheck

- repo: https://github.com/PyCQA/pylint.git
rev: v2.15.3
hooks:
- id: pylint
additional_dependencies:
- 'zkg'

- repo: local
hooks:
- id: stray_baselines
Expand All @@ -34,7 +41,9 @@ repos:
pass_filenames: false
- id: vermin
name: Check minimal required Python version
# Minimal required Python version according to https://docs.zeek.org/en/master/install.html#required-dependencies.
# Minimal required Python version according to
# https://docs.zeek.org/en/master/install.html#required-dependencies.
# The value be kept consistent with `py-version` in `.pylintrc`.
entry: vermin -vv --target=3.5- .
language: python
pass_filenames: false
Expand Down
32 changes: 32 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[MAIN]

# Naming style matching correct module names.
#
# NOTE: This package has the existing invalid name `package-template` while
# PEP8 suggest snake_case.
module-naming-style=any

# Minimum Python version to use for version dependent checks. Will default to
# the version used to run pylint.
#
# NOTE: Minimal required Python version according to
# https://docs.zeek.org/en/master/install.html#required-dependencies. This
# value should be kept consistent with vermin's target version in
# `.pre-commit-config.yaml`.
py-version=3.5

[FORMAT]
# Maximum number of characters on a single line.
max-line-length=120

[MESSAGES CONTROL]
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once). You can also use "--disable=all" to
# disable everything first and then re-enable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=missing-docstring
35 changes: 19 additions & 16 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

import git

import zeekpkg.template # pylint: disable=import-error
import zeekpkg.uservar # pylint: disable=import-error

# pylint: disable=missing-docstring,no-self-use
import zeekpkg.template
import zeekpkg.uservar

TEMPLATE_API_VERSION = "1.0.0"

Expand Down Expand Up @@ -158,25 +156,30 @@ def instantiate(self, tmpl):
super().instantiate(tmpl)

def pkg_file(*name):
p = os.path.join(self._packagedir, *name)
assert os.path.exists(p)
return p
path = os.path.join(self._packagedir, *name)
assert os.path.exists(path)
return path

# Manually merge Spicy analyzer-specific changes to `zkg.meta`.
with open(pkg_file("zkg.meta"), "ab") as f:
with open(pkg_file("zkg.meta"), "ab") as zkg_meta:
# Add a build command.
#
# NOTE: For backwards compatibility with <zkg-2.8.0 which did not
# inject binary paths of installed packages into `PATH`, we allow
# as a fallback a `spicyz` path inferred from `zkg`'s directory
# structure.
f.write(
b"build_command = mkdir -p build && cd build && SPICYZ=$(command -v spicyz || echo %(package_base)s/spicy-plugin/build/bin/spicyz) cmake .. && cmake --build .\n"
zkg_meta.write(
(
b"build_command = mkdir -p build && "
b"cd build && "
b"SPICYZ=$(command -v spicyz || echo %(package_base)s/spicy-plugin/build/bin/spicyz) cmake .. && "
b"cmake --build .\n"
)
)

# Manually merge Spicy analyzer-specific changes to `testing/btest.cfg`.
with open(pkg_file("testing", "btest.cfg"), "ab") as f:
f.write(
with open(pkg_file("testing", "btest.cfg"), "ab") as btest_cfg:
btest_cfg.write(
bytes(
textwrap.dedent(
"""\
Expand All @@ -196,8 +199,8 @@ def pkg_file(*name):
)

# Manually merge Spicy analyzer-specific changes to `scripts/__load__.zeek`.
with open(pkg_file("scripts", "__load__.zeek"), "ab") as f:
f.write(b"@load-sigs ./dpd.sig\n")
with open(pkg_file("scripts", "__load__.zeek"), "ab") as load:
load.write(b"@load-sigs ./dpd.sig\n")


class Template(zeekpkg.template.Template):
Expand Down Expand Up @@ -229,8 +232,8 @@ def define_user_vars(self):
),
]

def apply_user_vars(self, uvars):
for uvar in uvars:
def apply_user_vars(self, user_vars):
for uvar in user_vars:
if uvar.name() == "name":
self.define_param("name", uvar.val())
self.define_param("slug", zeekpkg.uservar.slugify(uvar.val()))
Expand Down

0 comments on commit 2a62dac

Please sign in to comment.