Compare commits

...

7 Commits

Author SHA1 Message Date
Zach White e3e0856f96 New release: 0.0.37 → 0.0.38 2021-01-11 09:53:21 -08:00
Zach White 670a07ff0b replace dash with underscore in module import name 2021-01-11 09:37:32 -08:00
Zach White 9ad519d4a2 Switch to the new way off adding a path.
Per <https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/>
2020-12-02 10:44:07 -08:00
Zach White 655979cef5 New release: 0.0.36 → 0.0.37 2020-12-02 10:34:46 -08:00
Zach White 6b0d5fe85b update the release script 2020-12-02 10:34:35 -08:00
fauxpark d163222123 Path-ify QMK_HOME 2020-10-20 10:38:36 -07:00
skullY 5342ab3e10 check if requirements are installed before importing qmk_firmware 2020-10-19 09:30:01 -07:00
8 changed files with 130 additions and 89 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ jobs:
- name: Install Python dependencies - name: Install Python dependencies
run: | run: |
python3 -m pip install wheel python3 -m pip install wheel
echo "::add-path::$HOME/.local/bin" echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install QMK CLI from source - name: Install QMK CLI from source
run: | run: |
+1 -1
View File
@@ -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.36' __version__ = '0.0.38'
+70 -26
View File
@@ -1,36 +1,80 @@
"""Useful helper functions. """Useful helper functions.
""" """
from milc import cli, format_ansi import os
from functools import lru_cache
from importlib.util import find_spec
from pathlib import Path
from milc import cli
def question(question, boolean=True, default=''): def find_broken_requirements(requirements):
"""Asks the user to answer a question. """ Check if the modules in the given requirements.txt are available.
This keeps re-asking until it gets acceptible input. Args:
requirements
The path to a requirements.txt file
Returns a list of modules that couldn't be imported
""" """
if cli.args.yes: with Path(requirements).open() as fd:
return True broken_modules = []
if default and default.lower() == 'y': for line in fd.readlines():
answer_key = 'Y/n' line = line.strip().replace('<', '=').replace('>', '=')
elif default and default.lower() == 'n':
answer_key = 'y/N'
else:
answer_key = 'y/n'
prompt = format_ansi('\n*** %s [%s] ' % (question, answer_key)) if len(line) == 0 or line[0] == '#' or line.startswith('-r'):
continue
while True: if '#' in line:
answer = input(prompt) line = line.split('#')[0]
print()
if answer == '' and default.lower() == 'y':
answer = 'y'
elif answer == '' and default.lower() == 'n':
answer = 'n'
if answer.lower() in ['y', 'yes']: module_name = line.split('=')[0] if '=' in line else line
return True module_import_name = module_name.replace('-', '_')
elif answer.lower() in ['n', 'no']:
return False # Not every module is importable by its own name.
else: if module_name == "pep8-naming":
cli.echo('Invalid answer!') module_import_name = "pep8ext_naming"
if not find_spec(module_import_name):
broken_modules.append(module_name)
return broken_modules
@lru_cache(maxsize=2)
def find_qmk_firmware():
"""Look for qmk_firmware in the usual places.
This function returns the path to qmk_firmware, or the default location if one does not exist.
"""
if in_qmk_firmware():
return in_qmk_firmware()
if cli.config.user.qmk_home:
return Path(cli.config.user.qmk_home).expanduser().resolve()
if 'QMK_HOME' in os.environ:
path = Path(os.environ['QMK_HOME']).expanduser()
if path.exists():
return path.resolve()
return path
return Path.home() / 'qmk_firmware'
def in_qmk_firmware():
"""Returns the path to the qmk_firmware we are currently in, or None if we are not inside qmk_firmware.
"""
cur_dir = Path.cwd()
while len(cur_dir.parents) > 0:
found_lib = cur_dir / 'lib/python/qmk/cli/__init__.py'
found_quantum = cur_dir / 'quantum'
if found_lib.is_file() and found_quantum.is_dir():
return cur_dir
# Move up a directory before the next iteration
cur_dir = cur_dir / '..'
cur_dir = cur_dir.resolve()
+43 -59
View File
@@ -3,15 +3,16 @@
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.
""" """
import argparse
import platform
import os import os
import subprocess import subprocess
import sys import sys
from functools import lru_cache from platform import platform
from pathlib import Path from traceback import print_exc
import milc import milc
import milc.subcommand.config # noqa
from .helpers import find_broken_requirements, find_qmk_firmware, in_qmk_firmware
milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}Ψ{style_reset_all}' milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}Ψ{style_reset_all}'
@@ -23,50 +24,7 @@ def qmk_main(cli):
cli.print_help() cli.print_help()
@lru_cache(maxsize=2) # Python setuptools entrypoint
def in_qmk_firmware():
"""Returns the path to the qmk_firmware we are currently in, or None if we are not inside qmk_firmware.
"""
cur_dir = Path.cwd()
while len(cur_dir.parents) > 0:
found_bin = cur_dir / 'bin' / 'qmk'
# An additional check for something that exists in the root of qmk_firmware,
# but not in the script's install directory, to avoid recursive execution,
# if started from install directory.
# e.g.: cd ~/.local/bin && ./qmk
found_quantum = cur_dir / 'quantum'
if found_bin.is_file() and found_quantum.is_dir():
command = [sys.executable, found_bin.as_posix()]
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
return cur_dir
# Move up a directory before the next iteration
cur_dir = cur_dir / '..'
cur_dir = cur_dir.resolve()
def find_qmk_firmware():
"""Look for qmk_firmware in the usual places.
This function returns the path to qmk_firmware, or the default location if one does not exist.
"""
if in_qmk_firmware():
return in_qmk_firmware()
if milc.cli.config.user.qmk_home:
return Path(milc.cli.config.user.qmk_home).expanduser().resolve()
if 'QMK_HOME' in os.environ:
path = Path(os.environ['QMK_HOME']).expanduser()
if path.exists():
return path.resolve()
return path
return Path.home() / 'qmk_firmware'
def main(): def main():
"""Setup the environment before dispatching to the entrypoint. """Setup the environment before dispatching to the entrypoint.
""" """
@@ -75,7 +33,7 @@ def main():
print('Warning: Your Python version is out of date! Some subcommands may not work!') print('Warning: Your Python version is out of date! Some subcommands may not work!')
print('Please upgrade to Python 3.6 or later.') print('Please upgrade to Python 3.6 or later.')
if 'windows' in platform.platform().lower(): if 'windows' in platform().lower():
msystem = os.environ.get('MSYSTEM', '') msystem = os.environ.get('MSYSTEM', '')
if 'mingw64' not in sys.executable or 'MINGW64' not in msystem: if 'mingw64' not in sys.executable or 'MINGW64' not in msystem:
@@ -91,21 +49,47 @@ def main():
os.environ['QMK_HOME'] = str(qmk_firmware) os.environ['QMK_HOME'] = str(qmk_firmware)
os.environ['ORIG_CWD'] = os.getcwd() os.environ['ORIG_CWD'] = os.getcwd()
# Import the subcommand modules
import qmk_cli.subcommands import qmk_cli.subcommands
# Check out and initialize the qmk_firmware environment
if qmk_firmware.exists(): if qmk_firmware.exists():
# All subcommands are run relative to the qmk_firmware root to make it easier to use the right copy of qmk_firmware.
os.chdir(str(qmk_firmware)) os.chdir(str(qmk_firmware))
sys.path.append(str(qmk_firmware / 'lib' / 'python'))
try:
import qmk.cli
except ImportError:
if qmk_firmware.name != 'qmk_firmware':
print('Warning: %s does not end in "qmk_firmware". Do you need to set QMK_HOME to "%s/qmk_firmware"?' % (qmk_firmware,qmk_firmware))
print('Error: %s is too old or not set up correctly!' % qmk_firmware) # Check to make sure we have all the requirements
print('Please update it or remove it completely before continuing.') broken_modules = find_broken_requirements('requirements.txt')
sys.exit(1) broken_dev_modules = find_broken_requirements('requirements-dev.txt') if milc.cli.config.user.developer else []
if broken_modules or broken_dev_modules:
for module in broken_modules + broken_dev_modules:
print('Could not find module %s!' % module)
msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.'
if broken_modules:
print()
print(msg_install % (qmk_firmware / 'requirements.txt',))
if broken_dev_modules:
print()
print(msg_install % (qmk_firmware / 'requirements-dev.txt',))
print('You can also turn off developer mode: qmk config user.developer=None')
print()
else:
# Environment looks good, include the qmk_firmware subcommands
sys.path.append(str(qmk_firmware / 'lib/python'))
try:
import qmk.cli
except ImportError as e:
if qmk_firmware.name != 'qmk_firmware':
print('Warning: %s does not end in "qmk_firmware". Do you need to set QMK_HOME to "%s/qmk_firmware"?' % (qmk_firmware, qmk_firmware))
print('Error: %s: %s', (e.__class__.__name__, e))
print_exc()
sys.exit(1)
# Call the entrypoint # Call the entrypoint
return_code = milc.cli() return_code = milc.cli()
+1 -1
View File
@@ -74,7 +74,7 @@ def setup(cli):
exit(1) exit(1)
# Offer to set `user.qmk_home` for them. # Offer to set `user.qmk_home` for them.
if cli.args.home != os.environ['QMK_HOME'] and yesno(home_prompt): if cli.args.home != Path(os.environ['QMK_HOME']) and yesno(home_prompt):
cli.config['user']['qmk_home'] = str(cli.args.home.absolute()) cli.config['user']['qmk_home'] = str(cli.args.home.absolute())
cli.write_config_option('user', 'qmk_home') cli.write_config_option('user', 'qmk_home')
+11
View File
@@ -12,6 +12,17 @@ TWINE_USERNAME=$PYPI_USERNAME
export FLIT_USERNAME TWINE_USERNAME export FLIT_USERNAME TWINE_USERNAME
if ! bumpversion -h &> /dev/null; then
echo "Missing bumpversion! Please run: pip3 install -U -r requirements-dev.txt"
exit 1
fi
if ! twine -h &> /dev/null; then
echo "Missing twine! Please run: pip3 install -U -r requirements-dev.txt"
exit 1
fi
# Bump the version, tag, and push
rm -f dist/* rm -f dist/*
bumpversion patch bumpversion patch
git push origin master --tags git push origin master --tags
+2
View File
@@ -0,0 +1,2 @@
bumpversion
twine
+1 -1
View File
@@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.0.36 current_version = 0.0.38
commit = True commit = True
tag = True tag = True
tag_name = {new_version} tag_name = {new_version}