diff --git a/omnibus/config/patches/datadog-agent-integrations-py2/create-regex-at-runtime.patch b/omnibus/config/patches/datadog-agent-integrations-py2/create-regex-at-runtime.patch new file mode 100644 index 0000000000000..24a4b6a4a8564 --- /dev/null +++ b/omnibus/config/patches/datadog-agent-integrations-py2/create-regex-at-runtime.patch @@ -0,0 +1,30 @@ +--- a/reader.py ++++ b/reader.py +@@ -71,6 +71,7 @@ class Reader(object): + self.index = 0 + self.line = 0 + self.column = 0 ++ self._non_printable = None + if isinstance(stream, unicode): + self.name = "" + self.check_printable(stream) +@@ -136,10 +137,15 @@ class Reader(object): + self.encoding = 'utf-8' + self.update(1) + +- if has_ucs4: +- NON_PRINTABLE = re.compile(u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD\U00010000-\U0010ffff]') +- else: +- NON_PRINTABLE = re.compile(u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]') ++ @property ++ def NON_PRINTABLE(self): ++ if self._non_printable is None: ++ if has_ucs4: ++ self._non_printable = re.compile(u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD\U00010000-\U0010ffff]') ++ else: ++ self._non_printable = re.compile(u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]') ++ return self._non_printable ++ + def check_printable(self, data): + match = self.NON_PRINTABLE.search(data) + if match: diff --git a/omnibus/config/software/datadog-agent-integrations-py2.rb b/omnibus/config/software/datadog-agent-integrations-py2.rb index 97f2810a12a7f..b6c697967b568 100644 --- a/omnibus/config/software/datadog-agent-integrations-py2.rb +++ b/omnibus/config/software/datadog-agent-integrations-py2.rb @@ -242,6 +242,14 @@ command "#{pip} install --no-deps .", :env => nix_build_env, :cwd => "#{project_dir}/#{check}" end end + + # Patch applies to only one file: set it explicitly as a target, no need for -p + if windows? + patch :source => "create-regex-at-runtime.patch", :target => "#{python_2_embedded}/Lib/site-packages/yaml/reader.py" + else + patch :source => "create-regex-at-runtime.patch", :target => "#{install_dir}/embedded/lib/python2.7/site-packages/yaml/reader.py" + end + end # Run pip check to make sure the agent's python environment is clean, all the dependencies are compatible @@ -255,5 +263,4 @@ # Used by the `datadog-agent integration` command to prevent downgrading a check to a version # older than the one shipped in the agent copy "#{project_dir}/requirements-agent-release.txt", "#{install_dir}/" - end diff --git a/releasenotes/notes/use-pyyaml-patch-for-costly-regex-97dc285e26288e03.yaml b/releasenotes/notes/use-pyyaml-patch-for-costly-regex-97dc285e26288e03.yaml new file mode 100644 index 0000000000000..1a703b944249f --- /dev/null +++ b/releasenotes/notes/use-pyyaml-patch-for-costly-regex-97dc285e26288e03.yaml @@ -0,0 +1,12 @@ +# Each section from every releasenote are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +fixes: + - | + Use a custom patch for a costly regex in PyYAML, + see ``_.