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

Gedit 3.8.3 only supports python3 plugins #121

Closed
swansontec opened this issue Sep 19, 2013 · 29 comments
Closed

Gedit 3.8.3 only supports python3 plugins #121

swansontec opened this issue Sep 19, 2013 · 29 comments
Assignees

Comments

@swansontec
Copy link
Member

I tried installing the editorconfig gedit plugin on my Arch Linux box, only to see the following error:

(gedit:5323): libpeas-WARNING **: Could not find loader 'python' for plugin 'editorconfig_gedit'

After some deep research, it turns out that the latest version of gedit no longer contains python2 plugin support. Therefore, our options are to either port the plugin to python3 or re-write it in C.

@ghost ghost assigned swansontec Sep 19, 2013
@treyhunner
Copy link
Member

The EditorConfig core already supports Python 3.

It should be fairly easy to support Python 3 with the Gedit plugin.

@swansontec
Copy link
Member Author

Getting the plugin to load only takes a 2-line change, so that's good. Once it's loaded, though, things still don't work correctly, and I am still looking into that. Apparently, the GObject bindings have changed between python2 and python3.

@swansontec
Copy link
Member Author

Ok, I have a locally-modified version of this plug-in which works correctly on my machine. I would like to push my changes up to GitHub, but I'm not sure what the best approach would be.

The problem is that there are actually plugins in this repository, one for Gedit 2.x and one for Gedit 3.x. Both plugins share a common source file, shared.py, which needed to be changed to work with Python 3. Our options are to either remove the shared file and just have two independent plugins, or port the port the Gedit 2.x plugin to Python 3. Since Gedit 2.x is rather old, I don't think using Python 3 would be a good idea for that plugin. As much as I dislike code duplication, I think this may be the better way.

@treyhunner
Copy link
Member

Gedit 3 also needs to support Python 2 because not everyone is running a
new version with Python 3 support (basically everyone not on Arch Linux
probably is on Python 2 with Gedit 3).

I think the best approach is to support both Python 2 and Python 3 in the
same code base, like we do with the core plugin. That's pretty easy to do.

My suggestion is: create a branch for your new Python 3-compatible code and
make a pull request. We can test the code with Gedit 3 and Python 2 and
see if it works. If it doesn't then we can fix it to work on both before
merging it.

On Mon, Sep 23, 2013 at 5:44 PM, William Swanson
notifications@github.comwrote:

Ok, I have a locally-modified version of this plug-in which works
correctly on my machine. I would like to push my changes up to GitHub, but
I'm not sure what the best approach would be.

The problem is that there are actually plugins in this repository, one for
Gedit 2.x and one for Gedit 3.x. Both plugins share a common source file,
shared.py, which needed to be changed to work with Python 3. Our options
are to either remove the shared file and just have two independent plugins,
or port the port the Gedit 2.x plugin to Python 3. Since Gedit 2.x is
rather old, I don't think using Python 3 would be a good idea for that
plugin. As much as I dislike code duplication, I think this may be the
better way.


Reply to this email directly or view it on GitHubhttps://github.com//issues/121#issuecomment-24967348
.

Trey Hunner

@swansontec
Copy link
Member Author

I think the best approach is to support both Python 2 and Python 3 in the same code base, like we do with the core plugin. That's pretty easy to do.

I originally thought this might not be possible, since the GObject API had changed a bit between Python 2 and Python 3. Fortunately, the Python 3 way works in Python 2 (tested in an Ubuntu VM)

@swansontec
Copy link
Member Author

After doing a git blame on the gedit source code, it looks like the change to python3 was in commit 74cf9539, made after version 3.7.2-12 was tagged. Therefore, this only affects the most recent released version (3.8). The install script still needs to be modified to check for this version and install an updated plugin file.

@treyhunner
Copy link
Member

I think we can and should make only one plugin file that works regardless of the Gedit 3 version.

Most of the Python projects I work on are both Python 2 and Python 3 compatible. It's usually not very difficult to do.

@swansontec
Copy link
Member Author

Most of the Python projects I work on are both Python 2 and Python 3 compatible. It's usually not very difficult to do.

I have already finished this part. It's in the pull request.

The part that isn't done is the meta-data, which tells gedit which plugin loader to use. This is just a one-line change, but it needs to be conditional based on the version of gedit is in use. For 3.8, it needs to say Loader=python3, but for earlier versions it needs to say Loader=python, as it does now. The install script needs to be modified to detect the gedit version and select the correct file based on that.

@treyhunner
Copy link
Member

Ah I see. I wonder how other plugins are handling this. This seems like it would be a very universal problem for Gedit plugins.

@swansontec
Copy link
Member Author

I wonder how other plugins are handling this. This seems like it would be a very universal problem for Gedit plugins.

I checked a few examples, and they seem to be hard-coding the "python3" bit. If you have an older version of gedit, they must expect you to use an older version of the plugin.

@sergiy-kozak
Copy link

I run Gedit 3.10.4, within Gnome 3 shell. Trying to enable EditorConfig Gedit plugin after installation, I still get the same error:

libpeas-WARNING **: Could not find loader 'python' for plugin 'editorconfig_gedit3'

Plugin version is 0.5.1
Python version:

~ $ python --version
Python 2.7.5

@treyhunner
Copy link
Member

This is an odd bug. If I change Loader from python to python3 in my ~/.local/share/gedit/plugins/editorconfig.plugin file I now receive import errors, seemingly due to relative imports without a prefixed .. Some of these errors are in the core EditorConfig library.

Example:

Traceback (most recent call last):
  File "/home/trey/.local/share/gedit/plugins/editorconfig_gedit3.py", line 1, in <module>
    from editorconfig_plugin.gedit3 import *
  File "/home/trey/.local/share/gedit/plugins/editorconfig_plugin/gedit3.py", line 27, in <module>
    from .shared import EditorConfigPluginMixin
  File "/home/trey/.local/share/gedit/plugins/editorconfig_plugin/shared.py", line 2, in <module>
    from .editorconfig import get_properties, EditorConfigError
  File "/home/trey/.local/share/gedit/plugins/editorconfig_plugin/editorconfig/__init__.py", line 3, in <module>
    from versiontools import join_version
ImportError: No module named 'versiontools'

(gedit:1303): libpeas-WARNING **: Error loading plugin 'editorconfig_gedit3'

I have an inadequate understanding of the difference in the import style between the various versions of Python. I may be able to look into this issue this next week. If someone gets to it sooner, feel free to start a pull request or comment on this issue.

@swansontec
Copy link
Member Author

How did you install the plugin? There are actually three versions of the plugin in the same repo, and the install script is responsible for selecting the correct one. In the case of gedit 3.8+, the install script actually edits python3 support into the source files using a sed script. So, I can easily see how you would have problems if you used the wrong install procedure.

@sergiy-kozak
Copy link

Hi @swansontec,
for me the installation of the plugin was as following:

  1. Download plugin release from https://github.com/editorconfig/editorconfig-gedit/archive/v0.5.1.tar.gz
  2. Unpack tar.gz somewhere in the home directory
  3. Locate install.sh file in the root directory of unpacked archive and execute ./install.sh in the console

You also mentioned:

the install script actually edits python3 support into the source files using a sed script

In fact, I don't see this happening in install.sh script, the only sed invocation is to grab currently installed Gedit version. Modifying ~/.local/share/gedit/plugins/editorconfig.plugin to have Loader=python3 results in the similar error as @treyhunner posted, libpeas-WARNING **: Error loading plugin 'editorconfig_gedit3', so I reverted code to the original state.

@swansontec
Copy link
Member Author

Aha! That tarball contains a really old version which doesn't contain any of my python3 fixes (getting it to work with python3 took a lot of effort). So, you need to use the latest git version for now. Trey, maybe we should think of making a new release tarball with my fixes?

@treyhunner
Copy link
Member

@swansontec you're right. I was wondering how I never noticed this problem before. We need to roll a new release.

@sergiy-kozak in the meantime you can download the ZIP from the master branch directly and it should work: https://github.com/editorconfig/editorconfig-gedit/archive/master.zip

@swansontec
Copy link
Member Author

I can't do a release, so I'll leave that in your hands.

@swansontec
Copy link
Member Author

The new release has been tagged, and the readme updated.

@treyhunner
Copy link
Member

@swansontec thanks!

@sergiy-kozak
Copy link

@swansontec, thanks for making a release with the recent changes. I had a moment to test this latest release v 0.5.3 of the plugin. Installation using install.sh script finished successfully, with the message Patching /path/to/gedit/plugins/editorconfig.plugin for Python 3 support.... After that I started Gedit and tried to enable the plugin, which resulted in:

Traceback (most recent call last):
  File "/home/skozak/.local/share/gedit/plugins/editorconfig_gedit3.py", line 1, in <module>
    from editorconfig_plugin.gedit3 import *
  File "/home/skozak/.local/share/gedit/plugins/editorconfig_plugin/gedit3.py", line 27, in <module>
    from .shared import EditorConfigPluginMixin
  File "/home/skozak/.local/share/gedit/plugins/editorconfig_plugin/shared.py", line 9, in <module>
    from editorconfig import get_properties, EditorConfigError
ImportError: No module named 'editorconfig'

(gedit:26289): libpeas-WARNING **: Error loading plugin 'editorconfig_gedit3'

The issues still don't seem to be gone...

P.S. just to remind versions:

skozak@skozak-sabayon ~ $ python --version
Python 2.7.5
skozak@skozak-sabayon ~ $ gedit --version
gedit - Version 3.10.4

@swansontec
Copy link
Member Author

Ah, it looks like you haven't installed editorconfig-core-py. You have to cd into that directory and run setup.py.

@xuhdev
Copy link
Member

xuhdev commented Apr 1, 2014

I think checkout the submodule should be enough. You can choose to install it, for sure.

@sergiy-kozak
Copy link

Thanks for pointing to that, @swansontec, just installed editorconfig-core-py, no errors, finished OK. Started Gedit and tried to enable plugin again. Unfortunately same import error. What could it be, it looks now totally strange because I can see in python interactive console:

help> modules editorconfig

Here is a list of matching modules.  Enter any module name to get more help.

editorconfig - EditorConfig Python Core
editorconfig.compat - EditorConfig Python2/Python3/Jython compatibility utilities
editorconfig.exceptions - EditorConfig exception classes
editorconfig.fnmatch - Filename matching with shell patterns.
editorconfig.handler - EditorConfig file handler
editorconfig.ini - EditorConfig file parser
editorconfig.main - EditorConfig command line interface
editorconfig.odict - odict.py: An Ordered Dictionary object
editorconfig.versiontools - EditorConfig version tools
dm.c: 1640: not running as root returning empty list
** Message: pygobject_register_sinkfunc is deprecated (GstObject)

(.:13173): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",
(.:13173): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",
(.:13173): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",
(.:13173): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",
(.:13173): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",
(.:13173): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",
(.:13173): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",

help> quit

so everything for editorconfig is right there, ready to use. Any ideas how to fix that import errors?

@swansontec
Copy link
Member Author

Are you running python 2 or python 3? It sometimes gets confusing with both versions installed on the system.

@xuhdev No, you definitely need to install the core separately from the plugin.

@sergiy-kozak
Copy link

A couple of commands to see the version information:

skozak@skozak-sabayon ~ $ eselect python list
Available Python interpreters:
  [1]   python2.7 *
  [2]   python3.3
skozak@skozak-sabayon ~ $ python --version
Python 2.7.5

So python currently used is 2.7.5, but could it be that Gedit messes things up by selecting not system-wide configured python, meaning python 3.3?

@swansontec
Copy link
Member Author

Ah, so, when you ran that setup script, it installed the editorconfig-core for python2, not python3. Since the plugin is python3, from his perspective, editorconfig-core is not installed. Therefore, you somehow need to install the core for python3.

@treyhunner
Copy link
Member

@swansontec actually you should not need to install the EditorConfig module globally for this plugin to work. That's why the core library is included in the repository. See the top of the shared.py file for details about the local import of the library.

@swansontec
Copy link
Member Author

@treyhunner That's a nice theory, but that's not how it's coded. The install script only copies over the plugin files, not the core. Things have been this way since a while now; they were certainly this way when I did the python3 fixes. If this is not how they are supposed to be, then that's a bug that needs to be fixed. Since I don't have time to fix the install script right now, installing the core globally is the only way to make the plugin work.

@flipdazed
Copy link

flipdazed commented Jul 6, 2016

hacked a fix for latex plugin using 2to3 - http://stackoverflow.com/a/38235346/4013571

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

No branches or pull requests

5 participants