Skip to content

Unix.user_documents_dir ignores ensure_exists=True for XDG_DOCUMENTS_DIR #558

Closed

Description

@glaziermag

Unix(ensure_exists=True).user_documents_path returns the directory configured by XDG_DOCUMENTS_DIR without creating it or its parents. The same instance creates user_data_path as expected. Unix.user_documents_dir returns _get_user_media_dir(...) directly, bypassing _optionally_create_directory.

Reproduced against main at 6d287024230ad1c040e537cfd97ef8df6fd6b229, using an editable install:

import os
from pathlib import Path
from tempfile import TemporaryDirectory

from platformdirs.unix import Unix

with TemporaryDirectory() as root:
    base = Path(root)
    os.environ["XDG_DATA_HOME"] = str(base / "data")
    os.environ["XDG_DOCUMENTS_DIR"] = str(base / "parent" / "Documents")
    dirs = Unix(ensure_exists=True)
    data = dirs.user_data_path
    documents = dirs.user_documents_path
    print(f"user_data_path: exists={data.is_dir()}")
    print(f"user_documents_path: exists={documents.is_dir()}")
    assert documents.is_dir(), "ensure_exists did not create the documents directory"

Actual output:

user_data_path: exists=True
user_documents_path: exists=False
AssertionError: ensure_exists did not create the documents directory

Expected: both directories exist after property access. The ensure_exists parameter documentation says: “When True, the directory is created (including parents) when the property is accessed.” The implicated return is in Unix.user_documents_dir.

#550 explicitly left creation of media directories as a separate question; this is a minimal example of that remaining behavior. This report was prepared with AI assistance and checked against the source and the reproduction above.

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