brainelectronics / micropython-modbus

MicroPython Modbus RTU Slave/Master and TCP Server/Slave library
GNU General Public License v3.0
104 stars 45 forks source link

Use git attributes for better python diff #76

Open wpyoga opened 1 year ago

wpyoga commented 1 year ago

Use .gitattributes file:

*.py diff=python

So that git diff shows the Python function name:

@@ -284,7 +284,7 @@ def _send_receive(self,

Instead of just the class name:

@@ -284,7 +284,7 @@ class Serial(CommonModbusFunctions):
brainelectronics commented 1 year ago

Isn't it the default? It seems so according to https://stackoverflow.com/a/18948381 I can also not see a difference after placing this file

wpyoga commented 1 year ago

Hmm... I've retested on my system:

$ git --version
git version 2.41.0

This is a git diff example without the .gitattributes entry:

$ git diff
diff --git a/umodbus/serial.py b/umodbus/serial.py
index 04e9c56..a78b29e 100644
--- a/umodbus/serial.py
+++ b/umodbus/serial.py
@@ -320,6 +320,8 @@ class Serial(CommonModbusFunctions):
         :returns:   Modbus response content
         :rtype:     bytes
         """
+        print("Response: {}".format(response.hex()))
+
         if len(response) == 0:
             raise OSError('no data received from slave')

This is the same command, with the .gitattributes entry:

$ git diff
diff --git a/umodbus/serial.py b/umodbus/serial.py
index 04e9c56..a78b29e 100644
--- a/umodbus/serial.py
+++ b/umodbus/serial.py
@@ -320,6 +320,8 @@ def _validate_resp_hdr(self,
         :returns:   Modbus response content
         :rtype:     bytes
         """
+        print("Response: {}".format(response.hex()))
+
         if len(response) == 0:
             raise OSError('no data received from slave')

How does it look like on your system? Do you have a ~/.gitconfig, ~/.config/git/config, or /etc/gitconfig file? I don't have any of those on my system.

Either way, this PR is not very important -- it only concerns git diff output.