diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/python/qmk/cli/doctor/main.py | 7 | ||||
-rw-r--r-- | lib/python/qmk/cli/format/c.py | 29 | ||||
-rwxr-xr-x | lib/python/qmk/cli/format/python.py | 3 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/compilation_database.py | 3 | ||||
-rw-r--r-- | lib/python/qmk/cli/generate/docs.py | 16 | ||||
-rw-r--r-- | lib/python/qmk/cli/pytest.py | 4 | ||||
-rw-r--r-- | lib/python/qmk/commands.py | 8 | ||||
-rw-r--r-- | lib/python/qmk/constants.py | 2 |
8 files changed, 47 insertions, 25 deletions
diff --git a/lib/python/qmk/cli/doctor/main.py b/lib/python/qmk/cli/doctor/main.py index ed20f46d3f..2e5e221e8f 100755 --- a/lib/python/qmk/cli/doctor/main.py +++ b/lib/python/qmk/cli/doctor/main.py @@ -11,7 +11,7 @@ from milc.questions import yesno from qmk import submodules from qmk.constants import QMK_FIRMWARE, QMK_FIRMWARE_UPSTREAM from .check import CheckStatus, check_binaries, check_binary_versions, check_submodules -from qmk.commands import git_check_repo, git_get_branch, git_is_dirty, git_get_remotes, git_check_deviation, in_virtualenv +from qmk.commands import git_check_repo, git_get_branch, git_get_tag, git_is_dirty, git_get_remotes, git_check_deviation, in_virtualenv def os_tests(): @@ -47,6 +47,11 @@ def git_tests(): git_branch = git_get_branch() if git_branch: cli.log.info('Git branch: %s', git_branch) + + repo_version = git_get_tag() + if repo_version: + cli.log.info('Repo version: %s', repo_version) + git_dirty = git_is_dirty() if git_dirty: cli.log.warning('{fg_yellow}Git has unstashed/uncommitted changes.') diff --git a/lib/python/qmk/cli/format/c.py b/lib/python/qmk/cli/format/c.py index 0160e6036f..8eb7fa1ed0 100644 --- a/lib/python/qmk/cli/format/c.py +++ b/lib/python/qmk/cli/format/c.py @@ -1,6 +1,5 @@ """Format C code according to QMK's style. """ -from os import path from shutil import which from subprocess import CalledProcessError, DEVNULL, Popen, PIPE @@ -15,6 +14,12 @@ core_dirs = ('drivers', 'quantum', 'tests', 'tmk_core', 'platforms') ignored = ('tmk_core/protocol/usb_hid', 'platforms/chibios/boards') +def is_relative_to(file, other): + """Provide similar behavior to PurePath.is_relative_to in Python > 3.9 + """ + return str(normpath(file).resolve()).startswith(str(normpath(other).resolve())) + + def find_clang_format(): """Returns the path to clang-format. """ @@ -68,18 +73,18 @@ def cformat_run(files): def filter_files(files, core_only=False): """Yield only files to be formatted and skip the rest """ - if core_only: - # Filter non-core files - for index, file in enumerate(files): + files = list(map(normpath, filter(None, files))) + + for file in files: + if core_only: # The following statement checks each file to see if the file path is # - in the core directories # - not in the ignored directories - if not any(i in str(file) for i in core_dirs) or any(i in str(file) for i in ignored): - files[index] = None + if not any(is_relative_to(file, i) for i in core_dirs) or any(is_relative_to(file, i) for i in ignored): cli.log.debug("Skipping non-core file %s, as '--core-only' is used.", file) + continue - for file in files: - if file and file.name.split('.')[-1] in c_file_suffixes: + if file.suffix[1:] in c_file_suffixes: yield file else: cli.log.debug('Skipping file %s', file) @@ -118,12 +123,8 @@ def format_c(cli): print(git_diff.stderr) return git_diff.returncode - files = [] - - for file in git_diff.stdout.strip().split('\n'): - if not any([file.startswith(ignore) for ignore in ignored]): - if path.exists(file) and file.split('.')[-1] in c_file_suffixes: - files.append(file) + changed_files = git_diff.stdout.strip().split('\n') + files = list(filter_files(changed_files, True)) # Sanity check if not files: diff --git a/lib/python/qmk/cli/format/python.py b/lib/python/qmk/cli/format/python.py index 47b5c45fd5..008622cac1 100755 --- a/lib/python/qmk/cli/format/python.py +++ b/lib/python/qmk/cli/format/python.py @@ -25,8 +25,9 @@ def yapf_run(files): def filter_files(files): """Yield only files to be formatted and skip the rest """ + files = list(map(normpath, filter(None, files))) for file in files: - if file and normpath(file).name.split('.')[-1] in py_file_suffixes: + if file.suffix[1:] in py_file_suffixes: yield file else: cli.log.debug('Skipping file %s', file) diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index 602635270c..7ac0f740fe 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -26,7 +26,8 @@ def system_libs(binary: str) -> List[Path]: # Actually query xxxxxx-gcc to find its include paths. if binary.endswith("gcc") or binary.endswith("g++"): - result = cli.run([binary, '-E', '-Wp,-v', '-'], capture_output=True, check=True, input='\n') + # (TODO): Remove 'stdin' once 'input' no longer causes issues under MSYS + result = cli.run([binary, '-E', '-Wp,-v', '-'], capture_output=True, check=True, stdin=None, input='\n') paths = [] for line in result.stderr.splitlines(): if line.startswith(" "): diff --git a/lib/python/qmk/cli/generate/docs.py b/lib/python/qmk/cli/generate/docs.py index 749336fea5..74112d834d 100644 --- a/lib/python/qmk/cli/generate/docs.py +++ b/lib/python/qmk/cli/generate/docs.py @@ -7,7 +7,9 @@ from subprocess import DEVNULL from milc import cli DOCS_PATH = Path('docs/') -BUILD_PATH = Path('.build/docs/') +BUILD_PATH = Path('.build/') +BUILD_DOCS_PATH = BUILD_PATH / 'docs' +DOXYGEN_PATH = BUILD_PATH / 'doxygen' @cli.subcommand('Build QMK documentation.', hidden=False if cli.config.user.developer else True) @@ -18,10 +20,12 @@ def generate_docs(cli): * [ ] Add a real build step... something static docs """ - if BUILD_PATH.exists(): - shutil.rmtree(BUILD_PATH) + if BUILD_DOCS_PATH.exists(): + shutil.rmtree(BUILD_DOCS_PATH) + if DOXYGEN_PATH.exists(): + shutil.rmtree(DOXYGEN_PATH) - shutil.copytree(DOCS_PATH, BUILD_PATH) + shutil.copytree(DOCS_PATH, BUILD_DOCS_PATH) # When not verbose we want to hide all output args = { @@ -34,6 +38,6 @@ def generate_docs(cli): # Generate internal docs cli.run(['doxygen', 'Doxyfile'], **args) - cli.run(['moxygen', '-q', '-a', '-g', '-o', BUILD_PATH / 'internals_%s.md', 'doxygen/xml'], **args) + cli.run(['moxygen', '-q', '-g', '-o', BUILD_DOCS_PATH / 'internals_%s.md', DOXYGEN_PATH / 'xml'], **args) - cli.log.info('Successfully generated internal docs to %s.', BUILD_PATH) + cli.log.info('Successfully generated internal docs to %s.', BUILD_DOCS_PATH) diff --git a/lib/python/qmk/cli/pytest.py b/lib/python/qmk/cli/pytest.py index a7f01a872a..b7b17f0e9d 100644 --- a/lib/python/qmk/cli/pytest.py +++ b/lib/python/qmk/cli/pytest.py @@ -7,11 +7,13 @@ from subprocess import DEVNULL from milc import cli +@cli.argument('-t', '--test', arg_only=True, action='append', default=[], help="Mapped to nose2 'testNames' positional argument - https://docs.nose2.io/en/latest/usage.html#specifying-tests-to-run") @cli.subcommand('QMK Python Unit Tests', hidden=False if cli.config.user.developer else True) def pytest(cli): """Run several linting/testing commands. """ - nose2 = cli.run(['nose2', '-v'], capture_output=False, stdin=DEVNULL) + nose2 = cli.run(['nose2', '-v', '-t' + 'lib/python', *cli.args.test], capture_output=False, stdin=DEVNULL) flake8 = cli.run(['flake8', 'lib/python'], capture_output=False, stdin=DEVNULL) return flake8.returncode | nose2.returncode diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 5a01943773..90a68ca3cd 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -295,6 +295,14 @@ def git_get_branch(): return git_branch.stdout.strip() +def git_get_tag(): + """Returns the current tag for a repo, or None. + """ + git_tag = cli.run(['git', 'describe', '--abbrev=0', '--tags']) + if git_tag.returncode == 0: + return git_tag.stdout.strip() + + def git_is_dirty(): """Returns 1 if repo is dirty, or 0 if clean """ diff --git a/lib/python/qmk/constants.py b/lib/python/qmk/constants.py index 754091a97e..433b110523 100644 --- a/lib/python/qmk/constants.py +++ b/lib/python/qmk/constants.py @@ -13,7 +13,7 @@ QMK_FIRMWARE_UPSTREAM = 'qmk/qmk_firmware' MAX_KEYBOARD_SUBFOLDERS = 5 # Supported processor types -CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK66FX1M0', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32L412', 'STM32L422', 'STM32L433', 'STM32L443', 'GD32VF103', 'WB32F3G71' +CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK66FX1M0', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F405', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32L412', 'STM32L422', 'STM32L433', 'STM32L443', 'GD32VF103', 'WB32F3G71' LUFA_PROCESSORS = 'at90usb162', 'atmega16u2', 'atmega32u2', 'atmega16u4', 'atmega32u4', 'at90usb646', 'at90usb647', 'at90usb1286', 'at90usb1287', None VUSB_PROCESSORS = 'atmega32a', 'atmega328p', 'atmega328', 'attiny85' |