Skip to content

fix: consolidate data file locations to follow XDG Base Directory Specification#77

Merged
shreyasmene06 merged 7 commits into
shreyasmene06:mainfrom
swarnimbandekar:feat/xdg-directory-compliance
May 21, 2026
Merged

fix: consolidate data file locations to follow XDG Base Directory Specification#77
shreyasmene06 merged 7 commits into
shreyasmene06:mainfrom
swarnimbandekar:feat/xdg-directory-compliance

Conversation

@swarnimbandekar
Copy link
Copy Markdown
Contributor

@swarnimbandekar swarnimbandekar commented May 10, 2026

Moves data files from $HOME to proper XDG directories:
fixes #76

Before After
~/.pyvm_history.json ~/.local/share/pyvm/history.json
~/.pyvm_metadata.sqlite ~/.cache/pyvm/metadata.sqlite
~/.pyvm/venvs/ ~/.local/share/pyvm/venvs/
~/.pyvm/venvs.json ~/.local/share/pyvm/venvs.json

On Windows everything goes to %LOCALAPPDATA%/pyvm/.

Existing files are automatically migrated on first run. Migration only runs once and logs what it moved.

Also respects XDG_*_HOME env vars if set.

Testing: All 64 tests pass, including 15 new ones for path resolution and migration.

GSSoC26

…ecification

- Add paths.py module with XDG-compliant path resolution
- Migrate legacy paths (~/.pyvm_history.json, ~/.pyvm_metadata.sqlite, ~/.pyvm/) to XDG locations
- On Linux/macOS: config in ~/.config/pyvm, data in ~/.local/share/pyvm, cache in ~/.cache/pyvm
- On Windows: all paths use %LOCALAPPDATA%/pyvm
- Update constants.py, config.py, venv.py to use new path helpers
- Wire migration into CLI entry point for automatic one-time migration
- Add comprehensive tests for path resolution and migration
@swarnimbandekar swarnimbandekar changed the title XDG Base Directory compliance fix: consolidate data file locations to follow XDG Base Directory Specification May 10, 2026
@shreyasmene06 shreyasmene06 self-requested a review May 15, 2026 08:38
Copy link
Copy Markdown
Owner

@shreyasmene06 shreyasmene06 left a comment

Choose a reason for hiding this comment

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

@swarnimbandekar please make sure the checks are passed

Copy link
Copy Markdown
Owner

@shreyasmene06 shreyasmene06 left a comment

Choose a reason for hiding this comment

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

The XDG migration logic can lose user data in conflict cases:

  1. _move_file: if destination already exists, it deletes the legacy source (src.unlink()), which can discard data.
  2. _move_directory: when destination exists, conflicting items are skipped, then source dir is removed (rmtree), so
    skipped/conflicting files can be lost.

Please make migration conflict-safe (no destructive delete of source on conflict), and add tests for “destination already
exists / partial overlap” cases before merge.

@swarnimbandekar swarnimbandekar marked this pull request as draft May 18, 2026 17:01
@swarnimbandekar
Copy link
Copy Markdown
Contributor Author

swarnimbandekar commented May 18, 2026

fix:
Resolved silent data loss issues during migration to XDG-compliant locations by ensuring that when destination files or directories already exist, legacy data is preserved in place (not deleted), and only non-conflicting items are moved. Added safety checks so migration does not mark as complete if conflicts occur, enabling retries. Relevant tests have been added and all pass.

@swarnimbandekar swarnimbandekar marked this pull request as ready for review May 18, 2026 17:10
Copy link
Copy Markdown
Owner

@shreyasmene06 shreyasmene06 left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes. The previous conflict/data-loss issue looks addressed and CI is green, but I still see one blocker
before merge.

When migrating ~/.pyvm/venvs and ~/.pyvm/venvs.json, the registry file is moved as-is. Existing registry entries can
still contain absolute paths under the legacy root, e.g. ~/.pyvm/venvs/myenv, while the actual venv directory has been
moved to the new XDG location, e.g. ~/.local/share/pyvm/venvs/myenv.

That would make migrated venvs appear missing or fail activation/removal because venv.py trusts the stored registry path.

Please update the migration to rewrite registry entry paths from the old venv root to the new venv root, and add a test
covering an existing venvs.json entry with an absolute legacy path.

Also minor: README.md line 251 has trailing whitespace (git diff --check catches it).

Copy link
Copy Markdown
Owner

@shreyasmene06 shreyasmene06 left a comment

Choose a reason for hiding this comment

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

LGTM!
Thank you for your contribution

@shreyasmene06 shreyasmene06 merged commit 9012fd3 into shreyasmene06:main May 21, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate data file locations to follow XDG Base Directory Specification

2 participants