Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions glean_parser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
from typing import Any, Callable, Iterable, Sequence, Tuple, Union, Optional
import urllib.request

import diskcache # type: ignore
import jinja2
import jsonschema # type: ignore
from jsonschema import _utils # type: ignore
import platformdirs # type: ignore
import yaml

try:
Expand Down Expand Up @@ -283,33 +281,18 @@ def resolve_remote(self, uri):
return NullResolver.from_schema(schema)


def fetch_remote_url(url: str, cache: bool = True):
def fetch_remote_url(url: str):
"""
Fetches the contents from an HTTP url or local file path, and optionally
caches it to disk.
Fetches the contents from an HTTP url or local file path.
"""
# Include the Python version in the cache key, since caches aren't
# sharable across Python versions.
key = (url, str(sys.version_info))

is_http = url.startswith("http")

if not is_http:
with open(url, "r", encoding="utf-8") as fd:
return fd.read()

if cache:
cache_dir = platformdirs.user_cache_dir("glean_parser", "mozilla")
with diskcache.Cache(cache_dir, disk=diskcache.JSONDisk) as dc:
if key in dc:
return dc[key]

contents = urllib.request.urlopen(url).read().decode("utf-8")

if cache:
with diskcache.Cache(cache_dir, disk=diskcache.JSONDisk) as dc:
dc[key] = contents

return contents


Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ classifiers = [
requires-python = ">=3.9"
dependencies = [
"Click>=7",
"diskcache>=4",
"Jinja2>=2.10.1",
"jsonschema>=3.0.2",
"platformdirs>=2.4.0",
Expand Down
11 changes: 0 additions & 11 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading