qmk / qmk_cli

A program to help users work with QMK
MIT License
142 stars 36 forks source link

[Bug] qmk info throws an error if no keymap is provided / defined #98

Closed j4ckofalltrades closed 2 years ago

j4ckofalltrades commented 3 years ago

Describe the Bug

Running qmk info -kb throws an error if there is no -km | --keymap argument provided or no default keymap is configured via qmk config.

$ qmk info -kb arisu
Keyboard Name: Arisu
Manufacturer: Fate
Website: https://github.com/FateNozomi/arisu-pcb
Maintainer: FateNozomi
Keyboard Folder: arisu
Layouts: LAYOUT
Processor: atmega32u4
Bootloader: atmel-dfu
<class 'TypeError'>
β˜’ unsupported operand type(s) for /: 'PosixPath' and 'NoneType'
Traceback (most recent call last):
  File "/home/jordan/.local/lib/python3.7/site-packages/milc/milc.py", line 523, in __call__
    return self.__call__()
  File "/home/jordan/.local/lib/python3.7/site-packages/milc/milc.py", line 528, in __call__
    return self._subcommand(self)
  File "/home/jordan/projects/personal/qmk_firmware/lib/python/qmk/decorators.py", line 27, in wrapper
    return func(*args, **kwargs)
  File "/home/jordan/projects/personal/qmk_firmware/lib/python/qmk/decorators.py", line 47, in wrapper
    return func(*args, **kwargs)
  File "/home/jordan/projects/personal/qmk_firmware/lib/python/qmk/cli/info.py", line 188, in info
    show_keymap(kb_info_json, title_caps)
  File "/home/jordan/projects/personal/qmk_firmware/lib/python/qmk/cli/info.py", line 24, in show_keymap
    keymap_path = locate_keymap(cli.config.info.keyboard, cli.config.info.keymap)
  File "/home/jordan/projects/personal/qmk_firmware/lib/python/qmk/keymap.py", line 287, in locate_keymap
    if (keymap_dir / keymap / 'keymap.c').exists():
TypeError: unsupported operand type(s) for /: 'PosixPath' and 'NoneType'

I tried printing out the keymap argument by adding print('keymap (-km | --keymap): ' + cli.config_source.info.keymap)and the result was keymap (-km | --keymap): argument.

Additional Context?

I would say this should be filed in https://github.com/qmk/qmk_cli, except that I don't get this error with MILC 1.5.0 - only after updating to the latest version (1.6.4) do I get the same thing, and it also occurs in MSYS with:

TypeError: unsupported operand type(s) for /: 'WindowsPath' and 'NoneType'

So it is either a MILC bug, or some interaction between MILC and the QMK CLI.

_Originally posted by @fauxpark in https://github.com/qmk/qmk_firmware/issues/14509#issuecomment-922434580_

fauxpark commented 3 years ago

As of MILC 1.6.2, cli.config_source.info.keymap returns argument instead of None, which causes this block to execute even if -km was not specified: https://github.com/qmk/qmk_firmware/blob/master/lib/python/qmk/cli/info.py#L187

So, apologies, it's not actually a qmk_cli issue after all - it's either the CLI portion housed in qmk_firmware, or MILC.

fauxpark commented 3 years ago

@skullydazed

fauxpark commented 3 years ago

After digging into it a little more, I'm thinking the issue is partly QMK CLI, partly MILC. The first condition in the line I linked above I suspect is wrong, and should just be cli.config.info.keymap. But also, cli.config_source.info.keymap should be None in this case, as it's not passed by command line argument, nor is it present in the config file.

skullydazed commented 3 years ago

I suspect this is the problem: https://github.com/clueboard/milc/pull/44/files#diff-f427888a58f1d4590296279a9460cd64af5f1ae875dff4257b141cb904c2f721R435

I'm thinking about this and will write up a test that catches this situation so we can fix it.

skullydazed commented 3 years ago

I've pushed a fix for this to MILC: https://github.com/clueboard/milc/commit/2ae9116aea3d52cc6b89ed6fc55c81b1fbca63f7

I'll cut a new release later this afternoon if the CI comes back clean.

skullydazed commented 3 years ago

I've released MILC 1.6.5 which should fix this. Can you give it a try?

fauxpark commented 3 years ago

Working on MSYS and WSL πŸ‘