Bug report #3145

Dash in plugin name causes unhelpful error message

Added by Václav Řehák about 9 years ago. Updated almost 9 years ago.

Status:Closed
Priority:Low
Assignee:Borys Jurgiel
Category:Python plugins
Affected QGIS version: Regression?:No
Operating System:All Easy fix?:No
Pull Request or Patch supplied: Resolution:invalid
Crashes QGIS or corrupts data: Copied to github as #:13205

Description

I encountered a problem with using a '-' sign (dash) in python plugin in 1.6 r14423. When I add my custom repository (http://www.tarsiusproject.org/qgis/plugins.xml) and try to install plugin called 'Dash Test' which contains 'dash-test' directory in 'dash-test.zip', QGIS raises error message that reads:

"The plugin is broken. Python said:
invalid syntax"

If there is a technical reason for prohibiting dash in the plugin folder I think QGIS should emit more descriptive error message.

History

#1 Updated by Giuseppe Sucameli about 9 years ago

Replying to rehakv1:

I encountered a problem with using a '-' sign (dash) in python plugin in 1.6 . When I add my custom repository (http://www.tarsiusproject.org/qgis/plugins.xml) and try to install plugin called 'Dash Test' which contains 'dash-test' directory in 'dash-test.zip', QGIS raises error message that reads:

"The plugin is broken. Python said:
invalid syntax"

You should rename your plugin folder and package to "dash_test" because the chars after the dash in the package name are used for release name or version (e.g "dash_test-dev.zip" or "dash_test-1.0.zip").Instead the folder name must be truncated before the dash (i.e. "dash_test" in both the above cases).

If there is a technical reason for prohibiting dash in the plugin folder I think QGIS should emit more descriptive error message.

The error message is for users, not for developers. IMHO users don't want to know why the package is broken.

#2 Updated by Václav Řehák about 9 years ago

You should rename your plugin folder and package to "dash_test" because the chars after the dash in the package name are used for release name or version (e.g "dash_test-dev.zip" or "dash_test-1.0.zip").Instead the folder name must be truncated before the dash (i.e. "dash_test" in both the above cases).

Yes, I figured this out and renamed my plugin folder. I also removed the version number based on this observation. Is there any recomendation or best practice guide for plugin naming? I see that e.g. the plugin in Faunalia repo don't add version number to the zip file.

The error message is for users, not for developers. IMHO users don't want to know why the package is broken.

Sorry, but I don't think this a good reasoning. The error message "The plugin is broken. Python said: invalid syntax" has no meaning to a regular user. And the developer has no chance to find out what's wrong with the plugin. I spent more than hour reviewing my source code because I thought there was a syntax error in my Python code. If the error was "Invalid filename" or even better "Invalid filename - allowed characters are alphanumeric symbols and underscore" I would have fixed it in 5 minutes.

#3 Updated by Giuseppe Sucameli about 9 years ago

Replying to [comment:2 rehakv1]:

Yes, I figured this out and renamed my plugin folder. I also removed the version number based on this observation. Is there any recomendation or best practice guide for plugin naming? I see that e.g. the plugin in Faunalia repo don't add version number to the zip file.

We at Faunalia avoid dashes and release name: I think it's only useful to maintain available different versions of the same plugin.

I don't know if there's a guide, but you can ask in the dev ML.

The error message is for users, not for developers. IMHO users don't want to know why the package is broken.

Sorry, but I don't think this a good reasoning. The error message "The plugin is broken. Python said: invalid syntax" has no meaning to a regular user. And the developer has no chance to find out what's wrong with the plugin. I spent more than hour reviewing my source code because I thought there was a syntax error in my Python code. If the error was "Invalid filename" or even better "Invalid filename - allowed characters are alphanumeric symbols and underscore" I would have fixed it in 5 minutes.

You're right, today I've changed my opinion about this.

If there's an useful message, users can help developers to find the issue, otherwise this may be more difficult.
The message is also useful to identify strange python plugin installer's behavior (if any).

#4 Updated by Borys Jurgiel almost 9 years ago

  • Resolution set to invalid
  • Status changed from Open to Closed

As the message says, it's a Python syntax error, not a Qgis restriction. Python modules can't contain dashes and when you try to import this plugin (what is a python module in fact), Python raises the syntax error and Qgis only passes that message to the gui. I'm closing the ticket as I think Qgis shouldn't analyze and validate Python syntax :) Please reopen if you disagree.

In general, the module name (=the plugin directory name) must meet Python requirements, so can't contain dashes, dots etc. The zip file name must be either moduleName.zip or moduleName.anySuffix.zip The suffix allows you to keep a few plugin versions in one directory in the repo, for example: myplugin.stable.zip and myplugin.dev.zip; the latter sghould be marked as experimental.

They both will be installed under the same moduleName name (one covers another), depending on the experimental switch state in the Installer. So the user can easily test the dev version and revert to the stable one.

If you want be able to install different versions side by side, you must use different moduleNames. But please only do it if necessery and use _stable and _dev suffixes rather than particular numbers, otherwise users will be flooded by depreciated modules with no hope to update :)

Also available in: Atom PDF