Unify scripting dirs and open user-based
This consolidates python scripting in two locations: the system-wide package-based location and the user configuration location. It also updates the "Show Scripting Folder" action to open the user configuration location instead of the package-based one. Fixes https://gitlab.com/kicad/code/kicad/issues/5652 Fixes https://gitlab.com/kicad/code/kicad/issues/5115
This commit is contained in:
parent
f3586ccd45
commit
45ca1709bb
|
@ -1475,11 +1475,11 @@ void PCB_EDIT_FRAME::PythonPluginsShowFolder()
|
|||
wxString msg;
|
||||
|
||||
// Quote in case there are spaces in the path.
|
||||
msg.Printf( "open \"%s\"", PyPluginsPath() );
|
||||
msg.Printf( "open \"%s\"", PyPluginsPath( true ) );
|
||||
|
||||
system( msg.c_str() );
|
||||
#else
|
||||
wxString pypath( PyPluginsPath() );
|
||||
wxString pypath( PyPluginsPath( true ) );
|
||||
|
||||
// Quote in case there are spaces in the path.
|
||||
AddDelimiterString( pypath );
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <pcb_edit_frame.h>
|
||||
#include <eda_dde.h>
|
||||
#include <wx/file.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/snglinst.h>
|
||||
#include <gestfich.h>
|
||||
#include <pcbnew.h>
|
||||
|
@ -280,6 +281,16 @@ static bool scriptingSetup()
|
|||
|
||||
#endif
|
||||
|
||||
wxFileName path( PyPluginsPath( true ) + wxT("/") );
|
||||
|
||||
// Ensure the user plugin path exists, and create it if not.
|
||||
if( !path.DirExists() && !path.Mkdir() )
|
||||
{
|
||||
wxLogDebug( "Warning: could not create user scripting path %s",
|
||||
path.GetPath() );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !pcbnewInitPythonScripting( TO_UTF8( PyScriptingPath() ) ) )
|
||||
{
|
||||
wxLogError( "pcbnewInitPythonScripting() failed." );
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <trace_helpers.h>
|
||||
|
||||
#include <pgm_base.h>
|
||||
#include <settings/settings_manager.h>
|
||||
|
||||
/* init functions defined by swig */
|
||||
|
||||
|
@ -207,7 +208,7 @@ bool pcbnewInitPythonScripting( const char * aUserScriptingPath )
|
|||
|
||||
#endif // ifdef KICAD_SCRIPTING_WXPYTHON
|
||||
|
||||
// Load pcbnew inside Python and load all the user plugins, TODO: add system wide plugins
|
||||
// Load pcbnew inside Python and load all the user plugins and package-based plugins
|
||||
{
|
||||
PyLOCK lock;
|
||||
|
||||
|
@ -616,16 +617,23 @@ wxString PyErrStringWithTraceback()
|
|||
/**
|
||||
* Find the Python scripting path.
|
||||
*/
|
||||
wxString PyScriptingPath()
|
||||
wxString PyScriptingPath( bool aUserPath )
|
||||
{
|
||||
wxString path;
|
||||
|
||||
//@todo This should this be a user configurable variable eg KISCRIPT?
|
||||
if( aUserPath)
|
||||
{
|
||||
path = SETTINGS_MANAGER::GetUserSettingsPath() + wxT( "/scripting" );
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined( __WXMAC__ )
|
||||
path = GetOSXKicadDataDir() + wxT( "/scripting" );
|
||||
path = GetOSXKicadDataDir() + wxT( "/scripting" );
|
||||
#else
|
||||
path = Pgm().GetExecutablePath() + wxT( "../share/kicad/scripting" );
|
||||
path = Pgm().GetExecutablePath() + wxT( "../share/kicad/scripting" );
|
||||
#endif
|
||||
}
|
||||
|
||||
wxFileName scriptPath( path );
|
||||
scriptPath.MakeAbsolute();
|
||||
|
@ -640,9 +648,9 @@ wxString PyScriptingPath()
|
|||
}
|
||||
|
||||
|
||||
wxString PyPluginsPath()
|
||||
wxString PyPluginsPath( bool aUserPath )
|
||||
{
|
||||
// Note we are using unix path separator, because window separator sometimes
|
||||
// creates issues when passing a command string to a python method by PyRun_SimpleString
|
||||
return PyScriptingPath() + '/' + "plugins";
|
||||
return PyScriptingPath( aUserPath ) + '/' + "plugins";
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ wxString PyStringToWx( PyObject* str );
|
|||
wxArrayString PyArrayStringToWx( PyObject* arr );
|
||||
wxString PyErrStringWithTraceback();
|
||||
|
||||
wxString PyScriptingPath();
|
||||
wxString PyPluginsPath();
|
||||
wxString PyScriptingPath( bool aUserPath = false );
|
||||
wxString PyPluginsPath( bool aUserPath = false );
|
||||
|
||||
#endif // __PYTHON_SCRIPTING_H
|
||||
|
|
|
@ -159,18 +159,10 @@ def LoadPlugins(bundlepath=None):
|
|||
<bundlepath>/
|
||||
<bundlepath>/plugins/
|
||||
|
||||
The Scripts relative to the KiCad search path environment variable:
|
||||
[KICAD_PATH]/scripting/
|
||||
[KICAD_PATH]/scripting/plugins/
|
||||
|
||||
The Scripts relative to the KiCad Users configuration:
|
||||
<kicad_config_path>/scripting/
|
||||
<kicad_config_path>/scripting/plugins/
|
||||
<userpath>/
|
||||
<userpath>/plugins/
|
||||
|
||||
And on Linux ONLY, extra paths relative to the users home directory:
|
||||
~/.kicad_plugins/
|
||||
~/.kicad/scripting/
|
||||
~/.kicad/scripting/plugins/
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
@ -181,7 +173,6 @@ def LoadPlugins(bundlepath=None):
|
|||
import importlib
|
||||
importlib.invalidate_caches()
|
||||
|
||||
kicad_path = os.environ.get('KICAD_PATH')
|
||||
config_path = pcbnew.SETTINGS_MANAGER.GetUserSettingsPath()
|
||||
plugin_directories=[]
|
||||
|
||||
|
@ -196,18 +187,10 @@ def LoadPlugins(bundlepath=None):
|
|||
plugin_directories.append(bundlepath)
|
||||
plugin_directories.append(os.path.join(bundlepath, 'plugins'))
|
||||
|
||||
if kicad_path:
|
||||
plugin_directories.append(os.path.join(kicad_path, 'scripting'))
|
||||
plugin_directories.append(os.path.join(kicad_path, 'scripting', 'plugins'))
|
||||
|
||||
if config_path:
|
||||
plugin_directories.append(os.path.join(config_path, 'scripting'))
|
||||
plugin_directories.append(os.path.join(config_path, 'scripting', 'plugins'))
|
||||
|
||||
if sys.platform.startswith('linux'):
|
||||
plugin_directories.append(os.path.join(os.environ['HOME'],'.kicad_plugins'))
|
||||
plugin_directories.append(os.path.join(os.environ['HOME'],'.kicad','scripting'))
|
||||
plugin_directories.append(os.path.join(os.environ['HOME'],'.kicad','scripting','plugins'))
|
||||
|
||||
global PLUGIN_DIRECTORIES_SEARCH
|
||||
PLUGIN_DIRECTORIES_SEARCH=""
|
||||
|
|
Loading…
Reference in New Issue