Skip to content

Commit

Permalink
Do not add package directories python sys.path. Refs #4924
Browse files Browse the repository at this point in the history
Packages need to remain only accessible via the package-name.submodule
else it breaks the whole point of them.
  • Loading branch information
martyngigg committed Apr 23, 2012
1 parent 1392edd commit f043515
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/PythonAPI/MantidFramework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ def _addToPySearchPath(dirs):
for path in dirs:
if path.endswith('/') or path.endswith("\\"):
path = os.path.dirname(path)
if not path in sys.path:
if not path in sys.path and not os.path.exists(os.path.join(path, '__init__.py')):
sys.path.append(path)

def _refreshPyAlgorithms(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from MantidFramework import *
from mantidsimple import *

from reducer import Reducer

import re
import itertools
from types import NoneType
Expand Down
17 changes: 14 additions & 3 deletions Code/Mantid/MantidPlot/src/PythonScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "MantidQtAPI/WorkspaceObserver.h"

#include <QFileInfo>
#include <QDir>

class ScriptingEnv;
class PythonScripting;
Expand Down Expand Up @@ -102,15 +103,25 @@ class PythonScript : public Script, MantidQt::API::WorkspaceObserver
const QFileInfo filePath(m_path);
if( filePath.exists() )
{
m_path = filePath.dirPath(true);
appendPath(m_path);
QDir directory = filePath.absoluteDir();
// Check it is not a package
if( !QFileInfo(directory, "__init__.py").exists() )
{
m_path = directory.absolutePath();
appendPath(m_path);
}
else
{
m_path = "";
}
}
}
/// Remove the entry from the path
~PythonPathHolder()
{
removePath(m_path);
if(!m_path.isEmpty()) removePath(m_path);
}

void appendPath(const QString & path)
{
GlobalInterpreterLock pythonLock;
Expand Down

0 comments on commit f043515

Please sign in to comment.