INTI-CMNB / KiBot

KiCad automation utility
GNU Affero General Public License v3.0
552 stars 65 forks source link

[BUG] Kibot doens't create it's own cache directory when needed #553

Closed oliv3r closed 8 months ago

oliv3r commented 8 months ago

Using the latest kibot 7 full dev container, i've created a test PCB with through-hole components, which triggers a cool kibot feature I wasn't aware of yet, create_colored_tht_resistor. The intermediate model is stored in the kibot cache directory. However, if this directory does not exist, we crash and burn.

This is nicely depicted in the following docker execution (Note, that I must run kicad-cli --version for a similar reason, otherwise the kicad homedir does not exist. Not the fault of kibot, or its container).

docker run --user 1000 --env HOME=/tmp --rm -it -v $(pwd):/workspace -w /workspace ghcr.io/inti-cmnb/kicad7_auto_full /bin/bash
I have no name!@3c5acab7ecdb:/workspace$ kicad-cli --version
7.0.9
I have no name!@3c5acab7ecdb:/workspace/hello$ kibot -W -w 9 -c .kibot/kicad_vrml.kibot.yaml 
Using SCH file: hello.kicad_sch
- 'PCB in VRML format' (vrml) [vrml]
Traceback (most recent call last):
  File "/usr/local/bin/kibot", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/kibot/__main__.py", line 534, in main
    generate_outputs(outputs, args.target, args.invert_sel, args.skip_pre, args.cli_order, args.no_priority,
  File "/usr/local/lib/python3.11/dist-packages/kibot/kiplot.py", line 595, in generate_outputs
    _generate_outputs(outputs, targets, invert, skip_pre, cli_order, no_priority, dont_stop)
  File "/usr/local/lib/python3.11/dist-packages/kibot/kiplot.py", line 585, in _generate_outputs
    run_output(out, dont_stop)
  File "/usr/local/lib/python3.11/dist-packages/kibot/kiplot.py", line 489, in run_output
    out.run(get_output_dir(out.dir, out))
  File "/usr/local/lib/python3.11/dist-packages/kibot/out_base.py", line 204, in run
    self.options.run(target)
  File "/usr/local/lib/python3.11/dist-packages/kibot/out_vrml.py", line 76, in run
    board_name = self.filter_components(highlight=set(self.expand_kf_components(self.highlight)), force_wrl=True)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/kibot/out_base_3d.py", line 559, in filter_components
    if self.download_models(force_wrl=force_wrl, all_comps=all_comps) or dnp_removed:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/kibot/out_base_3d.py", line 515, in download_models
    replace = self.do_colored_tht_resistor(full_name, sch_comp, used_extra)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/kibot/out_base_3d.py", line 435, in do_colored_tht_resistor
    self.create_colored_tht_resistor(name, cache_name, bars, r_len)
  File "/usr/local/lib/python3.11/dist-packages/kibot/out_base_3d.py", line 312, in create_colored_tht_resistor
    with open(name, "wt") as d:
         ^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/.cache/kibot/3d/R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal_1_0_2.wrl'
I have no name!@3c5acab7ecdb:/workspace/hello$ mkdir -p "${HOME}/.cache/kibot/3d/"
I have no name!@3c5acab7ecdb:/workspace/hello$ kibot -W -w 9 -c .kibot/kicad_vrml.kibot.yaml 
Using SCH file: hello.kicad_sch
- 'PCB in VRML format' (vrml) [vrml]
Found 0 unique warning/s (1 total, 1 filtered)
set-soft commented 8 months ago

Ok, the above patch creates the dir