Pyblish plugins syntax error


#1

I wrote some code in PyCharm and when i tried to register plugin i got Error: (invalid syntax (, line 1)).
The reason was that file contained \r\n tags instead of just \n.
I solved this problem by changing pyblish_base\pyblish\plugin.py:
From:
six.exec_(f.read(), module.__dict__)
To:
six.exec_(f.read().replace('\r', ''), module.__dict__)

Is it a bug or i missed something ?


#2

Hi @sega, thanks for reporting this.

Would you be able to post either the plug-in itself, or a reproducible here that I could have a look at? Also what OS are you on?


#3

Hi @marcus.

I`m on Windows 7, using pyblish_lite with maya 2013.
I got the same error when i opened default plugins in pyblish_base/pyblish/plugins by WordPad and resaved them, thats why i decied to check file syntax.


#4

Thanks @sega

Wordpad and other rich-text editors append additional metadata to plain text files that may break your source code. Try using a plain text editor or IDE, such as Notepad or Sublime Text.


#5

I`m using PyCharm and just tried to test things with wordpad.
I will try to check same thing with sublime/atom.


#6

Yes, sorry I completely missed you mentioned PyCharm. That should work without any problems.

Could you share some code that I could try on my end? There are many developers writing plug-ins in PyCharm without any problem so far.


#7

Here it is:

import pyblish.api
import maya.cmds as mc


class RigCollector(pyblish.api.ContextPlugin):
    label = "Collect rigs"
    order = pyblish.api.CollectorOrder

    def process(self, context):
        if mc.ls('asset_info'):
            name = mc.getAttr('asset_info.id')
            self.log.info("Collecting: %s" % name)
            instance = context.create_instance(name, families=["rig"])
            mc.select('character')
            instance[:] = mc.file(constructionHistory=True, exportSelected=True, preview=True, force=True)


class RigValidator(pyblish.api.InstancePlugin):
    order = pyblish.api.ValidatorOrder
    label = "Validate Rigs"
    families = ["rig"]

    def process(self, instance):
        self.log.info("Validating: %s" % instance)
        assert "main_control" in instance, "%s is missing main_control" % instance


class RigExtractor(pyblish.api.InstancePlugin):
    order = pyblish.api.ExtractorOrder
    families = ["rig"]
    label = "My Extractor"

    def process(self, instance):
        self.log.info("Extracting: %s" % instance)

https://drive.google.com/open?id=0BzoeFXjCV-etbTJQb3EzaDREY0k


#8

Thanks @sega, I pasted the code here for completeness, but the file is kept in the history of the edits.

I’ll take a look at this soon, but for now, are you able to copy/paste the above into a new file and save that? This seems like an issue with this particular file. Worst case, try saving it in Notepad, and have a look at whether PyCharm has any settings for line-endings.


#9

Copy-paste in notepad didn`t work, same error.