pallets / pallets/click

Feature to only update atomic file when changed

Open
#1,378 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

parsing
Dominant language
Python
Stars
17.7k
Forks
2.3k
Avg merge
1d 30m
Merged PRs (30d)
18

Description

I have various programs that are generating source files for use in a C project build. Often these files get generated the same each time but since they are written regardless they trigger cascading rebuilds of that file and those that depend on it.

https://github.com/pallets/click/blob/38a2712d596a5df9288c1817748b71197d8c7c57/click/_compat.py#L536-L546

I didn't implement it yet but it seems like it wouldn't be particularly difficult to add a changed check right after self._f.close(). Perhaps right before to avoid reopening the new content? I would not expect this changed check to be atomic with the replace. Maybe there's a way. It not being atomic isn't an issue for me. If two things are trying to dump into the file 'at the same time'... so it goes.

The 'only if changed' option would then be cascaded back up at least to the click.File() interface. Though having only_write_if_changed be always present but only usable with atomic=True isn't great so probably more to talk about there. A separate callable, something else, I haven't thought this through yet.

Does this sound like a feature which would be of interest and is worth me developing a PR to discuss? Or, should I just go implement this for myself on the side without bothering to have so much click integration.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing click/_compat.py at lines 536-546 and tracing how the atomic file behavior is exposed through click.File. Clarify the option’s API and whether it applies only with atomic=True. Done means unchanged generated content does not trigger a replacement while the proposed click.File integration is coherent.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.