Coverage for /Users/davegaeddert/Developer/dropseed/plain/plain/plain/assets/finders.py: 21%
28 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
1import os
3from plain.packages import packages
4from plain.runtime import APP_PATH
6APP_ASSETS_DIR = APP_PATH / "assets"
8SKIP_ASSETS = (".DS_Store", ".gitignore")
11def find_assets():
12 assets_map = {}
14 class Asset:
15 def __init__(self, *, url_path, absolute_path):
16 self.url_path = url_path
17 self.absolute_path = absolute_path
19 def __str__(self):
20 return self.url_path
22 def iter_directory(path):
23 for root, _, files in os.walk(path):
24 for f in files:
25 if f in SKIP_ASSETS:
26 continue
27 abs_path = os.path.join(root, f)
28 url_path = os.path.relpath(abs_path, path)
29 yield url_path, abs_path
31 # Iterate the installed package assets, in order
32 for pkg in packages.get_package_configs():
33 pkg_assets_dir = os.path.join(pkg.path, "assets")
34 for url_path, abs_path in iter_directory(pkg_assets_dir):
35 assets_map[url_path] = Asset(url_path=url_path, absolute_path=abs_path)
37 # The app/assets take priority over everything
38 for url_path, abs_path in iter_directory(APP_ASSETS_DIR):
39 assets_map[url_path] = Asset(url_path=url_path, absolute_path=abs_path)
41 return assets_map