コード例 #1
0
ファイル: plugin.py プロジェクト: bigdrum/snaked
    def project_manager(self):
        root = getattr(self.editor, 'ropeproject_root', self.editor.project_root)
        try:
            return project_managers[root]
        except KeyError:
            pass

        from rope.base.project import Project, NoProject
        from rope.base.fscommands import FileSystemCommands

        if not root:
            self.editor.message('Rope warning: there is no project. Assist was degraded', 3000)
            project = NoProject()
            project.validate = lambda *args: None
            project.root = None
        else:
            if os.access(root, os.W_OK):
                kwargs = {}
            else:
                kwargs = dict(ropefolder=None)

            project = Project(root, fscommands=FileSystemCommands(), **kwargs)

        project.snaked_project_root = root
        pm = RopeProjectManager(project)
        if root:
            project_managers[root] = pm

        return pm
コード例 #2
0
ファイル: projecttest.py プロジェクト: caseboy01/myemacs
 def setUp(self):
     super(OutOfProjectTest, self).setUp()
     self.test_directory = 'temp_test_directory'
     testutils.remove_recursively(self.test_directory)
     os.mkdir(self.test_directory)
     self.project = testutils.sample_project()
     self.no_project = NoProject()
コード例 #3
0
def get_proposals(project, source, offset=None, **kwargs):
    head = 'from scopetest import *\n\n'
    source = head + source

    if offset is None:
        offset = len(source)
    else:
        offset += len(head)

    resource = NoProject().get_file(join_to_file_dir(__file__, 'module.py'))
    resource.read = lambda: ''

    return code_assist(project, source, offset, resource=resource, **kwargs)
コード例 #4
0
class OutOfProjectTest(unittest.TestCase):
    def setUp(self):
        super(OutOfProjectTest, self).setUp()
        self.test_directory = "temp_test_directory"
        testutils.remove_recursively(self.test_directory)
        os.mkdir(self.test_directory)
        self.project = testutils.sample_project()
        self.no_project = NoProject()

    def tearDown(self):
        testutils.remove_project(self.project)
        testutils.remove_recursively(self.test_directory)
        super(OutOfProjectTest, self).tearDown()

    def test_simple_out_of_project_file(self):
        sample_file_path = os.path.join(self.test_directory, "sample.txt")
        sample_file = file(sample_file_path, "w")
        sample_file.write("sample content\n")
        sample_file.close()
        sample_resource = self.no_project.get_resource(sample_file_path)
        self.assertEquals("sample content\n", sample_resource.read())

    def test_simple_out_of_project_folder(self):
        sample_folder_path = os.path.join(self.test_directory, "sample_folder")
        os.mkdir(sample_folder_path)
        sample_folder = self.no_project.get_resource(sample_folder_path)
        self.assertEquals([], sample_folder.get_children())

        sample_file_path = os.path.join(sample_folder_path, "sample.txt")
        file(sample_file_path, "w").close()
        sample_resource = self.no_project.get_resource(sample_file_path)
        self.assertEquals(sample_resource, sample_folder.get_children()[0])

    def test_using_absolute_path(self):
        sample_file_path = os.path.join(self.test_directory, "sample.txt")
        file(sample_file_path, "w").close()
        normal_sample_resource = self.no_project.get_resource(sample_file_path)
        absolute_sample_resource = self.no_project.get_resource(os.path.abspath(sample_file_path))
        self.assertEquals(normal_sample_resource, absolute_sample_resource)

    def test_folder_get_child(self):
        sample_folder_path = os.path.join(self.test_directory, "sample_folder")
        os.mkdir(sample_folder_path)
        sample_folder = self.no_project.get_resource(sample_folder_path)
        self.assertEquals([], sample_folder.get_children())

        sample_file_path = os.path.join(sample_folder_path, "sample.txt")
        file(sample_file_path, "w").close()
        sample_resource = self.no_project.get_resource(sample_file_path)
        self.assertTrue(sample_folder.has_child("sample.txt"))
        self.assertFalse(sample_folder.has_child("doesnothave.txt"))
        self.assertEquals(sample_resource, sample_folder.get_child("sample.txt"))

    def test_out_of_project_files_and_path_to_resource(self):
        sample_file_path = os.path.join(self.test_directory, "sample.txt")
        sample_file = file(sample_file_path, "w")
        sample_file.write("sample content\n")
        sample_file.close()
        sample_resource = self.no_project.get_resource(sample_file_path)
        self.assertEquals(sample_resource, path_to_resource(self.project, sample_file_path))
コード例 #5
0
ファイル: plugin.py プロジェクト: bigdrum/snaked
    def get_rope_resource(self, project, uri=None):
        from rope.base import libutils, exceptions
        uri = uri or self.editor.uri

        if not hasattr(project, 'address'):
            return project.get_file(uri)
        else:
            try:
                return libutils.path_to_resource(project, uri)
            except exceptions.ResourceNotFoundError:
                from rope.base.project import NoProject
                resource = NoProject().get_file(uri)
                resource.read = lambda: ''
                return resource
コード例 #6
0
ファイル: projecttest.py プロジェクト: caseboy01/myemacs
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.project = testutils.sample_project(foldername='sampleproject',
                                             ropefolder=None)
     self.project_root = self.project.address
     self._make_sample_project()
     self.no_project = NoProject()
コード例 #7
0
 def setUp(self):
     super(OutOfProjectTest, self).setUp()
     self.test_directory = "temp_test_directory"
     testutils.remove_recursively(self.test_directory)
     os.mkdir(self.test_directory)
     self.project = testutils.sample_project()
     self.no_project = NoProject()
コード例 #8
0
def get_proposals(project, source, offset=None, **kwargs):
    head = (
        'class Window(object):\n'
        '   """glade-file: sample.glade"""\n'
        '\n'
        '   def func(self):\n'
        '       '
    )

    source = head + source

    if offset is None:
        offset = len(source)
    else:
        offset += len(head)

    resource = NoProject().get_file(join_to_file_dir(__file__, 'pygtktest', 'module.py'))
    resource.read = lambda: ''

    return code_assist(project, source, offset, resource=resource, **kwargs)
コード例 #9
0
ファイル: projecttest.py プロジェクト: caseboy01/myemacs
class OutOfProjectTest(unittest.TestCase):
    def setUp(self):
        super(OutOfProjectTest, self).setUp()
        self.test_directory = 'temp_test_directory'
        testutils.remove_recursively(self.test_directory)
        os.mkdir(self.test_directory)
        self.project = testutils.sample_project()
        self.no_project = NoProject()

    def tearDown(self):
        testutils.remove_project(self.project)
        testutils.remove_recursively(self.test_directory)
        super(OutOfProjectTest, self).tearDown()

    def test_simple_out_of_project_file(self):
        sample_file_path = os.path.join(self.test_directory, 'sample.txt')
        sample_file = open(sample_file_path, 'w')
        sample_file.write('sample content\n')
        sample_file.close()
        sample_resource = self.no_project.get_resource(sample_file_path)
        self.assertEquals('sample content\n', sample_resource.read())

    def test_simple_out_of_project_folder(self):
        sample_folder_path = os.path.join(self.test_directory, 'sample_folder')
        os.mkdir(sample_folder_path)
        sample_folder = self.no_project.get_resource(sample_folder_path)
        self.assertEquals([], sample_folder.get_children())

        sample_file_path = os.path.join(sample_folder_path, 'sample.txt')
        open(sample_file_path, 'w').close()
        sample_resource = self.no_project.get_resource(sample_file_path)
        self.assertEquals(sample_resource, sample_folder.get_children()[0])

    def test_using_absolute_path(self):
        sample_file_path = os.path.join(self.test_directory, 'sample.txt')
        open(sample_file_path, 'w').close()
        normal_sample_resource = self.no_project.get_resource(sample_file_path)
        absolute_sample_resource = \
            self.no_project.get_resource(os.path.abspath(sample_file_path))
        self.assertEquals(normal_sample_resource, absolute_sample_resource)

    def test_folder_get_child(self):
        sample_folder_path = os.path.join(self.test_directory, 'sample_folder')
        os.mkdir(sample_folder_path)
        sample_folder = self.no_project.get_resource(sample_folder_path)
        self.assertEquals([], sample_folder.get_children())

        sample_file_path = os.path.join(sample_folder_path, 'sample.txt')
        open(sample_file_path, 'w').close()
        sample_resource = self.no_project.get_resource(sample_file_path)
        self.assertTrue(sample_folder.has_child('sample.txt'))
        self.assertFalse(sample_folder.has_child('doesnothave.txt'))
        self.assertEquals(sample_resource,
                          sample_folder.get_child('sample.txt'))

    def test_out_of_project_files_and_path_to_resource(self):
        sample_file_path = os.path.join(self.test_directory, 'sample.txt')
        sample_file = open(sample_file_path, 'w')
        sample_file.write('sample content\n')
        sample_file.close()
        sample_resource = self.no_project.get_resource(sample_file_path)
        self.assertEquals(sample_resource,
                          path_to_resource(self.project, sample_file_path))