MCPcopy
hub / github.com/plotly/dash / _walk_assets_directory

Method _walk_assets_directory

dash/dash.py:1706–1755  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1704 return res
1705
1706 def _walk_assets_directory(self):
1707 walk_dir = self.config.assets_folder
1708 slash_splitter = re.compile(r"[\\/]+")
1709 ignore_str = self.config.assets_ignore
1710 ignore_path_list = self.config.assets_path_ignore
1711 ignore_filter = re.compile(ignore_str) if ignore_str else None
1712 ignore_path_filters = [
1713 re.compile(ignore_path)
1714 for ignore_path in (ignore_path_list or [])
1715 if ignore_path
1716 ]
1717
1718 for current, _, files in sorted(os.walk(walk_dir)):
1719 if current == walk_dir:
1720 base = ""
1721 s = ""
1722 else:
1723 s = current.replace(walk_dir, "").lstrip("\\").lstrip("/")
1724 splitted = slash_splitter.split(s)
1725 if len(splitted) > 1:
1726 base = "/".join(slash_splitter.split(s))
1727 else:
1728 base = splitted[0]
1729
1730 # Check if any level of current path matches ignore path
1731 if s and any(
1732 ignore_path_filter.search(x)
1733 for ignore_path_filter in ignore_path_filters
1734 for x in s.split(os.path.sep)
1735 ):
1736 pass
1737 else:
1738 if ignore_filter:
1739 files_gen = (x for x in files if not ignore_filter.search(x))
1740 else:
1741 files_gen = files
1742
1743 for f in sorted(files_gen):
1744 path = "/".join([base, f]) if base else f
1745
1746 full = os.path.join(current, f)
1747
1748 if f.endswith("js"):
1749 self.scripts.append_script(
1750 self._add_assets_resource(path, full)
1751 )
1752 elif f.endswith("css"):
1753 self.css.append_css(self._add_assets_resource(path, full)) # type: ignore[reportArgumentType]
1754 elif f == "favicon.ico":
1755 self._favicon = path
1756
1757 @staticmethod
1758 def _invalid_resources_handler(err):

Callers 1

_setup_serverMethod · 0.95

Calls 5

_add_assets_resourceMethod · 0.95
compileMethod · 0.80
walkMethod · 0.80
append_scriptMethod · 0.80
append_cssMethod · 0.80

Tested by

no test coverage detected