How to use rope - 10 common examples

To help you get started, we’ve selected a few rope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marslo / myvim / Configurations / Offline_Packages / bundle / python-mode / pymode / libs2 / rope / refactor / importutils / __init__.py View on Github external
def _rename_in_module(self, pymodule, name, new_name, till_dot=False):
        old_name = name.split('.')[-1]
        old_pyname = rope.base.evaluate.eval_str(pymodule.get_scope(), name)
        occurrence_finder = occurrences.create_finder(
            self.project, old_name, old_pyname, imports=False)
        changes = rope.base.codeanalyze.ChangeCollector(pymodule.source_code)
        for occurrence in occurrence_finder.find_occurrences(
                pymodule=pymodule):
            start, end = occurrence.get_primary_range()
            if till_dot:
                new_end = pymodule.source_code.index('.', end) + 1
                space = pymodule.source_code[end:new_end - 1].strip()
                if not space == '':
                    for c in space:
                        if not c.isspace() and c not in '\\':
                            raise ValueError()
                end = new_end
            changes.add_change(start, end, new_name)
        source = changes.get_changed()
github JulianEberius / RopeMate.tmbundle / Support / bin / refactor.py View on Github external
name = identifier_before_dot()

        if not name:
            return [], " Not at an identifier."
        module = None
        try:
            module = __import__(name)
        except ImportError, e:
            return [], " %s." % e
        
        names = dir(module)
        
        for name in names:
            if not name.startswith("__"):
                p = rope.contrib.codeassist.CompletionProposal(
                    name, "imported", rope.base.pynames.UnboundName())
                type_name = type(getattr(module, name)).__name__
                if type_name.find('function') != -1 or type_name.find('method') != -1:
                    p.type = 'function'
                elif type_name == 'module':
                    p.type = 'module'
                elif type_name == 'type':
                    p.type = 'class'
                else:
                    p.type = 'instance'
                result.append(p)
        
        # if module is a package, check the direc tory
        if hasattr(module,"__path__"):
          in_dir_names = [os.path.split(n)[1] for n in glob.glob(os.path.join(module.__path__[0], "*"))]
          in_dir_names = [n.replace(".py","") for n in in_dir_names
                              if not n.endswith(".pyc") and not n == "__init__.py"]
github python-rope / rope / rope / base / oi / soi.py View on Github external
def _follow_evaluations(assignment, pyname, pyobject):
    new_pyname = pyname
    tokens = assignment.evaluation.split('.')
    for token in tokens:
        call = token.endswith('()')
        if call:
            token = token[:-2]
        if token:
            pyname = new_pyname
            new_pyname = _get_attribute(pyobject, token)
            if new_pyname is not None:
                pyobject = new_pyname.get_object()
        if pyobject is not None and call:
            if isinstance(pyobject, rope.base.pyobjects.AbstractFunction):
                args = arguments.ObjectArguments([pyname])
                pyobject = pyobject.get_returned_object(args)
            else:
                pyobject = None
        if pyobject is None:
            break
    if pyobject is not None and assignment.assign_type:
        return rope.base.pyobjects.PyObject(pyobject)
    return pyobject
github gtt116 / vimrc / vim / bundle / python-mode / submodules / rope / rope / refactor / importutils / __init__.py View on Github external
def _rename_in_module(self, pymodule, name, new_name, till_dot=False):
        old_name = name.split('.')[-1]
        old_pyname = rope.base.evaluate.eval_str(pymodule.get_scope(), name)
        occurrence_finder = occurrences.create_finder(
            self.project, old_name, old_pyname, imports=False)
        changes = rope.base.codeanalyze.ChangeCollector(pymodule.source_code)
        for occurrence in occurrence_finder.find_occurrences(
                pymodule=pymodule):
            start, end = occurrence.get_primary_range()
            if till_dot:
                new_end = pymodule.source_code.index('.', end) + 1
                space = pymodule.source_code[end:new_end - 1].strip()
                if not space == '':
                    for c in space:
                        if not c.isspace() and c not in '\\':
                            raise ValueError()
                end = new_end
            changes.add_change(start, end, new_name)
        source = changes.get_changed()
        if source is not None:
github spyder-ide / spyder / external-py2 / rope / refactor / similarfinder.py View on Github external
def _pydefined_to_str(pydefined):
    address = []
    if isinstance(pydefined, (builtins.BuiltinClass, builtins.BuiltinFunction)):
        return '__builtins__.' + pydefined.get_name()
    else:
        while pydefined.parent is not None:
            address.insert(0, pydefined.get_name())
            pydefined = pydefined.parent
        module_name = pydefined.pycore.modname(pydefined.resource)
    return '.'.join(module_name.split('.') + address)
github DonJayamanne / pythonVSCode / pythonFiles / rope / refactor / move.py View on Github external
def _import_filter(self, stmt):
      module_name = libutils.modname(self.source)

      if isinstance(stmt.import_info, importutils.NormalImport):
          # Affect any statement that imports the source module
          return any(module_name == name
                     for name, alias in stmt.import_info.names_and_aliases)
      elif isinstance(stmt.import_info, importutils.FromImport):
          # Affect statements importing from the source package
          if '.' in module_name:
              package_name, basename = module_name.rsplit('.', 1)
              if (stmt.import_info.module_name == package_name and
                  any(basename == name
                      for name, alias in stmt.import_info.names_and_aliases)):
                  return True
          return stmt.import_info.module_name == module_name
      return False
github marslo / myvim / Configurations / Offline_Packages / bundle / python-mode / pymode / libs / rope / base / pyobjectsdef.py View on Github external
def __init__(self, pycore, ast_node, parent):
        rope.base.pyobjects.AbstractFunction.__init__(self)
        rope.base.pyobjects.PyDefinedObject.__init__(
            self, pycore, ast_node, parent)
        self.arguments = self.ast_node.args
        self.parameter_pyobjects = pynames._Inferred(
            self._infer_parameters, self.get_module()._get_concluded_data())
        self.returned = pynames._Inferred(self._infer_returned)
        self.parameter_pynames = None
github marslo / myvim / Configurations / Offline_Packages / bundle / python-mode / pymode / libs / rope / refactor / introduce_parameter.py View on Github external
def get_changes(self, new_parameter):
        definition_info = functionutils.DefinitionInfo.read(self.pyfunction)
        definition_info.args_with_defaults.append((new_parameter,
                                                   self._get_primary()))
        collector = codeanalyze.ChangeCollector(self.resource.read())
        header_start, header_end = self._get_header_offsets()
        body_start, body_end = sourceutils.get_body_region(self.pyfunction)
        collector.add_change(header_start, header_end,
                             definition_info.to_string())
        self._change_function_occurances(collector, body_start,
                                         body_end, new_parameter)
        changes = rope.base.change.ChangeSet('Introduce parameter <%s>' %
                                             new_parameter)
        change = rope.base.change.ChangeContents(self.resource,
                                                 collector.get_changed())
        changes.add_change(change)
        return changes
github JulianEberius / SublimePythonIDE / server / lib / python2 / rope / base / project.py View on Github external
def _default_config(self):
        import rope.base.default_config
        import inspect
        return inspect.getsource(rope.base.default_config)
github python-rope / rope / rope / base / project.py View on Github external
such a folder at all.
            - `prefs`: Specify project preferences.  These values
              overwrite config file preferences.

        """
        if projectroot != '/':
            projectroot = _realpath(projectroot).rstrip('/\\')
        self._address = projectroot
        self._ropefolder_name = ropefolder
        if not os.path.exists(self._address):
            os.mkdir(self._address)
        elif not os.path.isdir(self._address):
            raise exceptions.RopeError('Project root exists and'
                                       ' is not a directory')
        if fscommands is None:
            fscommands = rope.base.fscommands.create_fscommands(self._address)
        super(Project, self).__init__(fscommands)
        self.ignored = _ResourceMatcher()
        self.file_list = _FileListCacher(self)
        self.prefs.add_callback('ignored_resources', self.ignored.set_patterns)
        if ropefolder is not None:
            self.prefs['ignored_resources'] = [ropefolder]
        self._init_prefs(prefs)
        self._init_source_folders()