Commit Graph

52 Commits

Author SHA1 Message Date
skullydazed
74bcafa2de Use pathlib everywhere we can (#7872)
* Use pathlib everywhere we can

* Update lib/python/qmk/path.py

Co-Authored-By: Erovia <Erovia@users.noreply.github.com>

* Update lib/python/qmk/path.py

Co-Authored-By: Erovia <Erovia@users.noreply.github.com>

* Improvements based on @erovia's feedback

* rework qmk compile and qmk flash to use pathlib

* style

* Remove the subcommand_name argument from find_keyboard_keymap()

Co-authored-by: Erovia <Erovia@users.noreply.github.com>
2020-06-12 17:00:27 +09:00
Mikkel Jeppesen
e28b21794f Fix os detection in OSX python 3.8 (#8187)
* Fix os detection in osx python 3.8

* oops
2020-06-12 17:00:27 +09:00
Erovia
1b04d564e2 CLI: add support for list_keymaps
List all the available keymaps for a given keyboard

Add bs4 to requirements.txt

UnicodeDammit is needed from bs4 for reading files.

Major update to work better with revisions

Find the community keymaps supported by each revision.

Get all buildable keymaps for each revision

The command now return all keymaps that's buildable for a
keyboard/revision. If the base directory of a keyboard does not contain
a 'rules.mk' file, nothing is returned. If the base directory contains a
'keymaps' directory, those keycaps will be returned for every revision.

Fix help message.

Try to figure out revision, drop -rv/--revision argument

Fix output format

Another major refactoring, add documentation

Move all useful functions to the qmk module and use the cli subcommand
as a wrapper around it.
Add both inline comments and documentation.

Add test for list_keymaps

Fix regex for parsing rules.mk files

I don't know why it couldn't put it together before... ¯\_(ツ)_/¯

Drop bs4 dependency, update docs, minor improvements

Return only the unique keymaps

Fix merging community and base keymaps

Major rework, no regex/globbing, more walking

Instead of using regexes and globbing to find the rules.mk and keymap.c
files, walk the directory tree to find them.
Also, do away with the concept of revision.

Fix commandline parsing and flake8 findings, rebase

Fixed commandline and config parsing. Thx @xplusplus.
Rebased on master and fixed merge conflicts.

Code cleanup, use pathlib, use pytest keyboard

Clean up checks and logics that are unnecessary due to MILC updates.
Use pathlib instead of os.path for readability.
Use the 'pytest' keyboard for the tests.
Add community layout for 'handwired/onekey/pytest' so we can test
community layouts.

Pathlib-ify qmk.keymap.list_keymaps()

fix list_keymaps for python 3.5
2020-06-12 17:00:27 +09:00
Mikkel Jeppesen
f713abefb9 Fixed OS detection such that OSX doesn't take over the world (#8248) 2020-03-26 00:42:13 -07:00
Akaash Suresh
f4b460c200 New functionality for cformat (#7893)
Fixing complexity

remove lambda

PR review fixes #1

Removing unneccesary string substitution

Handle -a and specified files

Complexity rewrite, use pathlib
2020-03-26 00:42:13 -07:00
skullydazed
72b85f52e7 Use pathlib everywhere we can (#7872)
* Use pathlib everywhere we can

* Update lib/python/qmk/path.py

Co-Authored-By: Erovia <Erovia@users.noreply.github.com>

* Update lib/python/qmk/path.py

Co-Authored-By: Erovia <Erovia@users.noreply.github.com>

* Improvements based on @erovia's feedback

* rework qmk compile and qmk flash to use pathlib

* style

* Remove the subcommand_name argument from find_keyboard_keymap()

Co-authored-by: Erovia <Erovia@users.noreply.github.com>
2020-03-26 00:42:12 -07:00
Mikkel Jeppesen
91d34ed5b7 Fix os detection in OSX python 3.8 (#8187)
* Fix os detection in osx python 3.8

* oops
2020-03-26 00:42:11 -07:00
Erovia
4c3335b00b CLI: add support for list_keymaps
List all the available keymaps for a given keyboard

Add bs4 to requirements.txt

UnicodeDammit is needed from bs4 for reading files.

Major update to work better with revisions

Find the community keymaps supported by each revision.

Get all buildable keymaps for each revision

The command now return all keymaps that's buildable for a
keyboard/revision. If the base directory of a keyboard does not contain
a 'rules.mk' file, nothing is returned. If the base directory contains a
'keymaps' directory, those keycaps will be returned for every revision.

Fix help message.

Try to figure out revision, drop -rv/--revision argument

Fix output format

Another major refactoring, add documentation

Move all useful functions to the qmk module and use the cli subcommand
as a wrapper around it.
Add both inline comments and documentation.

Add test for list_keymaps

Fix regex for parsing rules.mk files

I don't know why it couldn't put it together before... ¯\_(ツ)_/¯

Drop bs4 dependency, update docs, minor improvements

Return only the unique keymaps

Fix merging community and base keymaps

Major rework, no regex/globbing, more walking

Instead of using regexes and globbing to find the rules.mk and keymap.c
files, walk the directory tree to find them.
Also, do away with the concept of revision.

Fix commandline parsing and flake8 findings, rebase

Fixed commandline and config parsing. Thx @xplusplus.
Rebased on master and fixed merge conflicts.

Code cleanup, use pathlib, use pytest keyboard

Clean up checks and logics that are unnecessary due to MILC updates.
Use pathlib instead of os.path for readability.
Use the 'pytest' keyboard for the tests.
Add community layout for 'handwired/onekey/pytest' so we can test
community layouts.

Pathlib-ify qmk.keymap.list_keymaps()

fix list_keymaps for python 3.5
2020-03-26 00:42:11 -07:00
Mikkel Jeppesen
c9d18bc22e use replace() over rename() to have cross-platform overwriting (#8148) 2020-03-26 00:42:10 -07:00
Joel Challis
f7dbbf006a CI: Add workflow for CLI testing (#7357)
Create GitHub Actions cli test workflow and remove travis runs of 'qmk pytest'
2020-02-26 10:15:12 +09:00
Cody Bender
ce9397836b Add QMK Compile Context Sensitivity (#6884)
* Add context sensitive compile, without config check

* Initial full working state. Plan to refactor

* Refactor loop for simplicity, add comments

* Update docs/cli.md with qmk compile examples

* Simplify path for keyboard derivation

* Update path to use path.join instead of concat

* Refactor keyboard path, the skully way

* Add in keymap folder support

* Add /layouts compile support

* Update docs/cli.md with empty compile in layouts

* Add comments to compile.py

* Update docs for clarity, and fix compile error typo

* Fix config option compile

* Fix layout compile and failure mode

* Add rules.mk check

* Fix variable names for global config

* Add in_layout priority

* Remove default fallback in favor of throw, update docs

* Add keymap folder context

* Fix formatting

* Add os import

* Convert to create_make_command

* Fix Travis lint errors

* Remove blank line with whitespace

* Add blank lines for readability

* Remove unnecessary config logic

* Update Docs to add flash

Co-Authored-By: skullydazed <skullydazed@users.noreply.github.com>

* Shift config precedence to MILC

Co-authored-by: skullydazed <skullydazed@users.noreply.github.com>
2020-02-26 10:15:12 +09:00
skullydazed
1d05d8ba6a Improve the functionality of qmk.questions (#8020)
* wip

* tested and working

* remove unused import

* Update lib/python/qmk/questions.py

Co-Authored-By: Erovia <Erovia@users.noreply.github.com>

* fix flake8 errors

Co-authored-by: Erovia <Erovia@users.noreply.github.com>
2020-02-26 10:15:12 +09:00
Joel Challis
0ca620a7f6 Fix cformat processing files within ignore folders (#8063) 2020-02-26 10:15:12 +09:00
Mikkel Jeppesen
b1f101030b Qmk doctor os check to support newer msys2/w10 installations (#8031)
* Fixed OS detection on newer MSYS installations

* made OS sting lower case
2020-02-26 10:15:12 +09:00
skullydazed
41b518c55f Beef up how qmk doctor works. (#7375)
* Beef up how `qmk doctor` works.

* improve the `git submodule status` parsing. h/t @erovia

* Fix whitespace and imports

* yapf

* Add documentation for the new doctor functionality

* Replace type_unchanged() with str()

* remove unused modules

* Update lib/python/qmk/cli/doctor.py

Co-Authored-By: Erovia <Erovia@users.noreply.github.com>

Co-authored-by: Erovia <Erovia@users.noreply.github.com>
2020-02-26 10:15:12 +09:00
Joel Challis
72c5e4958c Align cformat rules with current CI implementation (#7936)
* Align cformat rules with current CI implementation

* Optimise file walking
2020-02-26 10:15:12 +09:00
Erovia
97038602f5 Fix attribute heritance for long commands.
This is needed for inheritance to work with commands that have dashes in
their names.
2020-02-26 10:15:12 +09:00
Erovia
6a5afb67fd Fix commandline arg merging, small improvements
Commandline args should be merged with the submodule's config.
Compare config values to None instead of False, so empty lines and False
can be used as values.
2020-02-26 10:15:12 +09:00
Erovia
bbcc605195 MILC: Fix/complete attribute heritance
If an undefined attribute of a submodule is accessed, fall back to
same attribute of the submodule's parent.
2020-02-26 10:15:12 +09:00
skullY
06e5032ad3 yapf and style 2020-02-26 10:15:12 +09:00
Erovia
dc05100c4c Make the udev rules easier to read and manage 2020-02-26 10:15:12 +09:00
Erovia
d37042f31c Fix Pro Micro's and its bootloader's name 2020-02-26 10:15:12 +09:00
Erovia
dac9a94d17 CLI: Rework ModemManager check and add udev check 2020-02-26 10:15:12 +09:00
skullY
0f1f9ba155 Add pep8-naming to our python linting 2020-01-09 08:57:11 +09:00
Erovia
ac75812e50 MILC: Add support for hidden subcommands (#7034)
* MILC: Add support for hidden subcommands

Subcommands with 'hidden=True' will not show up in the help output, but
will work as any other subcommands.

* Hide those hidden submodules, for real now

* Rebase on latest MILC
2020-01-09 08:57:11 +09:00
skullydazed
dfa3631a44 Add flake8 to our test suite and fix all errors (#7379)
* Add flake8 to our test suite and fix all errors

* Add some documentation
2020-01-09 08:57:11 +09:00
skullydazed
4dc4b7af75 Improve a number of things about how MILC operates (#7344)
* Pull in updates for MILC

* Remove the shadow argparser
* Make it easier to reason about arguments and how they're translated into the config tree
* Populate self.config during init to support setting user.qmk_home for the global CLI
* Remove the short argument -c so that we can unambiguously determine the config file location without doing full argument processing
* Remove the --save-config option as it's a little confusing anyway
* Use Pathlib for path manipulation

* Fix commands with no arguments
2020-01-09 08:57:11 +09:00
QMK Bot
6f57ecc58e format code according to conventions [skip ci] 2020-01-09 08:57:11 +09:00
jorgemanzo
d459da0c95 Add CLI command for flashing a keyboard
A new CLI subcommand was added, flash, which behaves very similar to the already present compile CLI comamnd, but with the added ability to target a bootloader. The command is used like so: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename].

A -kb <keyboard> and -km <keymap> is expected, or a configurator export JSON filename. A bootloader can be specified using -bl <target>, and if left unspecified, the target is assumed to be :flash. -bl can be used to list the available bootloaders.

If -km <keymap> is provided, but no -kb <keyboard>, then a message is printed suggesting the user to run qmk list_keyboards.
2020-01-09 08:57:11 +09:00
QMK Bot
22891f9c83 format code according to conventions [skip ci] 2020-01-09 08:57:11 +09:00
Cody Bender
31608fe2a9 Add cli convert subcommand, from raw KLE to JSON (#6898)
* Add initial pass at KLE convert

* Add cli log on convert

* Move kle2xy, add absolute filepath arg support

* Add overwrite flag, and context sensitive conversion

* Update docs/cli.md

* Fix converter.py typo

* Add convert unit test

* Rename to kle2qmk

* Rename subcommand

* Rename subcommand to kle2json

* Change tests to cover rename

* Rename in __init__.py

* Update CLI docs with new subcommand name

* Fix from suggestions in PR #6898

* Help with cases of case sensitivity

* Update cli.md

* Use angle brackets to indicate required option

* Make the output text more accurate
2020-01-09 08:57:11 +09:00
skullY
853394f8e1 Make generating keymap.c from JSON more reliable 2020-01-09 08:57:11 +09:00
skullY
8d35ebab7f Small CLI cleanups
* yapf changes
* Fix the cformat test
* Make the normpath test work when run from /
* `qmk config`: Mark `--read-only` as arg_only
2020-01-09 08:57:11 +09:00
skullY
55b2c4c1ed When checking program returncodes treat both 0 and 1 as installed 2020-01-09 08:57:11 +09:00
skullY
06a8a3c0d3 Add support for newer versions of clang-format, if installed 2020-01-09 08:57:11 +09:00
Erovia
e3e2489f86 MILC: Use dashes instead of underscores for subcommands
The subcommand functions' name follows the Python convention of using
snake case, but looks odd on the command line.
Fix it by converting underscores to dashes, eg.: list_keyboards ->
list-keyboards.
2019-11-04 16:51:03 +09:00
Harry Wada
415ab3c96c Fix detection of ModemManager (#7076) 2019-11-04 16:51:03 +09:00
Dan McClain
be4771380f [CLI] Add qmk list_keyboards (#6927)
`list_keyboards` replicates the `make list-keyboards` by globbing for all paths
that include `rules.mk` and then removing the paths that include `keymaps`.

This basis of this cli command could be reused in the future as a util, but is
not done so here since this would be the only place that would use it currently

Resolves #6911
2019-11-04 16:51:03 +09:00
St. John Johnson
56dd8cfe48 Use keymap instead of username variable for qmk new_keymap (#6885)
Username is not defined and this causes `qmk new_keymap` to error.  This
appears to have originated from a partial update in
https://github.com/qmk/qmk_firmware/pull/6708/files#diff-d5208bcbc79aa428556a743b6ff41086.  This change completes the migration from `username` to `keymap`
2019-11-04 16:51:03 +09:00
Ayman Bagabas
74d3820ff4 Fix qmk doctor 'bytes-like object is required' on linux
This fixes the following issue related to encoding on linux systems. Add
`universal_newlines=True` to subprocess.

<class 'TypeError'>
☒ a bytes-like object is required, not 'str'
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/milc.py", line 564, in __call__
    return self.__call__()
  File "/usr/local/lib/python3.7/site-packages/milc.py", line 569, in __call__
    return self._entrypoint(self)
  File "$HOME/qmk_firmware/lib/python/qmk/cli/doctor.py", line 56, in doctor
    for line in mm_check.stdout.split('\n'):
TypeError: a bytes-like object is required, not 'str'
2019-11-04 16:51:03 +09:00
skullydazed
3f2ea83234 Configuration system for CLI (#6708)
* Rework how bin/qmk handles subcommands

* qmk config wip

* Code to show all configs

* Fully working `qmk config` command

* Mark some CLI arguments so they don't pollute the config file

* Fleshed out config support, nicer subcommand support

* sync with installable cli

* pyformat

* Add a test for subcommand_modules

* Documentation for the `qmk config` command

* split config_token on space so qmk config is more predictable

* Rework how subcommands are imported

* Document `arg_only`

* Document deleting from CLI

* Document how multiple operations work

* Add cli config to the doc index

* Add tests for the cli commands

* Make running the tests more reliable

* Be more selective about building all default keymaps

* Update new-keymap to fit the new subcommand style

* Add documentation about writing CLI scripts

* Document new-keyboard

* Update docs/cli_configuration.md

Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>

* Update docs/cli_development.md

Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>

* Update docs/cli_development.md

Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>

* Update docs/cli_development.md

Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com>

* Address yan's comments.

* Apply suggestions from code review

suggestions from @noahfrederick

Co-Authored-By: Noah Frederick <code@noahfrederick.com>

* Apply suggestions from code review

Co-Authored-By: Noah Frederick <code@noahfrederick.com>

* Remove pip3 from the test runner
2019-11-04 16:51:03 +09:00
Kenny Hoang
5ad8d221c8 Created new_keymap.py, python version of new_keymap.sh (#6066)
* Created python version of new_keymap.sh: new_keymap.py

* Updated usage message

* Updated new_keymap.py to use python3.5+ syntax & be more similar to new_keyboard.sh

* Updated complete message

* Updated usage in argparser and removed incorrect usage_message

* Reverted the fstrings back to strings that use .format() & updated docstring convention

* Added helper to recursively cd .. until at qmk_firmware root directory

* Revert "Added helper to recursively cd .. until at qmk_firmware root directory"

This reverts commit 61a0ff3b25f91901287bec8d58eb51a1f126e2ad.

* Updated new_keymap.py to use printf-style format strings

* First draft lib/python/qmk/cli/new/keymap.py with milc

* Removed shebang & syspath appending lines

* Added optional args & resolved some cr comemnts

* Added a docstring and updated strings
2019-09-26 10:08:39 +09:00
skullY
74d97c7c1d Add a command to format python code 2019-09-26 10:08:39 +09:00
skullY
6d891bfae9 Make the modem manager check more pythonic 2019-09-26 10:08:39 +09:00
skullY
3cb9a24bff run yapf on the code 2019-09-26 10:08:39 +09:00
skullY
50f3d2556d Setup a python test framework 2019-09-26 10:08:39 +09:00
skullY
128bde1be1 readability enhancements 2019-09-26 10:08:39 +09:00
skullY
ffca0ecd0a Add support for passing files at the command line 2019-09-26 10:08:39 +09:00
skullY
56443ee486 CLI command to format C code 2019-09-26 10:08:39 +09:00
skullydazed
ca5162b90e Refactor qmk compile-json to qmk compile (#6592) 2019-08-28 14:55:37 +09:00