Skip to content

Commit 96bae01

Browse files
author
Jerjou Cheng
committed
Lint session should check all changed files.
1 parent 7193d1e commit 96bae01

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

nox.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ def list_files(folder, pattern):
6161
yield os.path.join(root, filename)
6262

6363

64-
def collect_sample_dirs(start_dir, blacklist=set()):
64+
def collect_sample_dirs(start_dir, blacklist=set(), suffix='_test.py'):
6565
"""Recursively collects a list of dirs that contain tests.
6666
6767
This works by listing the contents of directories and finding
6868
directories that have `*_test.py` files.
6969
"""
7070
# Collect all the directories that have tests in them.
7171
for parent, subdirs, files in os.walk(start_dir):
72-
if any(f for f in files if f[-8:] == '_test.py'):
72+
if any(f for f in files if f.endswith(suffix) and f not in blacklist):
7373
# Don't recurse further, since py.test will do that.
7474
del subdirs[:]
7575
# This dir has tests in it. yield it.
@@ -240,9 +240,14 @@ def session_lint(session):
240240
"""Lints each sample."""
241241
sample_directories = session.posargs
242242
if not sample_directories:
243-
sample_directories = collect_sample_dirs('.')
244-
245-
# On travis, on lint changed samples.
243+
# The top-level dir isn't a sample dir - only its subdirs.
244+
_, subdirs, _ = next(os.walk('.'))
245+
sample_directories = (
246+
sample_dir for subdir in subdirs if not subdir.startswith('.')
247+
for sample_dir in collect_sample_dirs(
248+
subdir, suffix='.py', blacklist='conftest.py'))
249+
250+
# On travis, only lint changed samples.
246251
if ON_TRAVIS:
247252
changed_files = get_changed_files()
248253
sample_directories = filter_samples(

0 commit comments

Comments
 (0)