Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 120ce557f1 | |||
| a15b0d6460 | |||
| f0dafaf068 | |||
| 3414bdcaa3 | |||
| c8567d8098 | |||
| dc3ca88deb | |||
| a4e9c34387 | |||
| 742e1ce0e1 | |||
| 39df759f57 | |||
| b694c4284d | |||
| e184710036 | |||
| d67addde2d | |||
| 29541559d0 | |||
| db0b8cb9a0 | |||
| 6a0e62a078 | |||
| bbc5ffd6c9 | |||
| e0adba4e68 | |||
| 56bcb12ed6 | |||
| 897fe121e2 | |||
| 1a723e488f | |||
| bf502d26fa | |||
| ebea7f7ea0 | |||
| 49b288786a |
@@ -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
|
# 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/).
|
A program to help users work with [QMK Firmware](https://qmk.fm/).
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
|||||||
@@ -178,8 +178,9 @@ class ConfigurationSection(Configuration):
|
|||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
"""Returns a config value, pulling from the `user` section as a fallback.
|
"""Returns a config value, pulling from the `user` section as a fallback.
|
||||||
|
This is called when the attribute is accessed either via the get method or through [ ] index.
|
||||||
"""
|
"""
|
||||||
if key in self._config:
|
if key in self._config and self._config.get(key) is not None:
|
||||||
return self._config[key]
|
return self._config[key]
|
||||||
|
|
||||||
elif key in self.parent.user:
|
elif key in self.parent.user:
|
||||||
@@ -187,6 +188,15 @@ class ConfigurationSection(Configuration):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def __getattr__(self, key):
|
||||||
|
"""Returns the config value from the `user` section.
|
||||||
|
This is called when the attribute is accessed via dot notation but does not exists.
|
||||||
|
"""
|
||||||
|
if key in self.parent.user:
|
||||||
|
return self.parent.user[key]
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def handle_store_boolean(self, *args, **kwargs):
|
def handle_store_boolean(self, *args, **kwargs):
|
||||||
"""Does the add_argument for action='store_boolean'.
|
"""Does the add_argument for action='store_boolean'.
|
||||||
@@ -263,7 +273,7 @@ class MILC(object):
|
|||||||
self._inside_context_manager = False
|
self._inside_context_manager = False
|
||||||
self.ansi = ansi_colors
|
self.ansi = ansi_colors
|
||||||
self.arg_only = []
|
self.arg_only = []
|
||||||
self.config = None
|
self.config = self.config_source = None
|
||||||
self.config_file = None
|
self.config_file = None
|
||||||
self.default_arguments = {}
|
self.default_arguments = {}
|
||||||
self.version = 'unknown'
|
self.version = 'unknown'
|
||||||
@@ -463,6 +473,7 @@ class MILC(object):
|
|||||||
"""
|
"""
|
||||||
self.acquire_lock()
|
self.acquire_lock()
|
||||||
self.config = Configuration()
|
self.config = Configuration()
|
||||||
|
self.config_source = Configuration()
|
||||||
self.config_file = self.find_config_file()
|
self.config_file = self.find_config_file()
|
||||||
|
|
||||||
if self.config_file and self.config_file.exists():
|
if self.config_file and self.config_file.exists():
|
||||||
@@ -488,6 +499,7 @@ class MILC(object):
|
|||||||
value = int(value)
|
value = int(value)
|
||||||
|
|
||||||
self.config[section][option] = value
|
self.config[section][option] = value
|
||||||
|
self.config_source[section][option] = 'config_file'
|
||||||
|
|
||||||
self.release_lock()
|
self.release_lock()
|
||||||
|
|
||||||
@@ -501,7 +513,10 @@ class MILC(object):
|
|||||||
|
|
||||||
if argument not in self.arg_only:
|
if argument not in self.arg_only:
|
||||||
# Find the argument's section
|
# Find the argument's section
|
||||||
if self._entrypoint.__name__ in self.default_arguments and argument in self.default_arguments[self._entrypoint.__name__]:
|
# 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
|
argument_found = True
|
||||||
section = self._entrypoint.__name__
|
section = self._entrypoint.__name__
|
||||||
if argument in self.default_arguments['general']:
|
if argument in self.default_arguments['general']:
|
||||||
@@ -513,13 +528,18 @@ class MILC(object):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Merge this argument into self.config
|
# Merge this argument into self.config
|
||||||
if argument in self.default_arguments:
|
if argument in self.default_arguments['general'] or argument in self.default_arguments[entrypoint_name]:
|
||||||
arg_value = getattr(self.args, argument)
|
arg_value = getattr(self.args, argument)
|
||||||
if arg_value:
|
if arg_value is not None:
|
||||||
self.config[section][argument] = arg_value
|
self.config[section][argument] = arg_value
|
||||||
|
self.config_source[section][argument] = 'argument'
|
||||||
else:
|
else:
|
||||||
if argument not in self.config[section]:
|
if argument not in self.config[entrypoint_name]:
|
||||||
self.config[section][argument] = getattr(self.args, argument)
|
# 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'
|
||||||
|
|
||||||
self.release_lock()
|
self.release_lock()
|
||||||
|
|
||||||
@@ -555,7 +575,7 @@ class MILC(object):
|
|||||||
|
|
||||||
# Move the new config file into place atomically
|
# Move the new config file into place atomically
|
||||||
if os.path.getsize(tmpfile.name) > 0:
|
if os.path.getsize(tmpfile.name) > 0:
|
||||||
os.rename(tmpfile.name, str(self.config_file))
|
os.replace(tmpfile.name, str(self.config_file))
|
||||||
else:
|
else:
|
||||||
self.log.warning('Config file saving failed, not replacing %s with %s.', str(self.config_file), tmpfile.name)
|
self.log.warning('Config file saving failed, not replacing %s with %s.', str(self.config_file), tmpfile.name)
|
||||||
|
|
||||||
@@ -595,23 +615,25 @@ class MILC(object):
|
|||||||
|
|
||||||
return entrypoint_func
|
return entrypoint_func
|
||||||
|
|
||||||
def add_subcommand(self, handler, description, name=None, **kwargs):
|
def add_subcommand(self, handler, description, name=None, hidden=False, **kwargs):
|
||||||
"""Register a subcommand.
|
"""Register a subcommand.
|
||||||
|
|
||||||
If name is not provided we use `handler.__name__`.
|
If name is not provided we use `handler.__name__`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self._inside_context_manager:
|
if self._inside_context_manager:
|
||||||
raise RuntimeError('You must run this before the with statement!')
|
raise RuntimeError('You must run this before the with statement!')
|
||||||
|
|
||||||
if self._subparsers is None:
|
if self._subparsers is None:
|
||||||
self.add_subparsers()
|
self.add_subparsers(metavar="")
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
name = handler.__name__.replace("_", "-")
|
name = handler.__name__.replace("_", "-")
|
||||||
|
|
||||||
self.acquire_lock()
|
self.acquire_lock()
|
||||||
|
if not hidden:
|
||||||
kwargs['help'] = description
|
self._subparsers.metavar = "{%s,%s}" % (self._subparsers.metavar[1:-1], name) if self._subparsers.metavar else "{%s%s}" % (self._subparsers.metavar[1:-1], name)
|
||||||
|
kwargs['help'] = description
|
||||||
self.subcommands[name] = SubparserWrapper(self, name, self._subparsers.add_parser(name, **kwargs))
|
self.subcommands[name] = SubparserWrapper(self, name, self._subparsers.add_parser(name, **kwargs))
|
||||||
self.subcommands[name].set_defaults(entrypoint=handler)
|
self.subcommands[name].set_defaults(entrypoint=handler)
|
||||||
|
|
||||||
@@ -619,11 +641,11 @@ class MILC(object):
|
|||||||
|
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
def subcommand(self, description, **kwargs):
|
def subcommand(self, description, hidden=False, **kwargs):
|
||||||
"""Decorator to register a subcommand.
|
"""Decorator to register a subcommand.
|
||||||
"""
|
"""
|
||||||
def subcommand_function(handler):
|
def subcommand_function(handler):
|
||||||
return self.add_subcommand(handler, description, **kwargs)
|
return self.add_subcommand(handler, description, hidden=hidden, **kwargs)
|
||||||
|
|
||||||
return subcommand_function
|
return subcommand_function
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
"""A program to help you work with qmk_firmware."""
|
"""A program to help you work with qmk_firmware."""
|
||||||
|
|
||||||
__version__ = '0.0.25'
|
__version__ = '0.0.31'
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
"""CLI wrapper for running QMK commands.
|
"""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.
|
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 argparse
|
||||||
import os
|
import os
|
||||||
@@ -33,7 +30,7 @@ def in_qmk_firmware():
|
|||||||
while len(cur_dir.parents) > 0:
|
while len(cur_dir.parents) > 0:
|
||||||
found_bin = cur_dir / 'bin' / 'qmk'
|
found_bin = cur_dir / 'bin' / 'qmk'
|
||||||
if found_bin.is_file():
|
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)
|
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
@@ -67,6 +64,11 @@ def find_qmk_firmware():
|
|||||||
def main():
|
def main():
|
||||||
"""Setup the environment before dispatching to the entrypoint.
|
"""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.')
|
||||||
|
|
||||||
# Environment setup
|
# Environment setup
|
||||||
import qmk_cli
|
import qmk_cli
|
||||||
milc.cli.version = qmk_cli.__version__
|
milc.cli.version = qmk_cli.__version__
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def setup(cli):
|
|||||||
# Run `qmk_firmware/bin/qmk doctor` to check the rest of the environment out
|
# Run `qmk_firmware/bin/qmk doctor` to check the rest of the environment out
|
||||||
if qmk_firmware.exists():
|
if qmk_firmware.exists():
|
||||||
qmk_bin = qmk_firmware / 'bin' / 'qmk'
|
qmk_bin = qmk_firmware / 'bin' / 'qmk'
|
||||||
doctor = subprocess.run([sys.executable, qmk_bin, 'doctor'])
|
doctor = subprocess.run([sys.executable, str(qmk_bin), 'doctor'])
|
||||||
if doctor.returncode != 0:
|
if doctor.returncode != 0:
|
||||||
cli.log.error('Your build environment is not setup completely.')
|
cli.log.error('Your build environment is not setup completely.')
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ TWINE_USERNAME=$PYPI_USERNAME
|
|||||||
|
|
||||||
export FLIT_USERNAME TWINE_USERNAME
|
export FLIT_USERNAME TWINE_USERNAME
|
||||||
|
|
||||||
rm dist/*
|
rm -f dist/*
|
||||||
bumpversion patch
|
bumpversion patch
|
||||||
git push origin master --tags
|
git push origin master --tags
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.0.25
|
current_version = 0.0.31
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
tag_name = {new_version}
|
tag_name = {new_version}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ if __name__ == "__main__":
|
|||||||
"colorama",
|
"colorama",
|
||||||
"flake8",
|
"flake8",
|
||||||
"hjson",
|
"hjson",
|
||||||
|
"nose2",
|
||||||
"yapf"
|
"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