Ejemplo n.º 1
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
"""
The imports module is designed to fix the import statements.
"""
import traceback

from qt_py_convert.general import ALIAS_DICT, change, supported_binding
from qt_py_convert.color import color_text, ANSI
from qt_py_convert.log import get_logger

EXPAND_STARS_LOG = get_logger("expand_stars")


class Processes(object):
    """Processes class for expand_stars"""
    @staticmethod
    def _get_children(binding, levels=None):
        """
        You have done the following:
        >>> from <binding>.<levels> import *

        And I hate you a little bit.
        I am changing it to the following:
        >>> from <binding> import <levels>

        But I don't know what the heck you used in the *
Ejemplo n.º 2
0
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
"""
The imports module is designed to fix the import statements.
"""
from qt_py_convert.general import __supported_bindings__, ALIAS_DICT, change, \
    supported_binding
from qt_py_convert.log import get_logger

IMPORTS_LOG = get_logger("imports")


class Processes(object):
    """Processes class for import"""
    @staticmethod
    def _build_child_name(child):
        return ".".join([child_part.dumps() for child_part in child.value])

    @staticmethod
    def _no_second_level_module(node, _child_parts, skip_lineno=False):
        replacement = "import Qt"
        change(
            logger=IMPORTS_LOG,
            node=node,
            replacement=replacement,
Ejemplo n.º 3
0
import redbaron

from qt_py_convert._modules import from_imports
from qt_py_convert._modules import imports
from qt_py_convert._modules import psep0101
from qt_py_convert._modules import unsupported
from qt_py_convert.general import merge_dict, ErrorClass, \
    ALIAS_DICT, change, UserInputRequiredException, ANSI,  \
    __suplimentary_bindings__, is_py, build_exc, WriteFlag
from qt_py_convert.color import color_text
from qt_py_convert.mappings import convert_mappings, misplaced_members
from qt_py_convert.log import get_logger

COMMON_MODULES = Qt._common_members.keys() + ["QtCompat"]

MAIN_LOG = get_logger("run")
Qt4_Qt5_LOG = get_logger("qt4->qt5")


def _cleanup_imports(red, aliases, mappings, skip_lineno=False):
    """
    _cleanup_imports fixes the imports.
    Initially changing them as per the following:
    >>> from PyQt4 import QtGui, QtCore
    to 
    >>> from Qt import QtGui, QtCore
    for each binding.
    It doesn't have enough knowledge of your script at this point to know if 
      you need QtWidgets or if the ones you import are all used. 
    This will get reflected at the end.
Ejemplo n.º 4
0
These are the changes that created "api v2.0", which is what PySide uses and
PyQt4 has the option of.
"""
__author__ = 'ahughes'
# https://github.com/techtonik/pseps

import re
import sys

from qt_py_convert.general import change, ErrorClass
from qt_py_convert.log import get_logger
from qt_py_convert._modules.psep0101 import _qsignal
from qt_py_convert._modules.psep0101 import _conversion_methods

PSEP_LOG = get_logger("psep0101")

# Pulled out of six because I don't want to have to bind this package to DD
# code to load six.
# That seems a little insane to me...So because I am only using six.text_type,
# I am removing the six import and inlining the code.
# TODO: rely on six when this is OSS
text_type = str if sys.version_info[0] == 3 else unicode


class Processes(object):
    """Processes class for psesp0101"""
    @staticmethod
    def _process_qvariant(red, objects, skip_lineno=False, **kwargs):
        """
        _process_qvariant is designed to replace QVariant code.
Ejemplo n.º 5
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
"""
The from_imports module is designed to fix the from import statements.
"""
from qt_py_convert._modules.expand_stars import process as stars_process
from qt_py_convert.general import __supported_bindings__, ALIAS_DICT, change, \
    supported_binding
from qt_py_convert.log import get_logger

FROM_IMPORTS_LOG = get_logger("from_imports")
IGNORED_IMPORT_TARGETS = ("right_parenthesis", "left_parenthesis")


class Processes(object):
    """Processes class for from_imports"""
    @staticmethod
    def _get_import_parts(node, binding):
        return node.dumps().replace(binding, "").lstrip(".").split(".")

    @staticmethod
    def _no_second_level_module(node, _parts, skip_lineno=False):
        text = "from Qt import {key}".format(
            key=", ".join([target.value for target in node.targets]))

        change(logger=FROM_IMPORTS_LOG,
Ejemplo n.º 6
0
# language governing permissions and limitations under the Apache License.
"""
general is utility functions for the qt_py_convert library
"""
import copy
import json
import os
import re

import Qt

from qt_py_convert.color import ANSI, color_text
from qt_py_convert.diff import highlight_diffs
from qt_py_convert.log import get_logger

GENERAL_LOGGER = get_logger("general", name_color=ANSI.colors.green)


class WriteFlag(object):
    WRITE_TO_FILE = 0b0001
    WRITE_TO_STDOUT = 0b0010


def change(logger, node, replacement, skip_lineno=False, msg=None):
    """
    A helper function to print information about replacing a node.

    :param logger: A python logger
    :type logger: logger.Logger
    :param node: Redbaron node that you are going to replace.
    :type node: redbaron.node
Ejemplo n.º 7
0
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
import re

import Qt

from qt_py_convert.log import get_logger
from qt_py_convert.general import _custom_misplaced_members

MAPPINGS_LOG = get_logger("mappings")


def misplaced_members(aliases, mappings):
    """
    misplaced_members uses the internal "_misplaced_members" from Qt.py as
    well as any "_custom_misplaced_members" that you have set to update the
    detected binding members. The Qt.py misplaced members aid in updating
    bindings to Qt5 compatible locations.

    :param aliases: Aliases is the replacement information that is build
        automatically from qt_py_convert.
    :type aliases: dict
    :param mappings: Mappings is information about the bindings that are used.
    :type mappings: dict
    :return: A tuple of aliases and mappings that have been updated.