[Package] Moved all resources to a central place

- All KiBot resources are now under kibot/resources
- PcbDraw resources are now in kibot/resources/pcbdraw
- All resources can be loaded relative to the script or from
  /usr/share/kibot
- The Debian package installs the resources in /usr/share/kibot
- The Python manifest includes all resources
- PcbDraw is now detected as a Python package
This commit is contained in:
Salvador E. Tropea 2022-10-19 13:05:56 -03:00
parent 5fe00f2598
commit 8ec4d481c0
91 changed files with 58 additions and 41 deletions

2
.gitmodules vendored
View File

@ -2,5 +2,5 @@
path = submodules/KiCost
url = https://github.com/hildogjr/KiCost.git
[submodule "kibot/PcbDraw/resources/footprints"]
path = kibot/PcbDraw/resources/footprints
path = kibot/resources/pcbdraw/footprints
url = https://github.com/yaqwsx/PcbDraw-Lib.git

View File

@ -1,10 +1,12 @@
include MANIFEST.in
include LICENSE
include README.md
include kibot/report_templates/*.txt
include kibot/kicad_colors/*.json
include kibot/kicad_layouts/*.kicad_wks
include kibot/config_templates/gerber/*.yaml
include kibot/config_templates/bom/*.yaml
include kibot/images/*.svg
include kibot/images/*.ico
include kibot/resources/report_templates/*.txt
include kibot/resources/kicad_colors/*.json
include kibot/resources/kicad_layouts/*.kicad_wks
include kibot/resources/config_templates/gerber/*.yaml
include kibot/resources/config_templates/bom/*.yaml
include kibot/resources/images/*.svg
include kibot/resources/images/*.ico
include kibot/resources/pcbdraw/styles/*.json
recursive-include kibot/resources/pcbdraw/footprints/ *.svg LICENCE *.md *.py *.pl *.png

6
debian/install vendored Normal file
View File

@ -0,0 +1,6 @@
kibot/resources/config_templates/ /usr/share/kibot/
kibot/resources/images/ /usr/share/kibot/
kibot/resources/kicad_colors/ /usr/share/kibot/
kibot/resources/kicad_layouts/ /usr/share/kibot/
kibot/resources/pcbdraw/ /usr/share/kibot/
kibot/resources/report_templates/ /usr/share/kibot/

11
debian/patches/001-Separate_data_files vendored Normal file
View File

@ -0,0 +1,11 @@
--- a/setup.py
+++ b/setup.py
@@ -21,7 +21,7 @@
scripts=['src/kibot-check'],
entry_points={'console_scripts': ['kibot=kibot.__main__:main', 'kiplot=kibot.__main__:main']},
install_requires=__pypi_deps__,
- include_package_data=True,
+ include_package_data=False,
classifiers=['Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',

View File

@ -1 +1,2 @@
# You must remove unused comment lines for the released package.
001-Separate_data_files

View File

@ -1,13 +1,13 @@
#!/usr/bin/make
all: ../README.md samples/generic_plot.kibot.yaml ../kibot/report_templates/report_full_svg.txt ../kibot/config_templates/bom/MacroFab_XYRS.kibot.yaml \
../kibot/config_templates/gerber/Elecrow.kibot.yaml ../kibot/config_templates/gerber/FusionPCB.kibot.yaml \
../kibot/config_templates/gerber/JLCPCB.kibot.yaml ../kibot/config_templates/gerber/PCBWay.kibot.yaml ../src/kibot-check
all: ../README.md samples/generic_plot.kibot.yaml ../kibot/resources/report_templates/report_full_svg.txt ../kibot/resources/config_templates/bom/MacroFab_XYRS.kibot.yaml \
../kibot/resources/config_templates/gerber/Elecrow.kibot.yaml ../kibot/resources/config_templates/gerber/FusionPCB.kibot.yaml \
../kibot/resources/config_templates/gerber/JLCPCB.kibot.yaml ../kibot/resources/config_templates/gerber/PCBWay.kibot.yaml ../src/kibot-check
../kibot/config_templates/gerber/%.kibot.yaml: samples/%.kibot.yaml
../kibot/resources/config_templates/gerber/%.kibot.yaml: samples/%.kibot.yaml
cp $< $@
../kibot/config_templates/bom/%.kibot.yaml: samples/%.kibot.yaml
../kibot/resources/config_templates/bom/%.kibot.yaml: samples/%.kibot.yaml
cp $< $@
../README.md: README.in replace_tags.pl ../kibot/out_*.py ../kibot/pre_*.py ../kibot/var_*.py ../kibot/fil_*.py ../kibot/__main__.py ../kibot/config_reader.py ../kibot/globals.py ../kibot/dep_downloader.py
@ -21,5 +21,5 @@ samples/generic_plot.kibot.yaml: ../kibot/out_*.py ../kibot/pre_*.py ../kibot/co
../src/kibot -v --example
mv example_template.kibot.yaml $@
../kibot/report_templates/report_full_svg.txt: ../kibot/report_templates/report_full.txt
../kibot/resources/report_templates/report_full_svg.txt: ../kibot/resources/report_templates/report_full.txt
sed -e 's/layer_pdfs/layer_svgs/' $< > $@

View File

View File

@ -15,7 +15,7 @@ except ImportError:
from datetime import datetime, date
from sys import exit
from shutil import copy2
from .misc import EXIT_BAD_ARGS, W_DATEFORMAT, W_UNKVAR
from .misc import EXIT_BAD_ARGS, W_DATEFORMAT, W_UNKVAR, WRONG_INSTALL
from .log import get_logger
logger = get_logger(__name__)
@ -408,3 +408,16 @@ class GS(object):
def check_tool(context, name):
""" Looks for a dependency """
return GS.check_tool_dep(context, name, fatal=False)
@staticmethod
def get_resource_path(name):
# Try relative to the script
dir_name = os.path.join(os.path.dirname(__file__), 'resources', name)
if os.path.isdir(dir_name):
return dir_name
# Try using the system level path
dir_name = os.path.join('usr', 'share', 'kibot', name)
if os.path.isdir(dir_name):
return dir_name
logger.error('Missing resource directory `{}`'.format(name))
exit(WRONG_INSTALL)

View File

@ -63,7 +63,7 @@ def load_color_theme(name):
logger.warning(W_COLORTHEME, "KiCad 5 doesn't support color themes ({})".format(name))
return None
if is_built_in:
fn = os.path.join(os.path.dirname(__file__), '..', 'kicad_colors', name+'.json')
fn = os.path.join(GS.get_resource_path('kicad_colors'), name+'.json')
else:
KiConf.init(GS.pcb_file)
fn = os.path.join(KiConf.config_dir, 'colors', name+'.json')

View File

@ -873,7 +873,7 @@ def generate_one_example(dest_dir, types):
logger.debug('- {}, skipped (PCB: {} SCH: {})'.format(n, o.is_pcb(), o.is_sch()))
continue
# Look for templates
tpls = glob(os.path.join(os.path.dirname(__file__), 'config_templates', n, '*.kibot.yaml'))
tpls = glob(os.path.join(GS.get_resource_path('config_templates'), n, '*.kibot.yaml'))
if tpls:
# Load the templates
tpl_names = tpls

View File

@ -189,7 +189,7 @@ class Navigate_ResultsOptions(BaseOptions):
if img_w in self.copied_images:
# Already copied, just return its name
return self.copied_images[img_w]
src = os.path.join(self.img_src_dir, 'images', img+'.svg')
src = os.path.join(self.img_src_dir, img+'.svg')
dst = os.path.join(self.out_dir, 'images', img_w)
id = img_w
if self.rsvg_command is not None and self.svg_to_png(src, dst+'.png', width):
@ -428,7 +428,7 @@ class Navigate_ResultsOptions(BaseOptions):
def run(self, name):
self.out_dir = os.path.dirname(name)
self.img_src_dir = os.path.dirname(__file__)
self.img_src_dir = GS.get_resource_path('images')
self.img_dst_dir = os.path.join(self.out_dir, 'images')
os.makedirs(self.img_dst_dir, exist_ok=True)
self.copied_images = {}
@ -454,7 +454,7 @@ class Navigate_ResultsOptions(BaseOptions):
self.home = name
self.back_img = self.copy('back', MID_ICON)
self.home_img = self.copy('home', MID_ICON)
copy2(os.path.join(self.img_src_dir, 'images', 'favicon.ico'), os.path.join(self.out_dir, 'favicon.ico'))
copy2(os.path.join(self.img_src_dir, 'favicon.ico'), os.path.join(self.out_dir, 'favicon.ico'))
self.generate_page_for(o_tree, name)
# Link it?
if self.link_from_root:

View File

@ -770,22 +770,10 @@ class PCB_PrintOptions(VariantOptions):
# Run PcbDraw to make the heavy work (find the Edge.Cuts path and create masks)
try:
plotter = PcbPlotter(GS.board)
# TODO: Review the paths, most probably add the system KiBot dir
# Read libs from current dir
# plotter.setup_arbitrary_data_path(".")
# Libs indicated by PCBDRAW_LIB_PATH
plotter.setup_env_data_path()
# Libs from resources relative to the script
plotter.setup_builtin_data_path()
# Libs from the user HOME and the system
plotter.setup_global_data_path()
plotter.yield_warning = pcbdraw_warnings
plotter.render_back = back
plotter.plot_plan = [PlotSubstrate(only_mask=True)]
image = plotter.plot()
# Most errors are reported as RuntimeError
# When the PCB can't be loaded we get IOError
# When the SVG contains errors we get SyntaxError
except (RuntimeError, SyntaxError, IOError) as e:
logger.error('PcbDraw error: '+str(e))
exit(PCBDRAW_ERR)
@ -975,7 +963,7 @@ class PCB_PrintOptions(VariantOptions):
# Find the layout file
layout = KiConf.fix_page_layout(GS.pro_file, dry=True)[1]
if not layout or not os.path.isfile(layout):
layout = os.path.abspath(os.path.join(os.path.dirname(__file__), 'kicad_layouts', 'default.kicad_wks'))
layout = os.path.abspath(os.path.join(GS.get_resource_path('kicad_layouts'), 'default.kicad_wks'))
logger.debug('- Using layout: '+layout)
self.layout = layout
# Plot options

View File

@ -3,7 +3,6 @@
# Copyright (c) 2020-2022 Instituto Nacional de Tecnología Industrial
# License: GPL-3.0
# Project: KiBot (formerly KiPlot)
# TODO: Package resources
"""
Dependencies:
- from: RSVG
@ -411,14 +410,11 @@ class PcbDrawOptions(VariantOptions):
try:
plotter = PcbPlotter(GS.board)
# TODO: Review the paths, most probably add the system KiBot dir
# Read libs from current dir
# plotter.setup_arbitrary_data_path(".")
# Read libs from KiBot resources
plotter.setup_arbitrary_data_path(GS.get_resource_path('pcbdraw'))
# Libs indicated by PCBDRAW_LIB_PATH
plotter.setup_env_data_path()
# Libs from resources relative to the script
plotter.setup_builtin_data_path()
# Libs from the user HOME and the system
# Libs from the user HOME and the system (for pcbdraw)
plotter.setup_global_data_path()
plotter.yield_warning = pcbdraw_warnings
plotter.libs = self.libs

View File

@ -222,7 +222,7 @@ class ReportOptions(BaseOptions):
self.template = self.template[:-6]
self.to_ascii = True
if self.template.lower() in ('full', 'simple', 'full_svg'):
self.template = os.path.abspath(os.path.join(os.path.dirname(__file__), 'report_templates',
self.template = os.path.abspath(os.path.join(GS.get_resource_path('report_templates'),
'report_'+self.template.lower()+'.txt'))
if not os.path.isabs(self.template):
self.template = os.path.expandvars(os.path.expanduser(self.template))

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB