Skip to content

Remove atomicwrites dependency, use stdlib tempfile + os.replace#173

Open
dhruvildarji wants to merge 1 commit intocommaai:masterfrom
dhruvildarji:fix/missing-dependency-setup
Open

Remove atomicwrites dependency, use stdlib tempfile + os.replace#173
dhruvildarji wants to merge 1 commit intocommaai:masterfrom
dhruvildarji:fix/missing-dependency-setup

Conversation

@dhruvildarji
Copy link
Copy Markdown

Summary

  • Replace the deprecated atomicwrites library with stdlib tempfile.NamedTemporaryFile + os.replace/os.link
  • Remove atomicwrites from pyproject.toml dependencies and requirements_examples.txt
  • Preserves atomic write safety: writes to a temp file in the same directory, then renames atomically

Approach

As suggested in #118, atomicwrites is deprecated and the author recommends using os.replace / os.rename instead. This PR:

  1. First usage (writing attempt timestamp): Uses NamedTemporaryFile + os.replace for atomic overwrite
  2. Second usage (writing downloaded data): Uses NamedTemporaryFile + os.replace (when overwrite=True) or os.link (when overwrite=False, which raises FileExistsError if the file already exists, matching the previous behavior)

Both patterns write to a temp file in the same directory (ensuring same filesystem) before atomically moving into place, which is safe for concurrent downloads.

Test plan

  • Verified no remaining references to atomicwrites in the codebase
  • The atomic write pattern (temp file + rename) is the same approach used previously in this codebase before atomicwrites was introduced

Fixes #118

Replace the deprecated `atomicwrites` library with stdlib
`tempfile.NamedTemporaryFile` + `os.replace`/`os.link` for atomic
file writes. This removes an unnecessary third-party dependency
while preserving the same race-condition safety.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing dependency in setup.py

1 participant