summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-04 10:23:48 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-06-05 15:15:23 +0000
commitb2b740167cfb5f4359aecbf114deb5ff1af73b04 (patch)
tree299d3644228df9dc1ef104e13eee46543b485380
parent246571606853aef6da856d778f783b14339a2cea (diff)
downloadbuildstream-b2b740167cfb5f4359aecbf114deb5ff1af73b04.tar.gz
_loader/loader: cythonize valid_chars_name
- Create a new _loader/utils.pyx cython module for functions cythonized in the loader module. - Move valid_chars_name from loader to utils and cythonize. This function is called extensively, and easy to extract
-rw-r--r--.pylintrc5
-rwxr-xr-xsetup.py1
-rw-r--r--src/buildstream/_loader/_loader.pyx52
-rw-r--r--src/buildstream/_loader/loader.py33
4 files changed, 59 insertions, 32 deletions
diff --git a/.pylintrc b/.pylintrc
index e0941862f..c33aa48b8 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -3,7 +3,10 @@
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
-extension-pkg-whitelist=buildstream._variables,buildstream._yaml
+extension-pkg-whitelist=
+ buildstream._loader._loader,
+ buildstream._variables,
+ buildstream._yaml
# Add files or directories to the blacklist. They should be base names, not
# paths.
diff --git a/setup.py b/setup.py
index ed211dd09..e68dc383c 100755
--- a/setup.py
+++ b/setup.py
@@ -398,6 +398,7 @@ def register_cython_module(module_name, dependencies=None):
BUILD_EXTENSIONS = []
+register_cython_module("buildstream._loader._loader")
register_cython_module("buildstream._yaml")
register_cython_module("buildstream._variables", dependencies=["buildstream._yaml"])
diff --git a/src/buildstream/_loader/_loader.pyx b/src/buildstream/_loader/_loader.pyx
new file mode 100644
index 000000000..258a34ab7
--- /dev/null
+++ b/src/buildstream/_loader/_loader.pyx
@@ -0,0 +1,52 @@
+#
+# Copyright (C) 2019 Bloomberg L.P.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+#
+# Authors:
+# Benjamin Schubert <bschubert@bloomberg.net>
+#
+
+
+# Check if given filename containers valid characters.
+#
+# Args:
+# name (str): Name of the file
+#
+# Returns:
+# (bool): True if all characters are valid, False otherwise.
+#
+def valid_chars_name(str name):
+ cdef int char_value
+ cdef int forbidden_char
+
+ for char_value in name:
+ # 0-31 are control chars, 127 is DEL, and >127 means non-ASCII
+ if char_value <= 31 or char_value >= 127:
+ return False
+
+ # Disallow characters that are invalid on Windows. The list can be
+ # found at https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file
+ #
+ # Note that although : (colon) is not allowed, we do not raise
+ # warnings because of that, since we use it as a separator for
+ # junctioned elements.
+ #
+ # We also do not raise warnings on slashes since they are used as
+ # path separators.
+ for forbidden_char in '<>"|?*':
+ if char_value == forbidden_char:
+ return False
+
+ return True
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py
index 752883d96..5435e0d41 100644
--- a/src/buildstream/_loader/loader.py
+++ b/src/buildstream/_loader/loader.py
@@ -27,6 +27,7 @@ from ..element import Element
from .._profile import Topics, PROFILER
from .._includes import Includes
+from ._loader import valid_chars_name
from .types import Symbol
from .loadelement import LoadElement, _extract_depends_from_node
from .metaelement import MetaElement
@@ -759,7 +760,7 @@ class Loader():
for filename in elements:
if not filename.endswith(".bst"):
invalid_elements[CoreWarnings.BAD_ELEMENT_SUFFIX].append(filename)
- if not self._valid_chars_name(filename):
+ if not valid_chars_name(filename):
invalid_elements[CoreWarnings.BAD_CHARACTERS_IN_NAME].append(filename)
if invalid_elements[CoreWarnings.BAD_ELEMENT_SUFFIX]:
@@ -771,33 +772,3 @@ class Loader():
self._warn("Target elements '{}' have invalid characerts in their name."
.format(invalid_elements[CoreWarnings.BAD_CHARACTERS_IN_NAME]),
warning_token=CoreWarnings.BAD_CHARACTERS_IN_NAME)
-
- # Check if given filename containers valid characters.
- #
- # Args:
- # name (str): Name of the file
- #
- # Returns:
- # (bool): True if all characters are valid, False otherwise.
- #
- def _valid_chars_name(self, name):
- for char in name:
- char_val = ord(char)
-
- # 0-31 are control chars, 127 is DEL, and >127 means non-ASCII
- if char_val <= 31 or char_val >= 127:
- return False
-
- # Disallow characters that are invalid on Windows. The list can be
- # found at https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file
- #
- # Note that although : (colon) is not allowed, we do not raise
- # warnings because of that, since we use it as a separator for
- # junctioned elements.
- #
- # We also do not raise warnings on slashes since they are used as
- # path separators.
- if char in r'<>"|?*':
- return False
-
- return True