diff options
| author | Daniel Schadt <kingdread@gmx.de> | 2025-12-27 10:44:28 +0100 |
|---|---|---|
| committer | Daniel Schadt <kingdread@gmx.de> | 2025-12-27 10:44:28 +0100 |
| commit | a836b77a04c898600ac208185d476062646488d3 (patch) | |
| tree | ef89cff9ea8d4cd99967f95d4664649a007eb99a /src | |
| parent | 8b025bad44dcdf4d373b8202780fb1847d83240f (diff) | |
| parent | 73593a0d318121662de1ec56bfa838a390d45f96 (diff) | |
| download | pyramid-a836b77a04c898600ac208185d476062646488d3.tar.gz pyramid-a836b77a04c898600ac208185d476062646488d3.tar.bz2 pyramid-a836b77a04c898600ac208185d476062646488d3.zip | |
Merge remote-tracking branch 'luhn/override-get-spec'
Diffstat (limited to 'src')
| -rw-r--r-- | src/pyramid/config/assets.py | 14 | ||||
| -rw-r--r-- | src/pyramid/config/views.py | 10 | ||||
| -rw-r--r-- | src/pyramid/interfaces.py | 8 |
3 files changed, 24 insertions, 8 deletions
diff --git a/src/pyramid/config/assets.py b/src/pyramid/config/assets.py index 6f2ddbe4a..3c6a8d360 100644 --- a/src/pyramid/config/assets.py +++ b/src/pyramid/config/assets.py @@ -122,6 +122,12 @@ class PackageOverrides: if o is not None: yield o + def get_spec(self, resource_name): + for source, path in self.filtered_sources(resource_name): + result = source.get_spec(path) + if result is not None: + return result + def get_filename(self, resource_name): for source, path in self.filtered_sources(resource_name): result = source.get_filename(path) @@ -223,6 +229,11 @@ class PackageAssetSource: def get_path(self, resource_name): return f'{self.prefix}{resource_name}' + def get_spec(self, resource_name): + path = self.get_path(resource_name) + if pkg_resources.resource_exists(self.pkg_name, path): + return f'{self.pkg_name}:{path}' + def get_filename(self, resource_name): path = self.get_path(resource_name) if pkg_resources.resource_exists(self.pkg_name, path): @@ -270,6 +281,9 @@ class FSAssetSource: path = self.prefix return path + def get_spec(self, resource_name): + return self.get_filename(resource_name) + def get_filename(self, resource_name): path = self.get_path(resource_name) if os.path.exists(path): diff --git a/src/pyramid/config/views.py b/src/pyramid/config/views.py index fababf542..302704c3e 100644 --- a/src/pyramid/config/views.py +++ b/src/pyramid/config/views.py @@ -2338,14 +2338,7 @@ class StaticURLInfo: pathspec = f'{pkg_name}:{pkg_subpath}{subpath}' overrides = registry.queryUtility(IPackageOverrides, name=pkg_name) if overrides is not None: - resource_name = posixpath.join(pkg_subpath, subpath) - sources = overrides.filtered_sources(resource_name) - for source, filtered_path in sources: - rawspec = source.get_path(filtered_path) - if hasattr(source, 'pkg_name'): - rawspec = f'{source.pkg_name}:{rawspec}' - break - + rawspec = overrides.get_spec(f'{pkg_subpath}{subpath}') else: pathspec = pkg_subpath + subpath @@ -2354,6 +2347,7 @@ class StaticURLInfo: kw['pathspec'] = pathspec kw['rawspec'] = rawspec + print(kw) for spec_, cachebust, explicit in reversed(self.cache_busters): if (explicit and rawspec.startswith(spec_)) or ( not explicit and pathspec.startswith(spec_) diff --git a/src/pyramid/interfaces.py b/src/pyramid/interfaces.py index 4ee294189..063b0385e 100644 --- a/src/pyramid/interfaces.py +++ b/src/pyramid/interfaces.py @@ -1079,6 +1079,14 @@ class IPEP302Loader(Interface): class IPackageOverrides(IPEP302Loader): """Utility for pkg_resources overrides""" + def get_spec(resource_name): + """Return a specifier for the resource. + + The specifier may be a dotted Python name or an absolute path on the + filesystem. + + """ + # VH_ROOT_KEY is an interface; its imported from other packages (e.g. # traversalwrapper) |
