• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.normalize_path函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中static_precompiler.utils.normalize_path函数的典型用法代码示例。如果您正苦于以下问题:Python normalize_path函数的具体用法?Python normalize_path怎么用?Python normalize_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了normalize_path函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_locate_imported_file

def test_locate_imported_file(compiler_module, monkeypatch):

    root = os.path.dirname(__file__)

    existing_files = set()
    for f in ("A/B.scss", "A/_C.scss", "A/S.sass", "D.scss"):
        existing_files.add(os.path.join(root, "static", utils.normalize_path(f)))

    additional_path = os.path.join(root, "static", "additional-path")
    existing_files.add(
        os.path.join(additional_path, "foo.scss")
    )

    monkeypatch.setattr("os.path.exists", lambda x: x in existing_files)

    compiler = compiler_module.SCSS(load_paths=(
        additional_path,
    ))

    assert compiler.locate_imported_file("A", "B.scss") == "A/B.scss"
    assert compiler.locate_imported_file("A", "C") == "A/_C.scss"
    assert compiler.locate_imported_file("E", "../D") == "D.scss"
    assert compiler.locate_imported_file("E", "../A/B.scss") == "A/B.scss"
    assert compiler.locate_imported_file("", "D.scss") == "D.scss"
    assert compiler.locate_imported_file("A", "S.sass") == "A/S.sass"
    assert compiler.locate_imported_file("A", "S") == "A/S.sass"
    assert compiler.locate_imported_file("A", "foo") == "foo.scss"
    assert compiler.locate_imported_file("bar", "foo") == "foo.scss"

    with pytest.raises(exceptions.StaticCompilationError):
        compiler.locate_imported_file("", "Z.scss")
开发者ID:sir-sigurd,项目名称:django-static-precompiler,代码行数:31,代码来源:test_scss.py


示例2: test_find_dependencies

    def test_find_dependencies(self):
        compiler = LESS()
        files = {
            "A.less": "@import 'B/C.less';",
            "B/C.less": "@import '../E';",
            "E.less": "p {color: red;}",
        }
        compiler.get_source = MagicMock(side_effect=lambda x: files[x])

        root = os.path.dirname(__file__)

        existing_files = set()
        for f in files:
            existing_files.add(os.path.join(root, "static", normalize_path(f)))

        with patch("os.path.exists") as mocked_os_path_exist:
            mocked_os_path_exist.side_effect = lambda x: x in existing_files

            self.assertEqual(
                compiler.find_dependencies("A.less"),
                ["B/C.less", "E.less"]
            )
            self.assertEqual(
                compiler.find_dependencies("B/C.less"),
                ["E.less"]
            )
            self.assertEqual(
                compiler.find_dependencies("E.less"),
                []
            )
开发者ID:Anber,项目名称:django-static-precompiler,代码行数:30,代码来源:test_less.py


示例3: test_locate_imported_file

    def test_locate_imported_file(self):
        compiler = LESS()
        with patch("os.path.exists") as mocked_os_path_exist:

            root = os.path.dirname(__file__)

            existing_files = set()
            for f in ("A/B.less", "D.less"):
                existing_files.add(os.path.join(root, "static", normalize_path(f)))

            mocked_os_path_exist.side_effect = lambda x: x in existing_files

            self.assertEqual(
                compiler.locate_imported_file("A", "B.less"),
                "A/B.less"
            )
            self.assertEqual(
                compiler.locate_imported_file("E", "../D"),
                "D.less"
            )
            self.assertEqual(
                compiler.locate_imported_file("E", "../A/B.less"),
                "A/B.less"
            )
            self.assertEqual(
                compiler.locate_imported_file("", "D.less"),
                "D.less"
            )
            self.assertRaises(
                StaticCompilationError,
                lambda: compiler.locate_imported_file("", "Z.less")
            )
开发者ID:Anber,项目名称:django-static-precompiler,代码行数:32,代码来源:test_less.py


示例4: get_full_source_path

    def get_full_source_path(self, source_path):
        """ Return the full path to the given source file.
            Check if the source file exists.
            The returned path is OS-dependent.

        :param source_path: relative path to a source file
        :type source_path: str
        :returns: str
        :raises: ValueError

        """
        norm_source_path = normalize_path(source_path.lstrip("/"))

        if STATIC_ROOT:
            full_path = os.path.join(STATIC_ROOT, norm_source_path)
            if os.path.exists(full_path):
                return full_path

        try:
            full_path = finders.find(norm_source_path)
        except SuspiciousOperation:
            full_path = None

        if full_path is None:
            raise ValueError("Can't find staticfile named: {0}".format(source_path))

        return full_path
开发者ID:Anber,项目名称:django-static-precompiler,代码行数:27,代码来源:base.py


示例5: get_full_output_path

    def get_full_output_path(self, source_path):
        """ Get full path to compiled file based for the given source file.
            The returned path is OS-dependent.

        :param source_path: relative path to a source file
        :type source_path: str
        :returns: str

        """
        return os.path.join(ROOT, normalize_path(self.get_output_path(source_path.lstrip("/"))))
开发者ID:Anber,项目名称:django-static-precompiler,代码行数:10,代码来源:base.py


示例6: get_full_source_path

 def get_full_source_path(self, source_path):
     try:
         return super(SCSS, self).get_full_source_path(source_path)
     except ValueError:
         # Try to locate the source file in directories specified in `load_paths`
         norm_source_path = utils.normalize_path(source_path.lstrip("/"))
         for dirname in self.load_paths:
             full_path = os.path.join(dirname, norm_source_path)
             if os.path.exists(full_path):
                 return full_path
         raise
开发者ID:sir-sigurd,项目名称:django-static-precompiler,代码行数:11,代码来源:scss.py


示例7: test_locate_imported_file

def test_locate_imported_file(monkeypatch):
    compiler = compilers.Stylus()

    root = os.path.dirname(__file__)

    existing_files = set()
    for f in ("A/B.styl", "C.styl"):
        existing_files.add(os.path.join(root, "static", utils.normalize_path(f)))

    monkeypatch.setattr("os.path.exists", lambda x: x in existing_files)

    assert compiler.locate_imported_file("A", "B.styl") == "A/B.styl"
    assert compiler.locate_imported_file("", "C.styl") == "C.styl"

    with pytest.raises(exceptions.StaticCompilationError):
        compiler.locate_imported_file("", "Z.styl")
开发者ID:dotmobo,项目名称:django-static-precompiler,代码行数:16,代码来源:test_stylus.py


示例8: test_locate_imported_file

def test_locate_imported_file(monkeypatch):
    compiler = LESS()

    root = os.path.dirname(__file__)

    existing_files = set()
    for f in ("A/B.less", "D.less"):
        existing_files.add(os.path.join(root, "static", normalize_path(f)))

    monkeypatch.setattr("os.path.exists", lambda path: path in existing_files)

    assert compiler.locate_imported_file("A", "B.less") == "A/B.less"
    assert compiler.locate_imported_file("E", "../D") == "D.less"
    assert compiler.locate_imported_file("E", "../A/B.less") == "A/B.less"
    assert compiler.locate_imported_file("", "D.less") == "D.less"

    with pytest.raises(StaticCompilationError):
        compiler.locate_imported_file("", "Z.less")
开发者ID:and3rson,项目名称:django-static-precompiler,代码行数:18,代码来源:test_less.py


示例9: locate_imported_file

    def locate_imported_file(self, source_dir, import_path):
        """ Locate the imported file in the source directory.
            Return the path to the imported file relative to STATIC_ROOT

        :param source_dir: source directory
        :type source_dir: str
        :param import_path: path to the imported file
        :type import_path: str
        :returns: str

        """
        import_filename = posixpath.basename(import_path)
        import_dirname = posixpath.dirname(import_path)
        import_filename_root, import_filename_extension = posixpath.splitext(import_filename)

        if import_filename_extension:
            filenames_to_try = [import_filename]
        else:
            # No extension is specified for the imported file, try all supported extensions
            filenames_to_try = [import_filename_root + "." + extension for extension in self.import_extensions]

        if not import_filename.startswith("_"):
            # Try the files with "_" prefix
            filenames_to_try += ["_" + filename for filename in filenames_to_try]

        # Try to locate the file in the directory relative to `source_dir`
        for filename in filenames_to_try:
            source_path = posixpath.normpath(posixpath.join(source_dir, import_dirname, filename))
            try:
                self.get_full_source_path(source_path)
                return source_path
            except ValueError:
                pass

        # Try to locate the file in the directories listed in `load_paths`
        for dirname in self.load_paths:
            for filename in filenames_to_try:
                source_path = posixpath.join(import_dirname, filename)
                if os.path.exists(os.path.join(dirname, utils.normalize_path(source_path))):
                    return source_path

        raise exceptions.StaticCompilationError("Can't locate the imported file: {0}".format(import_path))
开发者ID:sir-sigurd,项目名称:django-static-precompiler,代码行数:42,代码来源:scss.py


示例10: test_find_dependencies

def test_find_dependencies(monkeypatch):
    compiler = compilers.LESS()
    files = {
        "A.less": "@import 'B/C.less';",
        "B/C.less": "@import '../E';",
        "E.less": "p {color: red;}",
    }
    monkeypatch.setattr(compiler, "get_source", lambda x: files[x])

    root = os.path.dirname(__file__)

    existing_files = set()
    for f in files:
        existing_files.add(os.path.join(root, "static", utils.normalize_path(f)))

    monkeypatch.setattr("os.path.exists", lambda path: path in existing_files)

    assert compiler.find_dependencies("A.less") == ["B/C.less", "E.less"]
    assert compiler.find_dependencies("B/C.less") == ["E.less"]
    assert compiler.find_dependencies("E.less") == []
开发者ID:jaheba,项目名称:django-static-precompiler,代码行数:20,代码来源:test_less.py


示例11: test_find_dependencies

def test_find_dependencies(compiler_module, monkeypatch):
    compiler = compiler_module.SCSS()
    files = {
        "A.scss": "@import 'B/C.scss';",
        "B/C.scss": "@import '../E';",
        "_E.scss": "p {color: red;}",
        "compass-import.scss": '@import "compass"',
    }
    monkeypatch.setattr(compiler, "get_source", lambda x: files[x])

    root = os.path.dirname(__file__)

    existing_files = set()
    for f in files:
        existing_files.add(os.path.join(root, "static", utils.normalize_path(f)))

    monkeypatch.setattr("os.path.exists", lambda x: x in existing_files)

    assert compiler.find_dependencies("A.scss") == ["B/C.scss", "_E.scss"]
    assert compiler.find_dependencies("B/C.scss") == ["_E.scss"]
    assert compiler.find_dependencies("_E.scss") == []
开发者ID:sir-sigurd,项目名称:django-static-precompiler,代码行数:21,代码来源:test_scss.py



注:本文中的static_precompiler.utils.normalize_path函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.run_command函数代码示例发布时间:2022-05-27
下一篇:
Python base.BaseCompiler类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap