Skip to content

Conversation

@ana-sher
Copy link

@ana-sher ana-sher commented Nov 14, 2025

Prevent fixing symlink file
resolves #1143 LICENSE.txt fixing issue with end-of-file-fixer hook on Windows


📚 Documentation preview 📚: https://earthaccess--1144.org.readthedocs.build/en/1144/

@github-actions
Copy link

github-actions bot commented Nov 14, 2025

Binder 👈 Launch a binder notebook on this branch for commit 1a7922d

I will automatically update this comment whenever this PR is modified

Binder 👈 Launch a binder notebook on this branch for commit 906cf98

Binder 👈 Launch a binder notebook on this branch for commit 05fbfba

Binder 👈 Launch a binder notebook on this branch for commit b2f30e4

@ana-sher ana-sher marked this pull request as ready for review November 14, 2025 21:11
Comment on lines 16 to 17
- id: check-added-large-files
# Check for common mistakes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @ana-sher! It looks like you may have forgotten to skip the yamlfmt hook when you committed your change, but I think that's because you used VSCode to commit this change, rather than making the commit from the command line, where you would be able to specify SKIP.

Can you revert the changes in this file, other than the single line for excluding docs/LICENSE.txt?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you @chuckwondo, yes, that's exactly what happened 💯 Reverted and fixed by running from the command line.

@chuckwondo
Copy link
Collaborator

@ana-sher, thanks again for your first contribution!

It looks like your branch is out of date with the main branch. Can you pull in the latest changes from main?

@ana-sher ana-sher requested a review from chuckwondo November 14, 2025 22:00
@chuckwondo
Copy link
Collaborator

Much better :-)

I think I found a solution to the yamlfmt issue, if you want to give it a try. It works for me, but that's because I'm running macOS, so if you want to try the following on your Windows machine, that would be great.

If it works, I'd like you to add it to this PR so that it is a complete fix for #1143.

Please do the following:

First, create a file named scripts/yamlfmt.py (the scripts directory already exists in the repo), with the following contents:

"""Helper script that automatically skips the yamlfmt pre-commit hook on Windows.

This is not intended to be called directly.  It is configured to be called by
pre-commit via the configuration in .pre-commit-config.yml for the yamlfmt hook.

Due to https://github.com/google/yamlfmt/issues/263, comments in yaml files are
not handled properly under Windows, so any Windows user that causes yamlfmt to
format yaml files will cause CI build failure because we build under Linux, and
the resulting format will differ, causing file changes during the pre-commit
step, causing build failure.

Therefore, this script avoids calling yamlfmt (via pre-commit) when running on
Windows.
"""
import platform
import subprocess
import sys

if platform.system() != "Windows":
    sys.exit(subprocess.call(["yamlfmt", *sys.argv[1:]]))

Then, modify the yamlfmt hook configuration in .pre-commit-config.yml to look like so:

  - repo: https://github.com/google/yamlfmt
    rev: v0.20.0
    hooks:
      - id: yamlfmt
        entry: python scripts/yamlfmt.py
        types_or: [yaml]
        exclude: ".*/vcr_cassettes/.*\\.yaml"

Notice that I've added entry to that section, which will call the script above, rather than calling yamlfmt directly.

Once you've added the new script and modified the pre-commit config, try running pre-commit run -a again (without setting SKIP) to see if it leaves the yaml files unchanged. If so, then please commit the new changes to this PR.

@ana-sher
Copy link
Author

It is a good way to solve it until google/yamlfmt#263 will be fixed! Worked as intended on my Windows machine, thank you @chuckwondo , added script to the PR.

@mfisher87 mfisher87 changed the title Prevent fixing symlink file Prevent formatting symlink file Nov 15, 2025
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.

[BUG] pre-commit on Windows modifying main branch files

2 participants