Skip to content

STYLE/CI: implement incremental linting for asv benchmarks #18647

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

Merged
merged 3 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 15 additions & 7 deletions asv_bench/vbench_to_asv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def vbench_to_asv_source(bench, kinds=None):
output += tab + 'goal_time = 0.2\n\n'

if bench.setup:
indented_setup = [tab * 2 + '{}\n'.format(x) for x in bench.setup.splitlines()]
indented_setup = [tab * 2 + '{}\n'.format(x)
Copy link
Member

@gfyoung gfyoung Dec 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight preference for keyword arguments for clarity vs. bare {}.

@jreback @jorisvandenbossche : were we just trying to transition to using .format OR .format with keyword?

for x in bench.setup.splitlines()]
output += tab + 'def setup(self):\n' + ''.join(indented_setup) + '\n'

for kind in kinds:
Expand Down Expand Up @@ -77,7 +78,9 @@ def visit_TryExcept(self, node):

def visit_Assign(self, node):
for target in node.targets:
if isinstance(target, ast.Name) and not isinstance(target.ctx, ast.Param) and not self.in_class_define:
if (isinstance(target, ast.Name) and
not isinstance(target.ctx, ast.Param) and
not self.in_class_define):
self.transforms[target.id] = 'self.' + target.id
self.generic_visit(node)

Expand All @@ -87,7 +90,9 @@ def visit_Name(self, node):
new_node = node
if node.id in self.transforms:
if not isinstance(node.ctx, ast.Param):
new_node = ast.Attribute(value=ast.Name(id='self', ctx=node.ctx), attr=node.id, ctx=node.ctx)
new_node = ast.Attribute(value=ast.Name(id='self',
ctx=node.ctx),
attr=node.id, ctx=node.ctx)

self.generic_visit(node)

Expand All @@ -111,7 +116,6 @@ def visit_FunctionDef(self, node):

def translate_module(target_module):
g_vars = {}
l_vars = {}
exec('import ' + target_module) in g_vars

print(target_module)
Expand All @@ -138,9 +142,11 @@ def translate_module(target_module):
transformer = AssignToSelf()
transformed_module = transformer.visit(ast_module)

unique_imports = {astor.to_source(node): node for node in transformer.imports}
unique_imports = {astor.to_source(node): node
for node in transformer.imports}

transformed_module.body = unique_imports.values() + transformed_module.body
transformed_module.body = (unique_imports.values() +
transformed_module.body)

transformed_source = astor.to_source(transformed_module)

Expand All @@ -155,7 +161,9 @@ def translate_module(target_module):

for module in glob.glob(os.path.join(new_dir, '*.py')):
mod = os.path.basename(module)
if mod in ['make.py', 'measure_memory_consumption.py', 'perf_HEAD.py', 'run_suite.py', 'test_perf.py', 'generate_rst_files.py', 'test.py', 'suite.py']:
if mod in ['make.py', 'measure_memory_consumption.py', 'perf_HEAD.py',
'run_suite.py', 'test_perf.py', 'generate_rst_files.py',
'test.py', 'suite.py']:
continue
print('')
print(mod)
Expand Down
7 changes: 7 additions & 0 deletions ci/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ if [ "$LINT" ]; then
fi
echo "Linting setup.py DONE"

echo "Linting asv_bench/"
flake8 asv_bench/ --exclude=asv_bench/benchmarks/[ghijoprst]*.py --ignore=F811
if [ $? -ne "0" ]; then
RET=1
fi
echo "Linting asv_bench/*.py DONE"

echo "Linting *.pyx"
flake8 pandas --filename=*.pyx --select=E501,E302,E203,E111,E114,E221,E303,E128,E231,E126,E265,E305,E301,E127,E261,E271,E129,W291,E222,E241,E123,F403
if [ $? -ne "0" ]; then
Expand Down