Skip to content

Commit

Permalink
Revert version changes & figure out how to indent without py3.9 or lx…
Browse files Browse the repository at this point in the history
…ml>=4.5
  • Loading branch information
ceholden committed Jan 8, 2025
1 parent 16407a6 commit 359a6ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 11 additions & 7 deletions hls_vi/generate_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import sys
from xml.dom import minidom

from datetime import datetime, timezone
from pathlib import Path
Expand Down Expand Up @@ -136,22 +137,25 @@ def generate_metadata(input_dir: Path, output_dir: Path) -> None:
input_granule_ur,
)

# ensure any added attributes are indented
ET.indent(tree)

with (
importlib_resources.files("hls_vi")
/ "schema"
/ "Granule.xsd" # pyright: ignore[reportOperatorIssue]
).open() as xsd:
ET.XMLSchema(file=xsd).assertValid(tree)

tree.write(
str(output_dir / metadata_path.name.replace("HLS", "HLS-VI")),
encoding="utf-8",
xml_declaration=True,
# Python 3.9 or `lxml==4.5` add an `indent()` function to nicely format our XML
# Alas we cannot use those yet, so rely on this approach using `xml.dom.minidom`
dom = minidom.parseString(
ET.tostring(tree, xml_declaration=True, pretty_print=False)
)
pretty_xml = os.linesep.join(
[line for line in dom.toprettyxml(indent=" ").splitlines() if line.strip()]
)

dest = output_dir / metadata_path.name.replace("HLS", "HLS-VI")
dest.write_text(pretty_xml, encoding="utf-8")


def normalize_additional_attributes(container: ElementBase) -> None:
"""Normalize additional attribute values.
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
"dataclasses",
"geojson",
"importlib_resources",
"lxml==5.3.0",
# 1.19 is latest for our container, but ~1.19 allows
# a more recent 1.x version for our host
"numpy~=1.19",
"lxml==3.6.0",
"numpy~=1.19.0",
"pystac[validation]==1.0.0rc2",
"rasterio",
"shapely",
Expand Down

0 comments on commit 359a6ae

Please sign in to comment.