mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
Merge pull request #1045 from pypeclub/bugfix/unicode_strings
Auto fix unicode strings
This commit is contained in:
commit
7e97e8de27
3 changed files with 16 additions and 41 deletions
|
|
@ -1,40 +0,0 @@
|
|||
import os
|
||||
from maya import cmds
|
||||
|
||||
import pyblish.api
|
||||
import pype.api
|
||||
import pype.hosts.maya.api.action
|
||||
|
||||
|
||||
class ValidateUnicodeStrings(pyblish.api.Validator):
|
||||
"""Validate all environment variables are string type.
|
||||
|
||||
"""
|
||||
|
||||
order = pype.api.ValidateContentsOrder
|
||||
hosts = ['maya']
|
||||
families = ['review']
|
||||
label = 'Unicode Strings'
|
||||
actions = [pype.api.RepairAction]
|
||||
|
||||
def process(self, instance):
|
||||
invalid = self.get_invalid(instance)
|
||||
if invalid:
|
||||
raise RuntimeError("Found unicode strings in environment variables.")
|
||||
|
||||
@classmethod
|
||||
def get_invalid(cls, instance):
|
||||
invalid = []
|
||||
for key, value in os.environ.items():
|
||||
if type(value) is type(u't'):
|
||||
invalid.append((key, value))
|
||||
|
||||
return invalid
|
||||
|
||||
@classmethod
|
||||
def repair(cls, instance):
|
||||
"""Retype all unicodes to strings."""
|
||||
|
||||
for key, value in os.environ.items():
|
||||
if type(value) is type(u't'):
|
||||
os.environ[key] = str(value)
|
||||
|
|
@ -94,7 +94,7 @@ def run_subprocess(*args, **kwargs):
|
|||
# not passed.
|
||||
env = kwargs.get("env") or os.environ
|
||||
# Make sure environment contains only strings
|
||||
filtered_env = {k: str(v) for k, v in env.items()}
|
||||
filtered_env = {str(k): str(v) for k, v in env.items()}
|
||||
|
||||
# Use lib's logger if was not passed with kwargs.
|
||||
logger = kwargs.pop("logger", log)
|
||||
|
|
|
|||
15
pype/plugins/publish/repair_unicode_strings.py
Normal file
15
pype/plugins/publish/repair_unicode_strings.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import os
|
||||
import pyblish.api
|
||||
|
||||
|
||||
class RepairUnicodeStrings(pyblish.api.Collector):
|
||||
"""Validate all environment variables are string type.
|
||||
|
||||
"""
|
||||
|
||||
order = pyblish.api.CollectorOrder
|
||||
label = 'Unicode Strings'
|
||||
|
||||
def process(self, context):
|
||||
for key, value in os.environ.items():
|
||||
os.environ[str(key)] = str(value)
|
||||
Loading…
Add table
Add a link
Reference in a new issue