qmk_firmware/lib/python/qmk
Sergey Vlasov 7e27d72cbc
Fix qmk find failure due to circular imports (#22523)
There was an import cycle in the Python modules:

  - `qmk.build_targets` imported `qmk.cli.generate.compilation_database`;
  - importing `qmk.cli.generate.compilation_database` requires
    initializing `qmk.cli` first;
  - the initialization of `qmk.cli` imported the modules for all CLI
    commands;
  - `qmk.cli.compile` imported `qmk.build_targets`.

This cycle did not matter in most cases, because `qmk.cli` was imported
first, and in that case importing `qmk.cli.generate.compilation_database`
did not trigger the initialization of `qmk.cli` again.  However, there was
one corner case when `qmk.bulld_targets` was getting imported first:

  - The `qmk find` command uses the `multiprocessing` module.
  - The `multiprocessing` module uses the `spawn` start method on macOS
    and Windows.
  - When the `spawn` method is used, the child processes initialize
    without any Python modules loaded, and the required modules are loaded
    on demand by the `pickle` module when receiving the serialized objects
    from the main process.

The result was that the `qmk find` command did not work properly on macOS
(and probably Windows too); it reported exceptions like this:

    ImportError: cannot import name 'KeyboardKeymapBuildTarget' from partially initialized module 'qmk.build_targets' (most likely due to a circular import)

Moving the offending `qmk.cli.generate.compilation_database` import into
the method which actually uses it fixes the problem.
2023-11-21 15:05:29 +00:00
..
cli CLI refactoring for common build target APIs (#22221) 2023-11-15 16:24:54 +11:00
tests Update json2c to use dump_lines (#21013) 2023-05-22 07:03:59 +01:00
__init__.py
build_targets.py Fix qmk find failure due to circular imports (#22523) 2023-11-21 15:05:29 +00:00
c_parse.py Slightly refine g_led_config parsing (#21170) 2023-06-08 21:08:02 +01:00
commands.py CLI refactoring for common build target APIs (#22221) 2023-11-15 16:24:54 +11:00
comment_remover.py
constants.py Add qmk license-check developer-level CLI command. (#22075) 2023-11-11 20:50:33 +11:00
converter.py
datetime.py Generate api data on each push (#10609) 2020-10-25 14:48:44 -07:00
decorators.py CLI: Fix automagic (#13046) 2021-05-30 16:17:40 +01:00
errors.py CLI/c2json: Print 'cpp' error when executed in verbose mode (#12869) 2021-05-27 17:42:38 +01:00
flashers.py feat, docs: WB32 flashing (#21217) 2023-07-08 00:48:45 +10:00
git.py Add commit info to version.h (#19542) 2023-02-02 18:23:27 +00:00
importers.py qmk format-json: Expose full key path and respect sort_keys (#20836) 2023-05-20 22:15:05 +10:00
info.py Enable linking of encoders to switch within layout macros (#22264) 2023-11-20 15:41:48 +00:00
json_encoders.py qmk format-json: Expose full key path and respect sort_keys (#20836) 2023-05-20 22:15:05 +10:00
json_schema.py Reallocate user/kb keycode ranges (#19907) 2023-02-23 09:50:09 +11:00
keyboard.py Enable linking of encoders to switch within layout macros (#22264) 2023-11-20 15:41:48 +00:00
keycodes.py Reallocate user/kb keycode ranges (#19907) 2023-02-23 09:50:09 +11:00
keymap.py Improve argument handling of c2json (#22170) 2023-11-01 22:37:05 +00:00
makefile.py qmk find: usability improvements (#20440) 2023-05-20 22:14:43 +10:00
math.py
painter.py [Refactor] Python-ify QP's converter code (#20102) 2023-07-07 22:09:17 +10:00
painter_qff.py Quantum Painter (#10174) 2022-04-13 18:00:18 +10:00
painter_qgf.py [QP] Fix up delta frame boundaries (#20296) 2023-03-31 08:41:11 +11:00
path.py Improve argument handling of c2json (#22170) 2023-11-01 22:37:05 +00:00
search.py qmk find: Fix failure with multiple filters (#22497) 2023-11-19 08:26:00 +11:00
submodules.py Report submodule status when not valid work-tree (#19474) 2023-01-03 09:00:29 +11:00
util.py Allow for disabling of parallel processing of qmk find and qmk mass-compile. (#22160) 2023-10-17 09:43:50 +11:00