Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running python plugins from build dir (output dir) #286

Closed
wants to merge 2 commits into from
Closed

Allow running python plugins from build dir (output dir) #286

wants to merge 2 commits into from

Conversation

strk
Copy link
Contributor

@strk strk commented Oct 10, 2012

Takes a step forward toward closing http://hub.qgis.org/issues/5879
More work is needed to ensure all python plugins install themselves
under the output/python/plugins dir.

Sandro Santilli added 2 commits October 10, 2012 22:29
Takes a step forward toward closing  http://hub.qgis.org/issues/5879
More work is needed to ensure all python plugins install themselves
under the output/python/plugins dir.
@strk strk mentioned this pull request Oct 11, 2012
@@ -460,13 +457,13 @@ QString QgsPythonUtilsImpl::homePythonPath()
}
else
{
return '"' + settingsDir + "python\"";
return settingsDir + "python";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to break something.

Have a look at https://github.com/qgis/Quantum-GIS/blob/master/src/python/qgspythonutilsimpl.cpp#L459:
both the if and else statements return a string containing python code,
in your change the else statement returns a path as string while the if is unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Thu, Oct 11, 2012 at 06:00:43AM -0700, Giuseppe Sucameli wrote:

@@ -460,13 +457,13 @@ QString QgsPythonUtilsImpl::homePythonPath()
}
else
{

  • return '"' + settingsDir + "python"";
  • return settingsDir + "python";

This change seems to break something.

Have a look at https://github.com/qgis/Quantum-GIS/blob/master/src/python/qgspythonutilsimpl.cpp#L459:
both the if and else statements return a string containing python code,
in your code the else statement returns a path as string instead.

Yes, but the callers add the quotes when needed, doesn't them ?
But then I guess the xpanduser part wouldn't want to be quoted.
The problem was with https://github.com/qgis/Quantum-GIS/blob/master/src/python/qgspythonutilsimpl.cpp#L86
resulting in a weird sys.path (containing + in it).

@brushtyler
Copy link
Contributor

AFAICS after your change (and maybe also before it) the if/else is not needed at all, you can just replace it with return settingsDir + "python";

Here's the code before the change:

  QString settingsDir = QgsApplication::qgisSettingsDirPath();
  if ( settingsDir == QDir::homePath() + "/.qgis/" )
  {
    return "os.path.expanduser(\"~/.qgis/python\")";
  }
  else
  {
    return '"' + settingsDir + "python\"";
  }

that always returns settingsDir + "/python".

@strk
Copy link
Contributor Author

strk commented Oct 11, 2012

On Thu, Oct 11, 2012 at 09:03:31AM -0700, Giuseppe Sucameli wrote:

AFAICS after your change (and maybe also before it) the if/else is not needed at all, you can just replace it with return settingsDir + "python";

Here's the code before the change:

  QString settingsDir = QgsApplication::qgisSettingsDirPath();
  if ( settingsDir == QDir::homePath() + "/.qgis/" )
  {
    return "os.path.expanduser(\"~/.qgis/python\")";
  }
  else
  {
    return '"' + settingsDir + "python\"";
  }

that always returns settingsDir + "/python", i.e. ~/.qgis/python

It depends on the value returned by qgisSettingsDirPath(), doesn't it ?
I've no idea what purpose that setting is supposed to serve
nor the rationale for having python expand ~ differently than QT did.

Anyway, if nothing complains I'm happy to see the conditional dropped...

--strk;

http://www.cartodb.com - Map, analyze and build applications with your data

                                   ~~ http://strk.keybit.net

@etiennesky
Copy link
Contributor

does "~" work on windows?

@strk
Copy link
Contributor Author

strk commented Oct 11, 2012

On Thu, Oct 11, 2012 at 09:22:51AM -0700, Etienne Tourigny wrote:

does "~" work on windows?

Do you mean to say that the conditional is there to avoid using "~" ?
Because it doesn't look like that code would avoid that...

@brushtyler
Copy link
Contributor

Let's look:
QDir::homePath() returns "/home/brushtyler" on my Ubuntu.
Then if ( settingsDir == QDir::homePath() + "/.qgis/" ) means if settingsDir == "/home/brushtyler/.qgis/"
and the function returns /home/brushtyler/.qgis = settingsDir + "/.qgis/"
otherwise the function returns settingsDir + "/.qgis/.

@brushtyler
Copy link
Contributor

The os.path.expanduser() was added in b60a63b, then changed in ed0cb5d

@etiennesky
Copy link
Contributor

The question was - does "~" work on windows?

also, why the conditional? Shouldn't QgsApplication::qgisSettingsDirPath() + "python" be enough???

sorry for butting in, I haven't looked into this much.

@brushtyler
Copy link
Contributor

The question was - does "~" work on windows?

Are you talking about os.path.expanduser("~/.qgis/python")? It works also on win (see http://docs.python.org/library/os.path.html#os.path.expanduser)

why the conditional? Shouldn't QgsApplication::qgisSettingsDirPath() + "python" be enough???

Exactly what I wrote, removing the if/else at all. That block was added in ed0cb5d, maybe there's something we don't know, I'm looking at the related tickets.

@brushtyler
Copy link
Contributor

Found, have a look at http://hub.qgis.org/issues/2512.
The problem occurs with non-ascii chars, escaping the string in runString( "sys.path = [" + newpaths.join( "," ) + "] + sys.path" ); is not enough.

I guess that code need a bigger refactoring than just changing few lines of code.

@strk
Copy link
Contributor Author

strk commented Oct 11, 2012

On Thu, Oct 11, 2012 at 10:14:29AM -0700, Giuseppe Sucameli wrote:

Found, have a look at http://hub.qgis.org/issues/2512.
The problem occurs with non-ascii chars, escaping the string in runString( "sys.path = [" + newpaths.join( "," ) + "] + sys.path" ); is not enough.

I guess that code need a bigger refactoring than just changing few lines of code.

Do you think we can get to produce a testcase for that issue ?
HINT: tomorrow is Test Friday !

I have to admit I still fail to understand the issue.
Is it python failing when a "string" contains a non-ascii char ?

--strk;

http://www.cartodb.com - Map, analyze and build applications with your data

                                   ~~ http://strk.keybit.net

@wonder-sk
Copy link
Member

It is getting too easy to get lost in the quoting of the paths - IMHO the right solution would be to set the paths using Python C API to ensure that the paths with international characters are still properly passed to python side.

@strk
Copy link
Contributor Author

strk commented Oct 11, 2012

On Thu, Oct 11, 2012 at 12:07:58PM -0700, Martin Dobias wrote:

It is getting too easy to get lost in the quoting of the paths - IMHO the right solution would be to set the paths using Python C API to ensure that the paths with international characters are still properly passed to python side.

I still don't understand what's the problem with international chars.
Can it be just a matter of telling runString that the string will going
to be utf8 ?

@ghost ghost assigned wonder-sk Oct 12, 2012
@strk
Copy link
Contributor Author

strk commented Oct 12, 2012

I had a chance to try a simpler change, since I think last time I tested I was being confused by a lot more parameters.
This one would be much simpler:

diff --git a/src/python/qgspythonutilsimpl.cpp b/src/python/qgspythonutilsimpl.cpp
index d0be929..cea90c0 100644
--- a/src/python/qgspythonutilsimpl.cpp
+++ b/src/python/qgspythonutilsimpl.cpp
@@ -445,9 +445,6 @@ QString QgsPythonUtilsImpl::pythonPath()

 QString QgsPythonUtilsImpl::pluginsPath()
 {
-  if ( QgsApplication::isRunningFromBuildDir() )
-    return QString(); // plugins not used
-  else
     return pythonPath() + "/plugins";
 }

It worked fine in loading plugins from output/python/plugin dir.

@brushtyler
Copy link
Contributor

No more plus signs (+) in path???

@strk
Copy link
Contributor Author

strk commented Oct 12, 2012

Nope, just tried again with master, it's all fine. Only needs plugin in output/python/plugin then.
Maybe the plus signs I only saw when printing the string to standard output, but I guess they get interpreted by python which takes them as string concatenation before they're ever used.

Opening a new pull request with this small patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants