maintainers/scripts/update-typst-packages.py: Skip packages that cannot be found in the registry
This commit is contained in:
@@ -78,7 +78,14 @@ class TypstPackage:
|
|||||||
"nix-command",
|
"nix-command",
|
||||||
]
|
]
|
||||||
result = subprocess.run(cmd + [url], capture_output=True, text=True)
|
result = subprocess.run(cmd + [url], capture_output=True, text=True)
|
||||||
hash = re.search(r"hash\s+\'(sha256-.{44})\'", result.stderr).groups()[0]
|
# We currently rely on Typst Universe's github repository to
|
||||||
|
# track package dependencies. However, there might be an
|
||||||
|
# inconsistency between the registry and the repository. We
|
||||||
|
# skip packages that cannot be fetched from the registry.
|
||||||
|
if re.search(r"error: unable to download", result.stderr):
|
||||||
|
return url, None
|
||||||
|
else:
|
||||||
|
hash = re.search(r"hash\s+\'(sha256-.{44})\'", result.stderr).groups()[0]
|
||||||
return url, hash
|
return url, hash
|
||||||
|
|
||||||
def to_name_full(self):
|
def to_name_full(self):
|
||||||
@@ -86,10 +93,14 @@ class TypstPackage:
|
|||||||
|
|
||||||
def to_attrs(self):
|
def to_attrs(self):
|
||||||
deps = set()
|
deps = set()
|
||||||
excludes = list(map(
|
excludes = list(
|
||||||
lambda e: os.path.join(self.path, e),
|
map(
|
||||||
self.meta["package"]["exclude"] if "exclude" in self.meta["package"] else [],
|
lambda e: os.path.join(self.path, e),
|
||||||
))
|
self.meta["package"]["exclude"]
|
||||||
|
if "exclude" in self.meta["package"]
|
||||||
|
else [],
|
||||||
|
)
|
||||||
|
)
|
||||||
for root, _, files in os.walk(self.path):
|
for root, _, files in os.walk(self.path):
|
||||||
for file in filter(lambda f: f.split(".")[-1] == "typ", files):
|
for file in filter(lambda f: f.split(".")[-1] == "typ", files):
|
||||||
file_path = os.path.join(root, file)
|
file_path = os.path.join(root, file)
|
||||||
@@ -110,6 +121,9 @@ class TypstPackage:
|
|||||||
)
|
)
|
||||||
source_url, source_hash = self.source()
|
source_url, source_hash = self.source()
|
||||||
|
|
||||||
|
if not source_hash:
|
||||||
|
return None
|
||||||
|
|
||||||
return dict(
|
return dict(
|
||||||
url=source_url,
|
url=source_url,
|
||||||
hash=source_hash,
|
hash=source_hash,
|
||||||
@@ -152,11 +166,12 @@ def generate_typst_packages(preview_dir, output_file):
|
|||||||
def generate_package(pname, package_subtree):
|
def generate_package(pname, package_subtree):
|
||||||
sorted_keys = sorted(package_subtree.keys(), key=Version, reverse=True)
|
sorted_keys = sorted(package_subtree.keys(), key=Version, reverse=True)
|
||||||
print(f"Generating metadata for {pname}")
|
print(f"Generating metadata for {pname}")
|
||||||
return {
|
version_set = OrderedDict(
|
||||||
pname: OrderedDict(
|
(k, a)
|
||||||
(k, package_subtree[k].to_attrs()) for k in sorted_keys
|
for k, a in [(k, package_subtree[k].to_attrs()) for k in sorted_keys]
|
||||||
)
|
if a is not None
|
||||||
}
|
)
|
||||||
|
return {pname: version_set} if len(version_set) > 0 else {}
|
||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
|
||||||
sorted_packages = sorted(package_tree.items(), key=lambda x: x[0])
|
sorted_packages = sorted(package_tree.items(), key=lambda x: x[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user