mirror of
https://github.com/natelandau/obsidian-metadata.git
synced 2025-11-18 18:03:39 -05:00
fix: improve TOML error handing and docs for Windows paths (#31)
* fix: improve TOML error handing and documentation for Windows paths * build(linting): pash ruff v2.0.260
This commit is contained in:
@@ -77,10 +77,11 @@ class Config:
|
||||
VaultConfig(vault_name=key, vault_config=self.config[key]) for key in self.config
|
||||
]
|
||||
except TypeError as e:
|
||||
log.error(f"Configuration file is invalid: '{self.config_path}'")
|
||||
log.error(f"Configuration file is invalid: '{self.config_path}'\n{e}")
|
||||
raise typer.Exit(code=1) from e
|
||||
|
||||
log.debug(f"Loaded configuration from '{self.config_path}'")
|
||||
log.trace("Configuration:")
|
||||
log.trace(self.config)
|
||||
|
||||
def __rich_repr__(self) -> rich.repr.Result: # pragma: no cover
|
||||
@@ -91,10 +92,10 @@ class Config:
|
||||
def _load_config(self) -> dict[str, Any]:
|
||||
"""Load the configuration file."""
|
||||
try:
|
||||
with self.config_path.open(encoding="utf-8") as fp:
|
||||
with self.config_path.open(mode="rt", encoding="utf-8") as fp:
|
||||
return tomlkit.load(fp)
|
||||
except tomlkit.exceptions.TOMLKitError as e:
|
||||
alerts.error(f"Could not parse '{self.config_path}'")
|
||||
alerts.error(f"Could not parse '{self.config_path}'\n{e}")
|
||||
raise typer.Exit(code=1) from e
|
||||
|
||||
def _validate_config_path(self, config_path: Path | None) -> Path:
|
||||
@@ -117,6 +118,8 @@ class Config:
|
||||
["Vault 1"] # Name of the vault.
|
||||
|
||||
# Path to your obsidian vault
|
||||
# Note for Windows users: Windows paths must use `\\` as the path separator due to a limitation with how TOML parses strings.
|
||||
# Example: "C:\\Users\\username\\Documents\\Obsidian"
|
||||
path = "{vault_path}"
|
||||
|
||||
# Folders within the vault to ignore when indexing metadata
|
||||
|
||||
@@ -282,7 +282,9 @@ def remove_markdown_sections(
|
||||
return text
|
||||
|
||||
|
||||
def validate_csv_bulk_imports(csv_path: Path, note_paths: list) -> dict[str, list[dict[str, str]]]:
|
||||
def validate_csv_bulk_imports( # noqa: C901
|
||||
csv_path: Path, note_paths: list
|
||||
) -> dict[str, list[dict[str, str]]]:
|
||||
"""Validate the bulk import CSV file.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -319,7 +319,7 @@ class Vault:
|
||||
|
||||
return num_changed
|
||||
|
||||
def export_metadata(self, path: str, export_format: str = "csv") -> None:
|
||||
def export_metadata(self, path: str, export_format: str = "csv") -> None: # noqa: C901
|
||||
"""Write metadata to a csv file.
|
||||
|
||||
Args:
|
||||
@@ -333,7 +333,7 @@ class Vault:
|
||||
|
||||
match export_format:
|
||||
case "csv":
|
||||
with export_file.open(mode="w", encoding="UTF8") as f:
|
||||
with export_file.open(mode="w", encoding="utf-8") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(["Metadata Type", "Key", "Value"])
|
||||
|
||||
@@ -361,7 +361,7 @@ class Vault:
|
||||
"tags": self.metadata.tags,
|
||||
}
|
||||
|
||||
with export_file.open(mode="w", encoding="UTF8") as f:
|
||||
with export_file.open(mode="w", encoding="utf-8") as f:
|
||||
json.dump(dict_to_dump, f, indent=4, ensure_ascii=False, sort_keys=True)
|
||||
|
||||
def export_notes_to_csv(self, path: str) -> None:
|
||||
@@ -375,7 +375,7 @@ class Vault:
|
||||
alerts.error(f"Path does not exist: {export_file.parent}")
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
with export_file.open(mode="w", encoding="UTF8") as f:
|
||||
with export_file.open(mode="w", encoding="utf-8") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(["path", "type", "key", "value"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user