On 2020/04/01 11:28, Tracey Emery wrote:
> Hello,
> 
> The following diff adds python scripting support to kicad. It contains a
> couple of new patches and an update to an old one.
> 
> Builds and runs fine on amd64.
> 
> OK?
> 
> -- 
> 
> Tracey Emery
> 
> Index: cad/kicad/Makefile
> ===================================================================
> RCS file: /cvs/ports/cad/kicad/Makefile,v
> retrieving revision 1.39
> diff -u -p -r1.39 Makefile
> --- cad/kicad/Makefile        28 Dec 2019 15:53:54 -0000      1.39
> +++ cad/kicad/Makefile        1 Apr 2020 17:24:52 -0000
> @@ -4,6 +4,7 @@ V =                   5.1.5
>  COMMENT =            schematic and PCB editing software
>  DISTNAME =           kicad-${V}
>  EPOCH =                      0
> +REVISION =           0
>  
>  SHARED_LIBS +=               kicad_3dsg                0.0 # 2.0
>  
> @@ -22,10 +23,10 @@ WANTLIB += TKSTEP TKSTEP209 TKSTEPAttr T
>  WANTLIB += TKTopAlgo TKV3d TKXCAF TKXDEIGES TKXDESTEP TKXSBase
>  WANTLIB += TKernel X11 Xext boost_atomic-mt boost_chrono-mt boost_context-mt
>  WANTLIB += boost_date_time-mt boost_system-mt boost_thread-mt
> -WANTLIB += c cairo crypto curl freetype m ngspice pixman-1 ssl
> -WANTLIB += wx_baseu-3.0 wx_baseu_net-3.0 wx_baseu_xml-3.0 wx_gtk3u_adv-3.0
> -WANTLIB += wx_gtk3u_aui-3.0 wx_gtk3u_core-3.0 wx_gtk3u_gl-3.0
> -WANTLIB += wx_gtk3u_html-3.0 wx_gtk3u_stc-3.0
> +WANTLIB += c cairo crypto curl freetype m ngspice pixman-1 python3.7m

This should use ${MODPY_WANTLIB}.

> +WANTLIB += ssl wx_baseu-3.0 wx_baseu_net-3.0 wx_baseu_xml-3.0
> +WANTLIB += wx_gtk3u_adv-3.0 wx_gtk3u_aui-3.0 wx_gtk3u_core-3.0
> +WANTLIB += wx_gtk3u_gl-3.0 wx_gtk3u_html-3.0 wx_gtk3u_stc-3.0
>  
>  MASTER_SITES =               https://launchpad.net/kicad/5.0/${V}/+download/
>  
> @@ -33,6 +34,8 @@ EXTRACT_SUFX =              .tar.xz
>  
>  COMPILER =           base-clang ports-gcc
>  
> +MODPY_VERSION = ${MODPY_DEFAULT_VERSION_3}
> +
>  MODULES =            devel/cmake \
>                       lang/python
>  
> @@ -66,7 +69,8 @@ CONFIGURE_ARGS +=   -DCMAKE_BUILD_TYPE=Rel
>                       -DwxWidgets_LIBRARIES="${LOCALBASE}/lib" \
>                       -DwxWidgets_INCLUDE_DIRS="${LOCALBASE}/include/wx-3.0" \
>                       -DOCE_DIR="${LOCALBASE}/include/oce" \
> -                     -DKICAD_SCRIPTING=OFF
> +                     -DKICAD_SCRIPTING_PYTHON3=ON \
> +                     -DKICAD_SCRIPTING_WXPYTHON=OFF
>  
>  NO_TEST =            Yes
>  
> @@ -74,6 +78,10 @@ post-install:
>       ${MODPY_BIN} ${MODPY_LIBDIR}/compileall.py \
>               ${PREFIX}/share/kicad/demos/python_scripts_examples/
>       ${MODPY_BIN} ${MODPY_LIBDIR}/compileall.py \
> +             ${PREFIX}/lib/python3.7/site-packages/

And whatever the variable is for this, check python.port.mk.


> +     ${MODPY_BIN} ${MODPY_LIBDIR}/compileall.py \
>               ${PREFIX}/share/kicad/plugins/
> +     ${MODPY_BIN} ${MODPY_LIBDIR}/compileall.py \
> +             ${PREFIX}/share/kicad/scripting/plugins/
>  
>  .include <bsd.port.mk>
> Index: 
> cad/kicad/patches/patch-demos_python_scripts_examples_gen_gerber_and_drill_files_board_py
> ===================================================================
> RCS file: 
> cad/kicad/patches/patch-demos_python_scripts_examples_gen_gerber_and_drill_files_board_py
> diff -N 
> cad/kicad/patches/patch-demos_python_scripts_examples_gen_gerber_and_drill_files_board_py
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ 
> cad/kicad/patches/patch-demos_python_scripts_examples_gen_gerber_and_drill_files_board_py
>  1 Apr 2020 17:24:52 -0000
> @@ -0,0 +1,53 @@
> +$OpenBSD$
> +
> +Index: demos/python_scripts_examples/gen_gerber_and_drill_files_board.py
> +--- demos/python_scripts_examples/gen_gerber_and_drill_files_board.py.orig
> ++++ demos/python_scripts_examples/gen_gerber_and_drill_files_board.py
> +@@ -92,11 +92,11 @@ for layer_info in plot_plan:
> + 
> +     pctl.SetLayer(layer_info[1])
> +     pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_GERBER, layer_info[2])
> +-    print 'plot %s' % pctl.GetPlotFileName()
> ++    print('plot %s' % pctl.GetPlotFileName());
> +     if gen_job_file == True:
> +         jobfile_writer.AddGbrFile( layer_info[1], 
> os.path.basename(pctl.GetPlotFileName()) );
> +     if pctl.PlotLayer() == False:
> +-        print "plot error"
> ++        print("plot error");
> + 
> + #generate internal copper layers, if any
> + lyrcnt = board.GetCopperLayerCount();
> +@@ -106,9 +106,9 @@ for innerlyr in range ( 1, lyrcnt-1 ):
> +     pctl.SetLayer(innerlyr)
> +     lyrname = 'inner%s' % innerlyr
> +     pctl.OpenPlotfile(lyrname, PLOT_FORMAT_GERBER, "inner")
> +-    print 'plot %s' % pctl.GetPlotFileName()
> ++    print('plot %s' % pctl.GetPlotFileName());
> +     if pctl.PlotLayer() == False:
> +-        print "plot error"
> ++        print("plot error");
> + 
> + 
> + # At the end you have to close the last plot, otherwise you don't know when
> +@@ -133,18 +133,18 @@ drlwriter.SetFormat( metricFmt )
> + 
> + genDrl = True
> + genMap = True
> +-print 'create drill and map files in %s' % pctl.GetPlotDirName()
> ++print('create drill and map files in %s' % pctl.GetPlotDirName());
> + drlwriter.CreateDrillandMapFilesSet( pctl.GetPlotDirName(), genDrl, genMap 
> );
> + 
> + # One can create a text file to report drill statistics
> + rptfn = pctl.GetPlotDirName() + 'drill_report.rpt'
> +-print 'report: %s' % rptfn
> ++print('report: %s' % rptfn);
> + drlwriter.GenDrillReportFile( rptfn );
> + 
> + if gen_job_file == True:
> +     #job_fn=os.path.splitext(pctl.GetPlotFileName())[0] + '.gbrjob'
> +     job_fn=os.path.dirname(pctl.GetPlotFileName()) + '/' + 
> os.path.basename(filename)
> +     job_fn=os.path.splitext(job_fn)[0] + '.gbrjob'
> +-    print 'create job file %s' % job_fn
> ++    print('create job file %s' % job_fn);
> +     jobfile_writer.CreateJobFile( job_fn )
> + 
> Index: cad/kicad/patches/patch-demos_python_scripts_examples_plot_board_py
> ===================================================================
> RCS file: cad/kicad/patches/patch-demos_python_scripts_examples_plot_board_py
> diff -N cad/kicad/patches/patch-demos_python_scripts_examples_plot_board_py
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ cad/kicad/patches/patch-demos_python_scripts_examples_plot_board_py       
> 1 Apr 2020 17:24:52 -0000
> @@ -0,0 +1,14 @@
> +$OpenBSD$
> +
> +Index: demos/python_scripts_examples/plot_board.py
> +--- demos/python_scripts_examples/plot_board.py.orig
> ++++ demos/python_scripts_examples/plot_board.py
> +@@ -72,7 +72,7 @@ plot_plan = [
> + for layer_info in plot_plan:
> +     pctl.SetLayer(layer_info[1])
> +     pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_GERBER, layer_info[2])
> +-    print layer_info[0]
> ++    print(layer_info[0]);
> +     pctl.PlotLayer()
> + 
> + # Our fabricators want two additional gerbers:
> Index: cad/kicad/patches/patch-pcbnew_CMakeLists_txt
> ===================================================================
> RCS file: /cvs/ports/cad/kicad/patches/patch-pcbnew_CMakeLists_txt,v
> retrieving revision 1.2
> diff -u -p -r1.2 patch-pcbnew_CMakeLists_txt
> --- cad/kicad/patches/patch-pcbnew_CMakeLists_txt     8 Nov 2019 14:43:53 
> -0000       1.2
> +++ cad/kicad/patches/patch-pcbnew_CMakeLists_txt     1 Apr 2020 17:24:52 
> -0000
> @@ -12,3 +12,45 @@ Index: pcbnew/CMakeLists.txt
>   endif()
>   
>   
> +@@ -808,11 +808,7 @@ if( KICAD_SCRIPTING_MODULES )
> +         add_dependencies( ScriptingModulesPcbnewSoCopy 
> ScriptingWxpythonCopy )
> +         set( PYMOD_EXT "so" )
> +     else()  # only linux remains among supported platforms
> +-        add_library( pcbnew_python MODULE 
> $<TARGET_OBJECTS:pcbnew_kiface_objects> )
> +-        target_link_libraries( pcbnew_python ${PCBNEW_KIFACE_LIBRARIES} )
> +-        set_target_properties( pcbnew_python PROPERTIES OUTPUT_NAME pcbnew 
> PREFIX "_" SUFFIX ".so" )
> +-        install( TARGETS pcbnew_python DESTINATION ${PYTHON_DEST} COMPONENT 
> binary )
> +-
> ++        install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libpcbnew.a DESTINATION 
> ${PYTHON_DEST} COMPONENT binary RENAME "_pcbnew.so" )
> +         set( PYMOD_EXT "so" )
> +     endif()
> + 
> +@@ -827,18 +823,16 @@ if( KICAD_SCRIPTING_MODULES )
> +             DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_pcbnew.${PYMOD_EXT}
> +             )
> +     else()
> +-
> +-
> +-    # For phase 1, copy _pcbnew.kiface to the python module.
> +-    add_custom_command( OUTPUT 
> ${CMAKE_CURRENT_BINARY_DIR}/_pcbnew.${PYMOD_EXT}
> +-        DEPENDS pcbnew_kiface
> +-        COMMAND ${CMAKE_COMMAND} -E copy _pcbnew.kiface _pcbnew.${PYMOD_EXT}
> +-        COMMENT "Creating python's pcbnew native module 
> _pcbnew.${PYMOD_EXT} for command line use."
> +-        )
> +-    add_custom_target(
> +-        pcbnew_python_module ALL
> +-        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_pcbnew.${PYMOD_EXT}
> +-        )
> ++        # For phase 1, copy _pcbnew.kiface to the python module.
> ++        add_custom_command( OUTPUT 
> ${CMAKE_CURRENT_BINARY_DIR}/_pcbnew.${PYMOD_EXT}
> ++            DEPENDS pcbnew_kiface
> ++            COMMAND ${CMAKE_COMMAND} -E copy libpcbnew.a 
> _pcbnew.${PYMOD_EXT}
> ++            COMMENT "Creating python's pcbnew native module 
> _pcbnew.${PYMOD_EXT} for command line use."
> ++            )
> ++        add_custom_target(
> ++            pcbnew_python_module ALL
> ++            DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_pcbnew.${PYMOD_EXT}
> ++            )
> +     endif()
> + 
> + endif()
> Index: cad/kicad/pkg/PLIST
> ===================================================================
> RCS file: /cvs/ports/cad/kicad/pkg/PLIST,v
> retrieving revision 1.2
> diff -u -p -r1.2 PLIST
> --- cad/kicad/pkg/PLIST       10 Dec 2019 23:09:48 -0000      1.2
> +++ cad/kicad/pkg/PLIST       1 Apr 2020 17:24:52 -0000
> @@ -27,6 +27,10 @@ lib/kicad/plugins/3d/
>  @so lib/kicad/plugins/3d/libs3d_plugin_oce.so
>  @so lib/kicad/plugins/3d/libs3d_plugin_vrml.so
>  @lib lib/libkicad_3dsg.so.${LIBkicad_3dsg_VERSION}
> +lib/python${MODPY_VERSION}/site-packages/${MODPY_PYCACHE}/
> +lib/python${MODPY_VERSION}/site-packages/${MODPY_PYCACHE}pcbnew.${MODPY_PYC_MAGIC_TAG}pyc
> +@so lib/python${MODPY_VERSION}/site-packages/_pcbnew.so
> +lib/python${MODPY_VERSION}/site-packages/pcbnew.py
>  share/appdata/
>  share/appdata/kicad.appdata.xml
>  share/applications/bitmap2component.desktop
> @@ -224,16 +228,17 @@ share/kicad/demos/pic_programmer/pic_pro
>  share/kicad/demos/pic_programmer/pic_sockets.sch
>  share/kicad/demos/pic_programmer/sym-lib-table
>  share/kicad/demos/python_scripts_examples/
> +${MODPY_COMMENT}share/kicad/demos/python_scripts_examples/${MODPY_PYCACHE}/
> +share/kicad/demos/python_scripts_examples/${MODPY_PYCACHE}action_menu_add_automatic_border.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/demos/python_scripts_examples/${MODPY_PYCACHE}action_menu_text_by_date.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/demos/python_scripts_examples/${MODPY_PYCACHE}action_plugin_test_undoredo.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/demos/python_scripts_examples/${MODPY_PYCACHE}gen_gerber_and_drill_files_board.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/demos/python_scripts_examples/${MODPY_PYCACHE}plot_board.${MODPY_PYC_MAGIC_TAG}pyc
>  share/kicad/demos/python_scripts_examples/action_menu_add_automatic_border.py
> -share/kicad/demos/python_scripts_examples/action_menu_add_automatic_border.pyc
>  share/kicad/demos/python_scripts_examples/action_menu_text_by_date.py
> -share/kicad/demos/python_scripts_examples/action_menu_text_by_date.pyc
>  share/kicad/demos/python_scripts_examples/action_plugin_test_undoredo.py
> -share/kicad/demos/python_scripts_examples/action_plugin_test_undoredo.pyc
>  share/kicad/demos/python_scripts_examples/gen_gerber_and_drill_files_board.py
> -share/kicad/demos/python_scripts_examples/gen_gerber_and_drill_files_board.pyc
>  share/kicad/demos/python_scripts_examples/plot_board.py
> -share/kicad/demos/python_scripts_examples/plot_board.pyc
>  share/kicad/demos/simulation/
>  share/kicad/demos/simulation/laser_driver/
>  share/kicad/demos/simulation/laser_driver/ad8009.lib
> @@ -316,27 +321,61 @@ share/kicad/demos/video/video.pro
>  share/kicad/demos/video/video.sch
>  share/kicad/plugins/
>  share/kicad/plugins/README-bom.txt
> +${MODPY_COMMENT}share/kicad/plugins/${MODPY_PYCACHE}/
> +share/kicad/plugins/${MODPY_PYCACHE}bom_csv_grouped_by_value.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/plugins/${MODPY_PYCACHE}bom_csv_grouped_by_value_with_fp.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/plugins/${MODPY_PYCACHE}bom_csv_sorted_by_ref.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/plugins/${MODPY_PYCACHE}bom_html_grouped_by_value.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/plugins/${MODPY_PYCACHE}bom_html_with_advanced_grouping.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/plugins/${MODPY_PYCACHE}bom_sorted_by_ref.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/plugins/${MODPY_PYCACHE}kicad_netlist_reader.${MODPY_PYC_MAGIC_TAG}pyc
>  share/kicad/plugins/bom2csv.xsl
>  share/kicad/plugins/bom2grouped_csv.xsl
>  share/kicad/plugins/bom_csv_grouped_by_value.py
> -share/kicad/plugins/bom_csv_grouped_by_value.pyc
>  share/kicad/plugins/bom_csv_grouped_by_value_with_fp.py
> -share/kicad/plugins/bom_csv_grouped_by_value_with_fp.pyc
>  share/kicad/plugins/bom_csv_sorted_by_ref.py
> -share/kicad/plugins/bom_csv_sorted_by_ref.pyc
>  share/kicad/plugins/bom_html_grouped_by_value.py
> -share/kicad/plugins/bom_html_grouped_by_value.pyc
>  share/kicad/plugins/bom_html_with_advanced_grouping.py
> -share/kicad/plugins/bom_html_with_advanced_grouping.pyc
>  share/kicad/plugins/bom_sorted_by_ref.py
> -share/kicad/plugins/bom_sorted_by_ref.pyc
>  share/kicad/plugins/bom_with_title_block_2_csv.xsl
>  share/kicad/plugins/kicad_netlist_reader.py
> -share/kicad/plugins/kicad_netlist_reader.pyc
>  share/kicad/plugins/netlist_form_OrcadPcb2.xsl
>  share/kicad/plugins/netlist_form_cadstar-RINF.xsl
>  share/kicad/plugins/netlist_form_cadstar.xsl
>  share/kicad/plugins/netlist_form_pads-pcb.asc.xsl
> +share/kicad/scripting/
> +share/kicad/scripting/plugins/
> +share/kicad/scripting/plugins/FPC_wizard.py
> +share/kicad/scripting/plugins/FootprintWizardBase.py
> +share/kicad/scripting/plugins/PadArray.py
> +share/kicad/scripting/plugins/__init__.py
> +${MODPY_COMMENT}share/kicad/scripting/plugins/${MODPY_PYCACHE}/
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}FPC_wizard.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}FootprintWizardBase.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}PadArray.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}__init__.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}bga_wizard.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}circular_pad_array_wizard.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}kicad_qrcode.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}microMatch_connectors.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}qfn_wizard.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}qfp_wizard.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}qrcode_footprint_wizard.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}sdip_wizard.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}touch_slider_wizard.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}uss39_barcode.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/${MODPY_PYCACHE}zip_wizard.${MODPY_PYC_MAGIC_TAG}pyc
> +share/kicad/scripting/plugins/bga_wizard.py
> +share/kicad/scripting/plugins/circular_pad_array_wizard.py
> +share/kicad/scripting/plugins/kicad_qrcode.py
> +share/kicad/scripting/plugins/microMatch_connectors.py
> +share/kicad/scripting/plugins/qfn_wizard.py
> +share/kicad/scripting/plugins/qfp_wizard.py
> +share/kicad/scripting/plugins/qrcode_footprint_wizard.py
> +share/kicad/scripting/plugins/sdip_wizard.py
> +share/kicad/scripting/plugins/touch_slider_wizard.py
> +share/kicad/scripting/plugins/uss39_barcode.py
> +share/kicad/scripting/plugins/zip_wizard.py
>  share/kicad/template/kicad.pro
>  share/mime/packages/kicad-gerbers.xml
>  share/mime/packages/kicad-kicad.xml
> 

Reply via email to