Example #1
0
def test_sys_path_with_modifications():
    SRC = dedent(u("""
        import os
    """))
    grammar = load_grammar()
    p = Parser(grammar, SRC)
    p.module.path = os.path.abspath(os.path.join(os.curdir, 'module_name.py'))
    paths = sys_path_with_modifications(Evaluator(grammar), p.module)
    assert '/tmp/.buildout/eggs/important_package.egg' in paths
Example #2
0
def test_sys_path_with_modifications():
    SRC = dedent(u("""
        import os
    """))
    grammar = load_grammar()
    p = ParserWithRecovery(grammar, SRC)
    p.module.path = os.path.abspath(os.path.join(os.curdir, 'module_name.py'))
    paths = sys_path_with_modifications(Evaluator(grammar), p.module)
    assert '/tmp/.buildout/eggs/important_package.egg' in paths
def test_sys_path_with_modifications():
    code = dedent("""
        import os
    """)

    path = os.path.abspath(os.path.join(os.curdir, 'module_name.py'))
    grammar = load_grammar()
    module_node = parse(code, path=path)
    module_context = ModuleContext(Evaluator(grammar), module_node, path=path)
    paths = sys_path_with_modifications(module_context.evaluator, module_context)
    assert '/tmp/.buildout/eggs/important_package.egg' in paths
Example #4
0
def test_sys_path_with_modifications():
    code = dedent("""
        import os
    """)

    path = os.path.abspath(os.path.join(os.curdir, 'module_name.py'))
    grammar = load_grammar()
    module_node = parse(code, path=path)
    module_context = ModuleContext(Evaluator(grammar), module_node, path=path)
    paths = sys_path_with_modifications(module_context.evaluator,
                                        module_context)
    assert '/tmp/.buildout/eggs/important_package.egg' in paths
Example #5
0
    def sys_path_with_modifications(self):
        # If you edit e.g. gunicorn, there will be imports like this:
        # `from gunicorn import something`. But gunicorn is not in the
        # sys.path. Therefore look if gunicorn is a parent directory, #56.
        in_path = []
        if self.import_path and self.file_path is not None:
            parts = self.file_path.split(os.path.sep)
            for i, p in enumerate(parts):
                if p == unicode(self.import_path[0]):
                    new = os.path.sep.join(parts[:i])
                    in_path.append(new)

        return in_path + sys_path_with_modifications(self._evaluator, self.module)
    def sys_path_with_modifications(self):
        # If you edit e.g. gunicorn, there will be imports like this:
        # `from gunicorn import something`. But gunicorn is not in the
        # sys.path. Therefore look if gunicorn is a parent directory, #56.
        in_path = []
        if self.import_path and self.file_path is not None:
            parts = self.file_path.split(os.path.sep)
            for i, p in enumerate(parts):
                if p == unicode(self.import_path[0]):
                    new = os.path.sep.join(parts[:i])
                    in_path.append(new)

        return in_path + sys_path_with_modifications(self._evaluator, self.module)
Example #7
0
    def _sys_path_with_modifications(self):
        # If you edit e.g. gunicorn, there will be imports like this:
        # `from gunicorn import something`. But gunicorn is not in the
        # sys.path. Therefore look if gunicorn is a parent directory, #56.
        in_path = []
        if self.import_path:
            parts = self.file_path.split(os.path.sep)
            for i, p in enumerate(parts):
                if p == self.import_path[0]:
                    new = os.path.sep.join(parts[:i])
                    in_path.append(new)

        module = self.import_stmt.get_parent_until()
        return in_path + sys_path.sys_path_with_modifications(module)
Example #8
0
    def _sys_path_with_modifications(self):
        # If you edit e.g. gunicorn, there will be imports like this:
        # `from gunicorn import something`. But gunicorn is not in the
        # sys.path. Therefore look if gunicorn is a parent directory, #56.
        in_path = []
        if self.import_path:
            parts = self.file_path.split(os.path.sep)
            for i, p in enumerate(parts):
                if p == self.import_path[0]:
                    new = os.path.sep.join(parts[:i])
                    in_path.append(new)

        module = self.import_stmt.get_parent_until()
        return in_path + sys_path.sys_path_with_modifications(module)
    def sys_path_with_modifications(self):
        in_path = []
        sys_path_mod = list(sys_path.sys_path_with_modifications(self._evaluator, self.module))
        if self.file_path is not None:
            # If you edit e.g. gunicorn, there will be imports like this:
            # `from gunicorn import something`. But gunicorn is not in the
            # sys.path. Therefore look if gunicorn is a parent directory, #56.
            if self.import_path:  # TODO is this check really needed?
                for path in sys_path.traverse_parents(self.file_path):
                    if os.path.basename(path) == self.str_import_path[0]:
                        in_path.append(os.path.dirname(path))

            # Since we know nothing about the call location of the sys.path,
            # it's a possibility that the current directory is the origin of
            # the Python execution.
            sys_path_mod.insert(0, os.path.dirname(self.file_path))

        return in_path + sys_path_mod