pw_presubmit: Fix PATH; run Python tests
- Update the PATH to include the new CIPD directories.
- With the current Python test finding approach, Python tests must be
run from the package directory. Update the presubmit check to do this.
Change-Id: Ie1cdf61875643d435608597b27d03695bf46d3c3
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index 0271ea2..f3bbc44 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -16,6 +16,7 @@
"""Runs the local presubmit checks for the Pigweed repository."""
import argparse
+import glob
import logging
import os
import re
@@ -57,11 +58,15 @@
def init_cipd():
cipd = os.path.abspath('.presubmit/cipd')
call(sys.executable, 'env_setup/cipd/update.py', '--install-dir', cipd)
- os.environ['PATH'] = os.pathsep.join((
- cipd,
- os.path.join(cipd, 'bin'),
- os.environ['PATH'],
- ))
+
+ paths = [cipd, os.path.join(cipd, 'bin')]
+ for base in glob.glob(os.path.join(cipd, '*')):
+ paths.append(base)
+ paths.append(os.path.join(base, 'bin'))
+
+ paths.append(os.environ['PATH'])
+
+ os.environ['PATH'] = os.pathsep.join(paths)
_LOG.debug('PATH %s', os.environ['PATH'])
@@ -170,7 +175,7 @@
return
for package in packages:
- call('python', os.path.join(package, 'setup.py'), 'test')
+ call('python', os.path.join(package, 'setup.py'), 'test', cwd=package)
@filter_paths(endswith='.py')
@@ -312,8 +317,9 @@
if missing_bazel or missing_gn:
for build, files in [('Bazel', missing_bazel), ('GN', missing_gn)]:
- _LOG.warning('%s are missing from the %s build:\n%s',
- plural(files, 'file'), build, '\n'.join(files))
+ if files:
+ _LOG.warning('%s are missing from the %s build:\n%s',
+ plural(files, 'file'), build, '\n'.join(files))
_LOG.warning(
'All source files must appear in BUILD and BUILD.gn files')
diff --git a/pw_presubmit/py/pw_presubmit/tools.py b/pw_presubmit/py/pw_presubmit/tools.py
index d3ab723..0f93550 100644
--- a/pw_presubmit/py/pw_presubmit/tools.py
+++ b/pw_presubmit/py/pw_presubmit/tools.py
@@ -148,11 +148,9 @@
for i in indices)
bot_sections = '{9}'.join('{8:{8}^{width%d}}' % i for i in indices)
- # yapf: disable
return ''.join(['{0}', *top_sections, '{3}\n',
'{4}', *mid_sections, '{6}\n',
- '{7}', *bot_sections, '{10}'])
- # yapf: enable
+ '{7}', *bot_sections, '{10}']) # yapf: disable
_DOUBLE = '╔═╦╗║║║╚═╩╝'
@@ -166,7 +164,7 @@
def _title(msg, style=_DOUBLE):
- msg = f' {msg} '.center(WIDTH - 4)
+ msg = f' {msg} '.center(WIDTH - 2)
return _make_box('^').format(*style, section1=msg, width1=len(msg))