Fixes pylint warnings like this one:
doc/conf.py:325:0: W1401: Anomalous backslash in string: '\s'.
String constant might be missing an r prefix.
(anomalous-backslash-in-string)
The reason for this warning is that backslash escapes are interpreted in
non-raw (non-r-prefixed) strings. For example, '\a' and r'\a' are not
the same string (first one has a single ASCII bell character, second one
has two characters).
It just happens that there's no \s (or \., or \/) escape for example,
and '\s' turns into two characters (as needed for a regex). It's risky
to rely on stuff like that regexes though. Best to make them raw strings
unless they're super trivial.
Also note that '\s' and '\\s' turn into the same string.
Another tip: A literal ' can be put into a string with "blah'blah"
instead of 'blah\'blah'.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
74 lines
1.8 KiB
Python
Executable File
74 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# A script to generate a list of boards that have changed or added and create an
|
|
# arguemnts file for sanitycheck to allow running more tests for those boards.
|
|
|
|
import re, os
|
|
import sh
|
|
import logging
|
|
import argparse
|
|
|
|
if "ZEPHYR_BASE" not in os.environ:
|
|
logging.error("$ZEPHYR_BASE environment variable undefined.\n")
|
|
exit(1)
|
|
|
|
logger = None
|
|
|
|
repository_path = os.environ['ZEPHYR_BASE']
|
|
sh_special_args = {
|
|
'_tty_out': False,
|
|
'_cwd': repository_path
|
|
}
|
|
|
|
def init_logs():
|
|
log_lev = os.environ.get('LOG_LEVEL', None)
|
|
level = logging.INFO
|
|
global logger
|
|
|
|
if log_lev == "DEBUG":
|
|
level = logging.DEBUG
|
|
elif log_lev == "ERROR":
|
|
level = logging.ERROR
|
|
|
|
console = logging.StreamHandler()
|
|
format = logging.Formatter('%(levelname)-8s: %(message)s')
|
|
console.setFormatter(format)
|
|
logger = logging.getLogger('')
|
|
logger.addHandler(console)
|
|
logger.setLevel(level)
|
|
|
|
logging.debug("Log init completed")
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(
|
|
description="Generate a sanitycheck argument for for boards "
|
|
" that have changed")
|
|
parser.add_argument('-c', '--commits', default=None,
|
|
help="Commit range in the form: a..b")
|
|
return parser.parse_args()
|
|
|
|
def main():
|
|
boards = set()
|
|
|
|
args = parse_args()
|
|
if not args.commits:
|
|
exit(1)
|
|
|
|
commit = sh.git("diff","--name-only", args.commits, **sh_special_args)
|
|
files = commit.split("\n")
|
|
|
|
for f in files:
|
|
if f.endswith(".rst") or f.endswith(".png") or f.endswith(".jpg"):
|
|
continue
|
|
p = re.match(r"^boards\/[^/]+\/([^/]+)\/", f)
|
|
if p and p.groups():
|
|
boards.add(p.group(1))
|
|
|
|
if boards:
|
|
print("-p\n%s" %("\n-p\n".join(boards)))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|