Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5229ce14e3 | |||
| 8fa960f25e | |||
| 1481dfe157 | |||
| ac39b9bb0f | |||
| 44a446308f | |||
| 90bdf52416 | |||
| 191980052e | |||
| 5fbdd95c4b | |||
| 1002360e20 | |||
| a03aa1cbba | |||
| a0b692d718 | |||
| ab7d0c6e46 | |||
| 73c903b8b6 | |||
| 8f2185af32 | |||
| bae2f1f1ee | |||
| 120ce557f1 | |||
| a15b0d6460 | |||
| f0dafaf068 | |||
| 3414bdcaa3 | |||
| c8567d8098 | |||
| dc3ca88deb | |||
| a4e9c34387 | |||
| 742e1ce0e1 | |||
| 39df759f57 | |||
| b694c4284d | |||
| e184710036 | |||
| d67addde2d | |||
| 29541559d0 | |||
| db0b8cb9a0 | |||
| 6a0e62a078 |
@@ -0,0 +1,68 @@
|
||||
name: CLI Setup
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test_cli_linux_macos:
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
QMK_HOME: ~/qmk_firmware
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-latest, ubuntu-latest]
|
||||
python-version: [3.6, 3.7, 3.8]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Install python dependencies
|
||||
run: |
|
||||
python -m pip install wheel
|
||||
echo "::add-path::$HOME/.local/bin"
|
||||
|
||||
- name: Install QMK CLI from source
|
||||
run: |
|
||||
python3 -m pip install -r requirements.txt
|
||||
python setup.py sdist bdist_wheel
|
||||
cd ..
|
||||
python3 -m pip install --force-reinstall --no-index --no-deps --prefix=~/.local --find-links qmk_cli/dist qmk
|
||||
|
||||
- name: Run qmk setup -y
|
||||
run: qmk setup -y
|
||||
|
||||
test_cli_win:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [3.6, 3.8]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Set up MSYS2
|
||||
uses: qmk/setup-msys2@v1
|
||||
with:
|
||||
update: true
|
||||
|
||||
- name: (MSYS2) Install git and python3
|
||||
run: msys2do pacman -S git python3-pip --noconfirm
|
||||
|
||||
- name: (MSYS2) Upgrade pip and setuptools and install wheel
|
||||
run: |
|
||||
msys2do python3 -m pip install --upgrade pip setuptools
|
||||
msys2do python3 -m pip install wheel
|
||||
|
||||
- name: (MSYS2) Install QMK CLI from source
|
||||
run: msys2do ./setup_msys.sh $(cygpath "${{ github.workspace }}")
|
||||
|
||||
- name: (MSYS2) Run qmk setup -y
|
||||
run: msys2do qmk setup -y
|
||||
@@ -1,5 +1,5 @@
|
||||
# QMK CLI
|
||||
|
||||
[](https://github.com/qmk/qmk_cli/actions?query=workflow%3A%22CLI+Setup%22)
|
||||
A program to help users work with [QMK Firmware](https://qmk.fm/).
|
||||
|
||||
# Features
|
||||
|
||||
@@ -242,15 +242,24 @@ class SubparserWrapper(object):
|
||||
|
||||
This also stores the default for the argument in `self.cli.default_arguments`.
|
||||
"""
|
||||
if 'action' in kwargs and kwargs['action'] == 'store_boolean':
|
||||
if kwargs.get('action') == 'store_boolean':
|
||||
# Store boolean will call us again with the enable/disable flag arguments
|
||||
return handle_store_boolean(self, *args, **kwargs)
|
||||
|
||||
self.cli.acquire_lock()
|
||||
argument_name = self.cli.get_argument_name(*args, **kwargs)
|
||||
|
||||
self.subparser.add_argument(*args, **kwargs)
|
||||
|
||||
if kwargs.get('action') == 'store_false':
|
||||
self.cli._config_store_false.append(argument_name)
|
||||
|
||||
if kwargs.get('action') == 'store_true':
|
||||
self.cli._config_store_true.append(argument_name)
|
||||
|
||||
if self.submodule not in self.cli.default_arguments:
|
||||
self.cli.default_arguments[self.submodule] = {}
|
||||
self.cli.default_arguments[self.submodule][self.cli.get_argument_name(*args, **kwargs)] = kwargs.get('default')
|
||||
self.cli.default_arguments[self.submodule][argument_name] = kwargs.get('default')
|
||||
self.cli.release_lock()
|
||||
|
||||
|
||||
@@ -268,11 +277,13 @@ class MILC(object):
|
||||
|
||||
# Define some basic info
|
||||
self.acquire_lock()
|
||||
self._config_store_true = []
|
||||
self._config_store_false = []
|
||||
self._description = None
|
||||
self._entrypoint = None
|
||||
self._inside_context_manager = False
|
||||
self.ansi = ansi_colors
|
||||
self.arg_only = []
|
||||
self.arg_only = {}
|
||||
self.config = self.config_source = None
|
||||
self.config_file = None
|
||||
self.default_arguments = {}
|
||||
@@ -377,7 +388,7 @@ class MILC(object):
|
||||
self.add_argument('--log-file', help='File to write log messages to')
|
||||
self.add_argument('--color', action='store_boolean', default=True, help='color in output')
|
||||
self.add_argument('--config-file', help='The location for the configuration file')
|
||||
self.arg_only.append('config_file')
|
||||
self.arg_only['config_file'] = ['general']
|
||||
|
||||
def add_subparsers(self, title='Sub-commands', **kwargs):
|
||||
if self._inside_context_manager:
|
||||
@@ -427,17 +438,20 @@ class MILC(object):
|
||||
raise RuntimeError('You must run this before the with statement!')
|
||||
|
||||
def argument_function(handler):
|
||||
if 'arg_only' in kwargs and kwargs['arg_only']:
|
||||
subcommand_name = handler.__name__.replace("_", "-")
|
||||
|
||||
if kwargs.get('arg_only'):
|
||||
arg_name = self.get_argument_name(*args, **kwargs)
|
||||
self.arg_only.append(arg_name)
|
||||
if arg_name not in self.arg_only:
|
||||
self.arg_only[arg_name] = []
|
||||
self.arg_only[arg_name].append(subcommand_name)
|
||||
del kwargs['arg_only']
|
||||
|
||||
name = handler.__name__.replace("_", "-")
|
||||
if handler is self._entrypoint:
|
||||
self.add_argument(*args, **kwargs)
|
||||
|
||||
elif name in self.subcommands:
|
||||
self.subcommands[name].add_argument(*args, **kwargs)
|
||||
elif subcommand_name in self.subcommands:
|
||||
self.subcommands[subcommand_name].add_argument(*args, **kwargs)
|
||||
|
||||
else:
|
||||
raise RuntimeError('Decorated function is not entrypoint or subcommand!')
|
||||
@@ -511,35 +525,37 @@ class MILC(object):
|
||||
if argument in ('subparsers', 'entrypoint'):
|
||||
continue
|
||||
|
||||
if argument not in self.arg_only:
|
||||
# Find the argument's section
|
||||
# Underscores in command's names are converted to dashes during initialization.
|
||||
# TODO(Erovia) Find a better solution
|
||||
entrypoint_name = self._entrypoint.__name__.replace("_", "-")
|
||||
if entrypoint_name in self.default_arguments and argument in self.default_arguments[entrypoint_name]:
|
||||
argument_found = True
|
||||
section = self._entrypoint.__name__
|
||||
if argument in self.default_arguments['general']:
|
||||
argument_found = True
|
||||
section = 'general'
|
||||
# Find the argument's section
|
||||
# Underscores in command's names are converted to dashes during initialization.
|
||||
# TODO(Erovia) Find a better solution
|
||||
entrypoint_name = self._entrypoint.__name__.replace("_", "-")
|
||||
if entrypoint_name in self.default_arguments and argument in self.default_arguments[entrypoint_name]:
|
||||
argument_found = True
|
||||
section = self._entrypoint.__name__
|
||||
if argument in self.default_arguments['general']:
|
||||
argument_found = True
|
||||
section = 'general'
|
||||
|
||||
if not argument_found:
|
||||
raise RuntimeError('Could not find argument in `self.default_arguments`. This should be impossible!')
|
||||
exit(1)
|
||||
if not argument_found:
|
||||
raise RuntimeError('Could not find argument in `self.default_arguments`. This should be impossible!')
|
||||
exit(1)
|
||||
|
||||
if argument not in self.arg_only or section not in self.arg_only[argument]:
|
||||
# Determine the arg value and source
|
||||
arg_value = getattr(self.args, argument)
|
||||
if argument in self._config_store_true and arg_value:
|
||||
passed_on_cmdline = True
|
||||
elif argument in self._config_store_false and not arg_value:
|
||||
passed_on_cmdline = True
|
||||
elif arg_value is not None:
|
||||
passed_on_cmdline = True
|
||||
else:
|
||||
passed_on_cmdline = False
|
||||
|
||||
# Merge this argument into self.config
|
||||
if argument in self.default_arguments['general'] or argument in self.default_arguments[entrypoint_name]:
|
||||
arg_value = getattr(self.args, argument)
|
||||
if arg_value is not None:
|
||||
self.config[section][argument] = arg_value
|
||||
self.config_source[section][argument] = 'argument'
|
||||
else:
|
||||
if argument not in self.config[entrypoint_name]:
|
||||
# Check if the argument exist for this section
|
||||
arg = getattr(self.args, argument)
|
||||
if arg is not None:
|
||||
self.config[section][argument] = arg
|
||||
self.config_source[section][argument] = 'argument'
|
||||
if passed_on_cmdline and (argument in self.default_arguments['general'] or argument in self.default_arguments[entrypoint_name] or argument not in self.config[entrypoint_name]):
|
||||
self.config[section][argument] = arg_value
|
||||
self.config_source[section][argument] = 'argument'
|
||||
|
||||
self.release_lock()
|
||||
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
"""A program to help you work with qmk_firmware."""
|
||||
|
||||
__version__ = '0.0.28'
|
||||
__version__ = '0.0.33'
|
||||
|
||||
+18
-5
@@ -2,9 +2,6 @@
|
||||
"""CLI wrapper for running QMK commands.
|
||||
|
||||
This program can be run from anywhere, with or without a qmk_firmware repository. If a qmk_firmware repository can be located we will use that to augment our available subcommands.
|
||||
|
||||
FIXME(skullydazed/anyone): --help shows underscores where we want dashes in subcommands (EG json_keymap instead of json-keymap)
|
||||
TODO(skullydazed/anyone): Need a way to filter some subcommands from --help (EG `qmk hello`)
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
@@ -12,6 +9,7 @@ import subprocess
|
||||
import sys
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
import platform
|
||||
|
||||
import milc
|
||||
|
||||
@@ -33,7 +31,7 @@ def in_qmk_firmware():
|
||||
while len(cur_dir.parents) > 0:
|
||||
found_bin = cur_dir / 'bin' / 'qmk'
|
||||
if found_bin.is_file():
|
||||
command = [found_bin.as_posix(), '--version']
|
||||
command = [sys.executable, found_bin.as_posix()]
|
||||
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
if result.returncode == 0:
|
||||
@@ -67,6 +65,16 @@ def find_qmk_firmware():
|
||||
def main():
|
||||
"""Setup the environment before dispatching to the entrypoint.
|
||||
"""
|
||||
# Warn if they use an outdated python version
|
||||
if sys.version_info < (3, 6):
|
||||
print('Warning: Your Python version is out of date! Some subcommands may not work!')
|
||||
print('Please upgrade to Python 3.6 or later.')
|
||||
|
||||
if 'windows' in platform.platform().lower():
|
||||
if 'mingw64' not in sys.executable or 'mingw64' not in os.environ.get('MSYSTEM_PREFIX', ''):
|
||||
print('Warning: It seems you are not using the MINGW64 terminal.')
|
||||
print('While the MSYS one can work, too, we recommend/support you start "MSYS2 MinGW 64-bit".\n')
|
||||
|
||||
# Environment setup
|
||||
import qmk_cli
|
||||
milc.cli.version = qmk_cli.__version__
|
||||
@@ -80,7 +88,12 @@ def main():
|
||||
if qmk_firmware.exists():
|
||||
os.chdir(str(qmk_firmware))
|
||||
sys.path.append(str(qmk_firmware / 'lib' / 'python'))
|
||||
import qmk.cli
|
||||
try:
|
||||
import qmk.cli
|
||||
except ImportError:
|
||||
print('Error: %s is too old or not set up correctly!' % qmk_firmware)
|
||||
print('Please update it or remove it completely before continuing.')
|
||||
sys.exit(1)
|
||||
|
||||
# Call the entrypoint
|
||||
milc.cli()
|
||||
|
||||
@@ -14,7 +14,8 @@ default_fork = 'qmk/' + default_repo
|
||||
default_branch = 'master'
|
||||
|
||||
|
||||
@cli.argument('-y', '--yes', action='store_true', help='Answer yes to all questions')
|
||||
@cli.argument('-n', '--no', arg_only=True, action='store_true', help='Answer no to all questions')
|
||||
@cli.argument('-y', '--yes', arg_only=True, action='store_true', help='Answer yes to all questions')
|
||||
@cli.argument('--baseurl', default='https://github.com', help='The URL all git operations start from')
|
||||
@cli.argument('-b', '--branch', default=default_branch, help='The branch to clone')
|
||||
@cli.argument('destination', default=os.environ['QMK_HOME'], nargs='?', help='The directory to clone to')
|
||||
@@ -23,8 +24,13 @@ default_branch = 'master'
|
||||
def setup(cli):
|
||||
qmk_firmware = Path(cli.args.destination)
|
||||
|
||||
# Sanity checks
|
||||
if cli.args.yes and cli.args.no:
|
||||
cli.log.error("Can't use both --yes and --no at the same time.")
|
||||
exit(1)
|
||||
|
||||
# Check on qmk_firmware, and if it doesn't exist offer to check it out.
|
||||
if qmk_firmware.exists():
|
||||
if (qmk_firmware / 'Makefile').exists():
|
||||
cli.log.info('Found qmk_firmware at %s.', str(qmk_firmware))
|
||||
else:
|
||||
cli.log.error('qmk_firmware not found!')
|
||||
@@ -35,7 +41,12 @@ def setup(cli):
|
||||
# Run `qmk_firmware/bin/qmk doctor` to check the rest of the environment out
|
||||
if qmk_firmware.exists():
|
||||
qmk_bin = qmk_firmware / 'bin' / 'qmk'
|
||||
doctor = subprocess.run([sys.executable, qmk_bin, 'doctor'])
|
||||
doctor_cmd = [sys.executable, str(qmk_bin), 'doctor']
|
||||
if cli.args.yes:
|
||||
doctor_cmd.append('--yes')
|
||||
if cli.args.no:
|
||||
doctor_cmd.append('--no')
|
||||
doctor = subprocess.run(doctor_cmd)
|
||||
if doctor.returncode != 0:
|
||||
cli.log.error('Your build environment is not setup completely.')
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[bumpversion]
|
||||
current_version = 0.0.28
|
||||
current_version = 0.0.33
|
||||
commit = True
|
||||
tag = True
|
||||
tag_name = {new_version}
|
||||
|
||||
@@ -46,6 +46,7 @@ if __name__ == "__main__":
|
||||
"colorama",
|
||||
"flake8",
|
||||
"hjson",
|
||||
"nose2",
|
||||
"yapf"
|
||||
],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
cp -r $1 ~/qmk_cli
|
||||
|
||||
export PATH=~/.local/bin:$PATH
|
||||
echo "PATH=$PATH" >> ~/.bashrc
|
||||
|
||||
export QMK_HOME=~/qmk_firmware
|
||||
export CLI_DIR=~/qmk_cli
|
||||
|
||||
cd $CLI_DIR
|
||||
python3 -m pip install -r requirements.txt
|
||||
python3 setup.py sdist bdist_wheel
|
||||
cd ~
|
||||
python3 -m pip install --force-reinstall --no-index --no-deps --prefix=~/.local --find-links qmk_cli/dist qmk
|
||||
Reference in New Issue
Block a user