Skip to content

use defaults for download cache and logs location#12

Merged
clorton merged 2 commits into
mainfrom
config-defaults
Mar 31, 2026
Merged

use defaults for download cache and logs location#12
clorton merged 2 commits into
mainfrom
config-defaults

Conversation

@clorton

@clorton clorton commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@clorton clorton requested a review from Copilot March 30, 2026 21:19
@clorton clorton self-assigned this Mar 30, 2026
@clorton clorton added the bug Something isn't working label Mar 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_directory and default_log_directory constants to src/laser/init/config.py and 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() (and json.loads()) can return None or a non-dict value (e.g., empty YAML file). The rest of the codebase treats configuration as a dict and calls .get(...), so this can lead to an AttributeError at runtime. After loading, normalize with configuration = configuration or {} and ideally validate isinstance(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_provenance reads provenance.json unconditionally (provenance_file.read_text()), which will raise FileNotFoundError if the cache provenance hasn’t been created yet (or was deleted) even though downstream transforms call this unconditionally. Consider mirroring update_cache_provenance’s pattern: if the provenance file doesn’t exist, treat sources as {} 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.

Comment thread src/laser/init/config.py Outdated
Update .gitignore for common test countries.
@clorton clorton merged commit b79c35c into main Mar 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants