aboutsummaryrefslogtreecommitdiff
path: root/pw_module
diff options
context:
space:
mode:
authorWyatt Hepler <hepler@google.com>2020-03-04 16:19:36 -0800
committerWyatt Hepler <hepler@google.com>2020-03-04 16:26:32 -0800
commit52f7443f874b77afbfbe7de427d66b74d6b1266f (patch)
treec68235d0c421ca7c45a0c16aaee2ce740cd9a4ab /pw_module
parent95a980be8b6b0bfb46cb3e51bb644f8ed24f7359 (diff)
downloadpigweed-52f7443f874b77afbfbe7de427d66b74d6b1266f.tar.gz
pw_module: module-check with multiple modules
- Allow running pw module-check on multiple modules. If more than one module is being checked, print banners to visually separate the results. - Search for *test.cc to include files named test.cc. Change-Id: Ie448d9eb27fee20e196e16af0b82fd1c8a745c22
Diffstat (limited to 'pw_module')
-rw-r--r--pw_module/py/pw_module/check.py40
1 files changed, 29 insertions, 11 deletions
diff --git a/pw_module/py/pw_module/check.py b/pw_module/py/pw_module/check.py
index 322bde0c3..ab0391556 100644
--- a/pw_module/py/pw_module/check.py
+++ b/pw_module/py/pw_module/check.py
@@ -11,30 +11,48 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-# TODO(keir) add docstring
-# pylint: disable=missing-module-docstring
+"""Checks a Pigweed module's format and structure."""
import logging
import pathlib
import glob
from enum import Enum
-from typing import Callable
-from typing import NamedTuple
+from typing import Callable, NamedTuple
+
_LOG = logging.getLogger(__name__)
CheckerFunction = Callable[[str], None]
def register_arguments(parser):
- parser.add_argument('module', help='The module to check')
+ parser.add_argument('modules', nargs='+', help='The module to check')
+
+
+def main(modules):
+ if len(modules) > 1:
+ _LOG.info('Checking %d modules', len(modules))
+
+ passed = 0
+
+ for path in modules:
+ if len(modules) > 1:
+ print()
+ print(f' {path} '.center(80, '='))
+
+ passed += check_module(path)
+
+ if len(modules) > 1:
+ _LOG.info('%d of %d modules passed', passed, len(modules))
+
+ return 0 if passed == len(modules) else 1
-def main(module): # pylint: disable=missing-function-docstring
- # TODO(keir) add function docstring
+def check_module(module) -> bool:
+ """Runs module checks on one module; returns True if the module passes."""
if not pathlib.Path(module).is_dir():
_LOG.error('No directory found: %s', module)
- return 1
+ return False
found_any_warnings = False
found_any_errors = False
@@ -86,9 +104,9 @@ def main(module): # pylint: disable=missing-function-docstring
module)
if found_any_errors:
_LOG.error('FAIL: Found errors when checking module %s', module)
- return 1
+ return False
- return 0
+ return True
class Checker(NamedTuple):
@@ -132,7 +150,7 @@ def check_python_proper_module(directory):
@checker('PWCK002', 'If there are C++ files, there are C++ tests')
def check_have_cc_tests(directory):
module_cc_files = glob.glob(f'{directory}/**/*.cc', recursive=True)
- module_cc_test_files = glob.glob(f'{directory}/**/*_test.cc',
+ module_cc_test_files = glob.glob(f'{directory}/**/*test.cc',
recursive=True)
if module_cc_files and not module_cc_test_files:
yield Issue('C++ code present but no tests at all (you monster).')