diff options
author | Erovia <erovia@users.noreply.github.com> | 2019-10-24 20:33:58 +0200 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2020-02-15 15:19:03 -0800 |
commit | 3ed1223678d3ec40f4cceecd320dd1112cdfb157 (patch) | |
tree | aba0df6ac06a6e8632b1a24fe55c0a392e841394 | |
parent | d257a98cb80a90f116072c882753039b10a5e042 (diff) |
Drop bs4 dependency, update docs, minor improvements
-rw-r--r-- | docs/cli.md | 4 | ||||
-rw-r--r-- | lib/python/qmk/cli/list/keymaps.py | 11 | ||||
-rw-r--r-- | lib/python/qmk/makefile.py | 2 | ||||
-rw-r--r-- | lib/python/qmk/path.py | 23 | ||||
-rw-r--r-- | requirements.txt | 1 |
5 files changed, 18 insertions, 23 deletions
diff --git a/docs/cli.md b/docs/cli.md index f2b433fbbf..8ee8ab0e84 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -252,14 +252,14 @@ This command lists all the keyboards currently defined in `qmk_firmware` qmk list-keyboards ``` -## `qmk list_keymaps` +## `qmk list-keymaps` This command lists all the keymaps for a specified keyboard (and revision). **Usage**: ``` -qmk list_keymaps -kb planck/ez +qmk list-keymaps -kb planck/ez ``` ## `qmk new-keymap` diff --git a/lib/python/qmk/cli/list/keymaps.py b/lib/python/qmk/cli/list/keymaps.py index 494fe66a12..a17c6a9130 100644 --- a/lib/python/qmk/cli/list/keymaps.py +++ b/lib/python/qmk/cli/list/keymaps.py @@ -10,11 +10,14 @@ def list_keymaps(cli): """List the keymaps for a specific keyboard """ # ask for user input if keyboard was not provided in the command line - keyboard_name = cli.config.list_keymaps.keyboard if cli.config.list_keymaps.keyboard else input("Keyboard Name: ") + if not cli.config.list_keymaps.keyboard: + cli.config.list_keymaps.keyboard = input("Keyboard Name: ") try: - for name in qmk.keymap.list_keymaps(keyboard_name): + for name in qmk.keymap.list_keymaps(cli.config.list_keymaps.keyboard): # We echo instead of cli.log.info to allow easier piping of this output - cli.echo(keyboard_name + ":" + name) + cli.echo('%s:%s', cli.config.list_keymaps.keyboard, name) except NoSuchKeyboardError as e: - cli.echo("{fg_red}" + e.message) + cli.echo("{fg_red}%s: %s", cli.config.list_keymaps.keyboard, e.message) + except (FileNotFoundError, PermissionError) as e: + cli.echo("{fg_red}%s: %s", cli.config.list_keymaps.keyboard, e) diff --git a/lib/python/qmk/makefile.py b/lib/python/qmk/makefile.py index dc498adc8f..6ed6b4b702 100644 --- a/lib/python/qmk/makefile.py +++ b/lib/python/qmk/makefile.py @@ -21,8 +21,8 @@ def parse_rules_mk(file_path): # group(2) = operator (eg.: '=', '+=') # group(3) = value(s) rules_mk_regex = re.compile(r"^\s*(\w+)\s*([\?\:\+\-]?=)\s*(\S.*?)(?=\s*(\#|$))") - mk_content = qmk.path.unicode_lines(file_path) parsed_file = dict() + mk_content = qmk.path.file_lines(file_path) for line in mk_content: found = rules_mk_regex.search(line) if found: diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index e7e3ec53fa..0cdfe353c5 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py @@ -5,8 +5,6 @@ import os from qmk.errors import NoSuchKeyboardError -from bs4 import UnicodeDammit - def keymap(keyboard): """Locate the correct directory for storing a keymap. @@ -35,19 +33,14 @@ def normpath(path): return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path)) -def unicode_text(filename): - """Returns the contents of filename as a UTF-8 string. Tries to DTRT when it comes to encoding. - """ - with open(filename, "rb") as fd: - text = UnicodeDammit(fd.read()) - - if text.contains_replacement_characters: - log_warning("%s: Could not determine file encoding, some characters were replaced." % (filename,)) - - return text.unicode_markup or "" +def file_lines(filename): + """ Return a files content, line by line + Args: + filename: path to the file -def unicode_lines(filename): - """Returns the contents of filename as a UTF-8 string. Tries to DTRT when it comes to encoding. + Returns: + an list, in which each item is a line of the file """ - return unicode_text(filename).split("\n") + with open(filename, "r") as fd: + return fd.readlines() diff --git a/requirements.txt b/requirements.txt index bf4f411ede..074b11a8ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,3 @@ hjson nose2 flake8 pep8-naming -bs4 |