Skip to content

Commit

Permalink
Fix file comparison for pre-commit hooks (#177)
Browse files Browse the repository at this point in the history
* Fix comparison between file contents

* Bump version
  • Loading branch information
mondeja committed Nov 7, 2021
1 parent b26aca0 commit d58921d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.71
current_version = 0.3.72

[bumpversion:file:mdpo/__init__.py]

Expand Down
10 changes: 5 additions & 5 deletions docs/pre-commit-hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ so you don't need to specify them.
.. code-block:: yaml
- repo: https://github.com/mondeja/mdpo
rev: v0.3.71
rev: v0.3.72
hooks:
- id: md2po
args:
Expand Down Expand Up @@ -43,7 +43,7 @@ po2md
.. code-block:: yaml
- repo: https://github.com/mondeja/mdpo
rev: v0.3.71
rev: v0.3.72
hooks:
- id: po2md
args:
Expand All @@ -56,7 +56,7 @@ po2md
.. code-block:: yaml
- repo: https://github.com/mondeja/mdpo
rev: v0.3.71
rev: v0.3.72
hooks:
- id: po2md
files: README\.md
Expand All @@ -75,7 +75,7 @@ md2po2md
.. code-block:: yaml
- repo: https://github.com/mondeja/mdpo
rev: v0.3.71
rev: v0.3.72
hooks:
- id: md2po2md
args:
Expand All @@ -88,7 +88,7 @@ md2po2md
.. code-block:: yaml
- repo: https://github.com/mondeja/mdpo
rev: v0.3.71
rev: v0.3.72
hooks:
- id: md2po2md
files: README\.md
Expand Down
2 changes: 1 addition & 1 deletion mdpo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from mdpo.po2md import pofile_to_markdown


__version__ = '0.3.71'
__version__ = '0.3.72'
__title__ = 'mdpo'
__description__ = ('Markdown files translation using PO files.')
__all__ = (
Expand Down
12 changes: 3 additions & 9 deletions mdpo/io.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
"""mdpo I/O utilities."""

import filecmp
import glob
import os
import re
import tempfile


MDPO_FILECMP_TEMPFILE = os.path.join(tempfile.gettempdir(), '__mpdo-filecmp')


def filter_paths(filepaths, ignore_paths=[]):
Expand Down Expand Up @@ -104,9 +99,8 @@ def save_file_checking_file_changed(filepath, content, encoding='utf-8'):
f.write(content)
return True

with open(MDPO_FILECMP_TEMPFILE, 'w') as temp_f, open(filepath) as f:
temp_f.write(f.read())
with open(filepath) as f:
prev_content = f.read()
with open(filepath, 'w', encoding=encoding) as f:
f.write(content)

return filecmp.cmp(MDPO_FILECMP_TEMPFILE, filepath)
return content != prev_content
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = mdpo
version = 0.3.71
version = 0.3.72
description = Markdown files translation using PO files.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit d58921d

Please sign in to comment.