use defaults for download cache and logs location#12
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR standardizes where laser-init stores downloaded data and log files by centralizing default cache/log directories in config.py and updating callers to use those defaults.
Changes:
- Add
default_cache_directoryanddefault_log_directoryconstants tosrc/laser/init/config.pyand consume them across the package. - Switch extractors and provenance tracking to default to the shared cache directory (instead of
Path.cwd()in several extractors). - Switch logging to default to the shared log directory.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/laser/init/utils.py |
Uses centralized default cache directory for provenance lookup. |
src/laser/init/logger.py |
Uses centralized default log directory for file logging output. |
src/laser/init/extractors/worldpop.py |
Defaults WorldPop cache location to centralized cache directory. |
src/laser/init/extractors/unwpp.py |
Defaults UNWPP cache location to centralized cache directory. |
src/laser/init/extractors/unocha.py |
Defaults UNOCHA cache location to centralized cache directory. |
src/laser/init/extractors/geoboundaries.py |
Defaults GeoBoundaries cache location to centralized cache directory. |
src/laser/init/extractors/gadm.py |
Defaults GADM cache location to centralized cache directory. |
src/laser/init/config.py |
Introduces default cache/log directory constants and adds logic to write a default config file when none is found. |
Comments suppressed due to low confidence (2)
src/laser/init/config.py:147
yaml.safe_load()(andjson.loads()) can returnNoneor a non-dict value (e.g., empty YAML file). The rest of the codebase treatsconfigurationas a dict and calls.get(...), so this can lead to anAttributeErrorat runtime. After loading, normalize withconfiguration = configuration or {}and ideally validateisinstance(configuration, dict)(otherwise warn and fall back to{}).
for path in candidates:
if path.is_file():
if path.suffix.lower() == ".yaml":
try:
configuration = yaml.safe_load(path.read_text())
except yaml.YAMLError as e:
src/laser/init/utils.py:302
update_local_provenancereadsprovenance.jsonunconditionally (provenance_file.read_text()), which will raiseFileNotFoundErrorif the cache provenance hasn’t been created yet (or was deleted) even though downstream transforms call this unconditionally. Consider mirroringupdate_cache_provenance’s pattern: if the provenance file doesn’t exist, treatsourcesas{}and either skip missing records or raise a clearer error explaining how to regenerate the cache provenance.
cache_root = Path(config.get("cache_dir", default_cache_directory))
provenance_file = cache_root / "provenance.json"
sources = json.loads(provenance_file.read_text())
provenance_local = output_dir / "provenance.json"
provenance = json.loads(provenance_local.read_text() if provenance_local.exists() else "{}")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Update .gitignore for common test countries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.