Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cli._subcommand.__name__ deprecation warning #24533

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lib/python/qmk/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,31 @@
from qmk.keymap import find_keymap_from_dir


def _get_subcommand_name():
"""Handle missing cli.subcommand_name on older versions of milc
"""
try:
return cli.subcommand_name
except AttributeError:
return cli._subcommand.__name__


def automagic_keyboard(func):
"""Sets `cli.config.<subcommand>.keyboard` based on environment.

This will rewrite cli.config.<subcommand>.keyboard if the user did not pass `--keyboard` and the directory they are currently in is a keyboard or keymap directory.
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
cmd = _get_subcommand_name()

# Ensure that `--keyboard` was not passed and CWD is under `qmk_firmware/keyboards`
if cli.config_source[cli._subcommand.__name__]['keyboard'] != 'argument':
if cli.config_source[cmd]['keyboard'] != 'argument':
keyboard = find_keyboard_from_dir()

if keyboard:
cli.config[cli._subcommand.__name__]['keyboard'] = keyboard
cli.config_source[cli._subcommand.__name__]['keyboard'] = 'keyboard_directory'
cli.config[cmd]['keyboard'] = keyboard
cli.config_source[cmd]['keyboard'] = 'keyboard_directory'

return func(*args, **kwargs)

Expand All @@ -36,13 +47,15 @@ def automagic_keymap(func):
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
cmd = _get_subcommand_name()

# Ensure that `--keymap` was not passed and that we're under `qmk_firmware`
if cli.config_source[cli._subcommand.__name__]['keymap'] != 'argument':
if cli.config_source[cmd]['keymap'] != 'argument':
keymap_name, keymap_type = find_keymap_from_dir()

if keymap_name:
cli.config[cli._subcommand.__name__]['keymap'] = keymap_name
cli.config_source[cli._subcommand.__name__]['keymap'] = keymap_type
cli.config[cmd]['keymap'] = keymap_name
cli.config_source[cmd]['keymap'] = keymap_type

return func(*args, **kwargs)

Expand Down