Skip to contentSkip to conversation

utils/check-package: warn about utf-8 characters in .mk files

PATCH New Peter Seiderer 4 participants 5 messages May 8, 2019 – May 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils/check-package: warn about utf-8 characters in .mk files

---
Note: is_ascii taken from one of the stackoverflow suggestions ([1])

[1] https://stackoverflow.com/questions/196345/how-to-check-if-a-string-in-python-is-in-ascii

---
 utils/checkpackagelib/lib.py    | 13 +++++++++++++
 utils/checkpackagelib/lib_mk.py |  1 +
 2 files changed, 14 insertions(+)
utils/checkpackagelib/lib.py +13 -0
index 6afe1aabce..c65a2ed939 100644
@@ -52,3 +52,16 @@ class TrailingSpace(_CheckFunction):
             return ["{}:{}: line contains trailing whitespace"
                     .format(self.filename, lineno),
                     text]
+
+class Utf8Characters(_CheckFunction):
+    def is_ascii(self, s):
+        try:
+            return all(ord(c) < 128 for c in s)
+        except TypeError:
+            return False
+
+    def check_line(self, lineno, text):
+        if not self.is_ascii(text):
+            return ["{}:{}: line contains UTF-8 characters"
+                    .format(self.filename, lineno),
+                    text]
utils/checkpackagelib/lib_mk.py +1 -0
index 00efeb7fb2..9e9a045776 100644
@@ -11,6 +11,7 @@ from checkpackagelib.lib import ConsecutiveEmptyLines  # noqa: F401
 from checkpackagelib.lib import EmptyLastLine          # noqa: F401
 from checkpackagelib.lib import NewlineAtEof           # noqa: F401
 from checkpackagelib.lib import TrailingSpace          # noqa: F401
+from checkpackagelib.lib import Utf8Characters         # noqa: F401
 
 # used in more than one check
 start_conditional = ["ifdef", "ifeq", "ifndef", "ifneq"]

--
2.21.0

#1 lore raw

PATCH 1/1 utils/check-package: warn about utf-8 characters in .mk files

Hi all,

Works as expected with both Py2 and Py3

Quoted 1 line · Peter Seiderer
Quoted 50 lines

---
Note: is_ascii taken from one of the stackoverflow suggestions ([1])

[1] https://stackoverflow.com/questions/196345/how-to-check-if-a-string-in-python-is-in-ascii

---
  utils/checkpackagelib/lib.py    | 13 +++++++++++++
  utils/checkpackagelib/lib_mk.py |  1 +
  2 files changed, 14 insertions(+)
utils/checkpackagelib/lib.py +13 -0
index 6afe1aabce..c65a2ed939 100644
@@ -52,3 +52,16 @@ class TrailingSpace(_CheckFunction):
              return ["{}:{}: line contains trailing whitespace"
                      .format(self.filename, lineno),
                      text]
+
+class Utf8Characters(_CheckFunction):
+    def is_ascii(self, s):
+        try:
+            return all(ord(c) < 128 for c in s)
+        except TypeError:
+            return False
+
+    def check_line(self, lineno, text):
+        if not self.is_ascii(text):
+            return ["{}:{}: line contains UTF-8 characters"
+                    .format(self.filename, lineno),
+                    text]
utils/checkpackagelib/lib_mk.py +1 -1
index 00efeb7fb2..9e9a045776 100644
@@ -11,6 +11,7 @@ from checkpackagelib.lib import ConsecutiveEmptyLines  # noqa: F401
  from checkpackagelib.lib import EmptyLastLine          # noqa: F401
  from checkpackagelib.lib import NewlineAtEof           # noqa: F401
  from checkpackagelib.lib import TrailingSpace          # noqa: F401
+from checkpackagelib.lib import Utf8Characters         # noqa: F401
 
  # used in more than one check
  start_conditional = ["ifdef", "ifeq", "ifndef", "ifneq"]
--

2.21.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

#2 lore raw

PATCH 1/1 utils/check-package: warn about utf-8 characters in .mk files

In reply to Peter Seiderer
Quoted 3 lines · On Wed, 8 May 2019 19:34:27 +0200 Peter Seiderer <[email protected]> wrote:

---
Note: is_ascii taken from one of the stackoverflow suggestions ([1])

Applied to master, thanks.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

PATCH 1/1 utils/check-package: warn about utf-8 characters in .mk files

In reply to Peter Seiderer

Peter, All,

On 2019-05-08 19:34 +0200, Peter Seiderer spake thusly:

Quoted 15 lines

---
Note: is_ascii taken from one of the stackoverflow suggestions ([1])

[1] https://stackoverflow.com/questions/196345/how-to-check-if-a-string-in-python-is-in-ascii

---
 utils/checkpackagelib/lib.py    | 13 +++++++++++++
 utils/checkpackagelib/lib_mk.py |  1 +
 2 files changed, 14 insertions(+)
utils/checkpackagelib/lib.py +0 -0
index 6afe1aabce..c65a2ed939 100644

utils/checkpackagelib/lib.py class TrailingSpace(_CheckFunction): · line 56

Quoted 5 lines
utils/checkpackagelib/lib.py +2 -0
@@ -52,3 +52,16 @@ class TrailingSpace(_CheckFunction):
             return ["{}:{}: line contains trailing whitespace"
                     .format(self.filename, lineno),
                     text]
+
+class Utf8Characters(_CheckFunction):

This breaks flake8:

utils/checkpackagelib/lib.py:56:1: E302 expected 2 blank lines, found 1

Regards,
Yann E. MORIN.

Quoted 30 lines
utils/checkpackagelib/lib.py +11 -0
+    def is_ascii(self, s):
+        try:
+            return all(ord(c) < 128 for c in s)
+        except TypeError:
+            return False
+
+    def check_line(self, lineno, text):
+        if not self.is_ascii(text):
+            return ["{}:{}: line contains UTF-8 characters"
+                    .format(self.filename, lineno),
+                    text]
utils/checkpackagelib/lib_mk.py +1 -1
index 00efeb7fb2..9e9a045776 100644
@@ -11,6 +11,7 @@ from checkpackagelib.lib import ConsecutiveEmptyLines  # noqa: F401
 from checkpackagelib.lib import EmptyLastLine          # noqa: F401
 from checkpackagelib.lib import NewlineAtEof           # noqa: F401
 from checkpackagelib.lib import TrailingSpace          # noqa: F401
+from checkpackagelib.lib import Utf8Characters         # noqa: F401
 
 # used in more than one check
 start_conditional = ["ifdef", "ifeq", "ifndef", "ifneq"]
--

2.21.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#4 lore raw

PATCH 1/1 utils/check-package: warn about utf-8 characters in .mk files

Hello Yann,

Quoted 26 lines · Yann E. MORIN

Peter, All,

On 2019-05-08 19:34 +0200, Peter Seiderer spake thusly:

Quoted 15 lines

---
Note: is_ascii taken from one of the stackoverflow suggestions ([1])

[1] https://stackoverflow.com/questions/196345/how-to-check-if-a-string-in-python-is-in-ascii

---
 utils/checkpackagelib/lib.py    | 13 +++++++++++++
 utils/checkpackagelib/lib_mk.py |  1 +
 2 files changed, 14 insertions(+)
utils/checkpackagelib/lib.py +0 -0
index 6afe1aabce..c65a2ed939 100644

utils/checkpackagelib/lib.py class TrailingSpace(_CheckFunction): · line 56

Quoted 5 lines
utils/checkpackagelib/lib.py +2 -0
@@ -52,3 +52,16 @@ class TrailingSpace(_CheckFunction):
             return ["{}:{}: line contains trailing whitespace"
                     .format(self.filename, lineno),
                     text]
+
+class Utf8Characters(_CheckFunction):

This breaks flake8:

Quoted 1 line

utils/checkpackagelib/lib.py:56:1: E302 expected 2 blank lines, found 1

Sorry, introduced due to my poor python formatting skills..., patch to fix it just send out...

Regards,
Peter

Quoted 35 lines

Regards,
Yann E. MORIN.

Quoted 30 lines
utils/checkpackagelib/lib.py +11 -0
+    def is_ascii(self, s):
+        try:
+            return all(ord(c) < 128 for c in s)
+        except TypeError:
+            return False
+
+    def check_line(self, lineno, text):
+        if not self.is_ascii(text):
+            return ["{}:{}: line contains UTF-8 characters"
+                    .format(self.filename, lineno),
+                    text]
utils/checkpackagelib/lib_mk.py +1 -1
index 00efeb7fb2..9e9a045776 100644
@@ -11,6 +11,7 @@ from checkpackagelib.lib import ConsecutiveEmptyLines  # noqa: F401
 from checkpackagelib.lib import EmptyLastLine          # noqa: F401
 from checkpackagelib.lib import NewlineAtEof           # noqa: F401
 from checkpackagelib.lib import TrailingSpace          # noqa: F401
+from checkpackagelib.lib import Utf8Characters         # noqa: F401
 
 # used in more than one check
 start_conditional = ["ifdef", "ifeq", "ifndef", "ifneq"]
--

2.21.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot