diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5d24249 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38e2818..032b6fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,13 +12,13 @@ on: # cf. https://github.community/t/how-to-trigger-an-action-on-push-or-pull-r jobs: check: name: Run check - runs-on: ubuntu-latest strategy: fail-fast: false max-parallel: 5 matrix: python-version: [3.8, 3.9, '3.10', '3.11'] - + platform: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.platform }} steps: - name: Checkout code 🛎️ uses: actions/checkout@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 01d1086..f5b5ad2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: additional_dependencies: - mdformat-toc - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.5.3 + rev: master hooks: - id: forbid-crlf - id: remove-crlf diff --git a/README.md b/README.md index 437ade9..29820ee 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ A few useful git hooks to integrate with [pre-commit](http://pre-commit.com). ⚠️ ⚠️ **This hook, since v1.5.2, requires `pre-commit` 3.2.0 or superior.** -If you get an error like `Expected one of ... but got: 'pre-commit'`, check this issue: [#83](https://github.com/Lucas-C/pre-commit-hooks/issues/83) +If you get an error like `Expected one of ... but got: 'pre-commit'`, check +this issue: [#83](https://github.com/Lucas-C/pre-commit-hooks/issues/83) ⚠️ **The last version of this hook to support Python 2.7 & 3.6 is v1.1.15** diff --git a/pre_commit_hooks/chmod.py b/pre_commit_hooks/chmod.py index 0e63939..1e8ecab 100644 --- a/pre_commit_hooks/chmod.py +++ b/pre_commit_hooks/chmod.py @@ -39,17 +39,20 @@ def main(argv=None): print(f"Incorrect octal permissions provided in configuration: {error}") return 2 result = 0 - for filename in args.filenames: - current_mode = os.stat(filename).st_mode - # We ignore S_IFREG and other similar unsupported bits: - current_mode &= SUPPORTED_BITS - if current_mode != new_mode: - print( - f"Fixing file permissions on {filename}:" - f" 0o{current_mode:o} -> 0o{new_mode:o}" - ) - os.chmod(filename, new_mode) - result = 1 + if sys.platform == "win32": + print("This hook does nothing when executed on Windows") + else: + for filename in args.filenames: + current_mode = os.stat(filename).st_mode + # We ignore S_IFREG and other similar unsupported bits: + current_mode &= SUPPORTED_BITS + if current_mode != new_mode: + print( + f"Fixing file permissions on {filename}:" + f" 0o{current_mode:o} -> 0o{new_mode:o}" + ) + os.chmod(filename, new_mode) + result = 1 return result diff --git a/tests/chmod_test.py b/tests/chmod_test.py index 2168587..ec43da3 100644 --- a/tests/chmod_test.py +++ b/tests/chmod_test.py @@ -1,13 +1,21 @@ +import sys from pre_commit_hooks.chmod import main as chmod -from .utils import chdir_to_test_resources +from .utils import chdir_to_test_resources, capture_stdout def test_chmod_ok(): with chdir_to_test_resources(): - assert chmod(["755", "module_with_license.py"]) == 1 - assert chmod(["644", "module_with_license.py"]) == 1 - assert chmod(["644", "module_with_license.py"]) == 0 + if sys.platform == "win32": + with capture_stdout() as stdout: + assert chmod(["755", "module_with_license.py"]) == 0 + assert ( + "This hook does nothing when executed on Windows" in stdout.getvalue() + ) + else: + assert chmod(["755", "module_with_license.py"]) == 1 + assert chmod(["644", "module_with_license.py"]) == 1 + assert chmod(["644", "module_with_license.py"]) == 0 def test_invalid_perms():