Skip to content

import config2py creates ~/.config/config2py/configs at import time (split from #16, item 4) #26

Description

@thorwhalen

Split out of #16 (item 4).

Reproduction (verified 2026-09-26, config2py 0.1.54, Linux)

HOME=$(mktemp -d) python -c "import os, pathlib; import config2py; print(sorted(str(p.relative_to(os.environ['HOME'])) for p in pathlib.Path(os.environ['HOME']).rglob('*')))"
# ['.config', '.config/config2py', '.config/config2py/configs', '.config/config2py/configs/.config2py']

config2py/tools.py runs config_getter = simple_config_getter() and local_configs = get_configs_local_store() at module level, which create the folder and a marker file. This fails or surprises on read-only filesystems, sandboxed test runners and containers, and slows import config2py for callers who only need codecs or ConfigStore.

Why this was not changed unattended

config_getter, local_configs and configs are public, importable module attributes that dependents use directly. Making them lazy (module __getattr__) changes object identity and timing of the folder creation, which some dependents may rely on (they write into the folder right after import).

Proposed plan

  1. Replace the three module-level instances with a module-level __getattr__ in config2py/tools.py (and re-export through config2py/__init__.py via its own __getattr__), building them on first access and caching them.
  2. Test: importing config2py with HOME pointed at an empty temp dir creates nothing; first access to config2py.config_getter creates the folder.
  3. Run the dependents gate (fleet_dependents.json) before landing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions