Create pylint.yml (#1039)

* Create pylint.yml

* improve file matching

* fix some pylint issues

* run on PR and push (force on master only)

* more pylint fixes

* suppress noisy exit code and filter to fatals

* add conan as a dep so the module is importable

* fix lint error on unreachable branch
This commit is contained in:
Dominic Hamon 2020-09-09 09:43:26 +01:00 committed by GitHub
parent 4751550871
commit beb360d03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 116 additions and 88 deletions

26
.github/workflows/pylint.yml vendored Normal file
View File

@ -0,0 +1,26 @@
name: pylint
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint pylint-exit conan
- name: Run pylint
run: |
pylint `find . -name '*.py'|xargs` || pylint-exit $?

View File

@ -41,7 +41,7 @@ def skipped(state):
state.skip_with_error('some error')
return # NOTE: You must explicitly return, or benchmark will continue.
... # Benchmark code would be here.
# Benchmark code would be here.
if __name__ == '__main__':

View File

@ -9,7 +9,7 @@ import setuptools
from setuptools.command import build_ext
here = os.path.dirname(os.path.abspath(__file__))
HERE = os.path.dirname(os.path.abspath(__file__))
IS_WINDOWS = sys.platform.startswith('win')
@ -17,22 +17,23 @@ IS_WINDOWS = sys.platform.startswith('win')
def _get_version():
"""Parse the version string from __init__.py."""
with open(os.path.join(here, 'bindings', 'python', 'google_benchmark', '__init__.py')) as f:
with open(os.path.join(
HERE, 'bindings', 'python', 'google_benchmark', '__init__.py')) as init_file:
try:
version_line = next(
line for line in f if line.startswith('__version__'))
line for line in init_file if line.startswith('__version__'))
except StopIteration:
raise ValueError('__version__ not defined in __init__.py')
else:
ns = {}
exec(version_line, ns) # pylint: disable=exec-used
return ns['__version__']
namespace = {}
exec(version_line, namespace) # pylint: disable=exec-used
return namespace['__version__']
def _parse_requirements(path):
with open(os.path.join(here, path)) as f:
with open(os.path.join(HERE, path)) as requirements:
return [
line.rstrip() for line in f
line.rstrip() for line in requirements
if not (line.isspace() or line.startswith('#'))
]
@ -56,11 +57,12 @@ class BuildBazelExtension(build_ext.build_ext):
build_ext.build_ext.run(self)
def bazel_build(self, ext):
with open('WORKSPACE', 'r') as f:
workspace_contents = f.read()
"""Runs the bazel build to create the package."""
with open('WORKSPACE', 'r') as workspace:
workspace_contents = workspace.read()
with open('WORKSPACE', 'w') as f:
f.write(re.sub(
with open('WORKSPACE', 'w') as workspace:
workspace.write(re.sub(
r'(?<=path = ").*(?=", # May be overwritten by setup\.py\.)',
sysconfig.get_python_inc().replace(os.path.sep, posixpath.sep),
workspace_contents))
@ -106,7 +108,8 @@ setuptools.setup(
packages=setuptools.find_packages('bindings/python'),
install_requires=_parse_requirements('bindings/python/requirements.txt'),
cmdclass=dict(build_ext=BuildBazelExtension),
ext_modules=[BazelExtension('google_benchmark._benchmark', '//bindings/python/google_benchmark:_benchmark')],
ext_modules=[BazelExtension(
'google_benchmark._benchmark', '//bindings/python/google_benchmark:_benchmark')],
zip_safe=False,
# PyPI package information.
classifiers=[

View File

@ -158,7 +158,6 @@ def run_or_load_benchmark(filename, benchmark_flags):
ftype = check_input_file(filename)
if ftype == IT_JSON:
return load_benchmark_results(filename)
elif ftype == IT_Executable:
if ftype == IT_Executable:
return run_benchmark(filename, benchmark_flags)
else:
assert False # This branch is unreachable
raise ValueError('Unknown file type %s' % ftype)