-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buildsystem optimization #8588
Buildsystem optimization #8588
Conversation
|
f42c54d
to
9dc2100
Compare
Unfortunately, I have found that there are situations in which this causes incorrect form of data in the built data stream. For example, in ssg-rhel8-ds.xml the Ansible remediation for rule accounts_password_pam_minlen contains |
ssg/yaml.py
Outdated
@@ -121,7 +125,7 @@ def open_raw(yaml_file): | |||
return yaml_contents | |||
|
|||
|
|||
def ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict): | |||
def ordered_load(stream, Loader=yaml_SafeLoader, object_pairs_hook=OrderedDict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there is the "suspicious" line 33 which modifies yaml_SafeLoader
:
yaml_SafeLoader.add_constructor(u'tag:yaml.org,2002:bool', _bool_constructor)
But before your patch the yaml_SafeLoader
was used only in the _open_yaml
function. So this special modfication from line 33 affected only the _open_yaml
function. But, you start to use the yaml_SafeLoader
also here in ordered_load
, so now this special modification affects also the ordered_load
function.
If we would like to use yaml_SafeLoader
in both functions but keep the previous behavior of ordered_load
, we would have to rework it so that the special modification from line 33 would again affect only _open_yaml
. We can do that using a trick like this:
diff --git a/ssg/yaml.py b/ssg/yaml.py
index 71f7e3adee..601584a21d 100644
--- a/ssg/yaml.py
+++ b/ssg/yaml.py
@@ -29,8 +29,6 @@ def _unicode_constructor(self, node):
return str(string_like)
-# Don't follow python bool case
-yaml_SafeLoader.add_constructor(u'tag:yaml.org,2002:bool', _bool_constructor)
# Python2-relevant - become able to resolve "unicode strings"
yaml_SafeLoader.add_constructor(u'tag:yaml.org,2002:python/unicode', _unicode_constructor)
@@ -52,8 +50,13 @@ def _open_yaml(stream, original_file=None, substitutions_dict={}):
Return None if it contains "documentation_complete" key set to "false".
"""
+ class OurCustomLoader(yaml_SafeLoader):
+ pass
+
+ # Don't follow python bool case
+ OurCustomLoader.add_constructor(u'tag:yaml.org,2002:bool', _bool_constructor)
try:
- yaml_contents = yaml.load(stream, Loader=yaml_SafeLoader)
+ yaml_contents = yaml.load(stream, Loader=OurCustomLoader)
if yaml_contents.pop("documentation_complete", "true") == "false" and \
substitutions_dict.get("cmake_build_type") != "Debug":
I admit that I don't like that we have some special things like this yaml_SafeLoader.add_constructor(u'tag:yaml.org,2002:bool', _bool_constructor)
, it would be ideal to remove it, but that would be very very difficult because a lot of code depend on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for noticing this. From my testing, it seems this conversion was caused by using CSafeLoader
, when using CLoader
the issue is gone.
or it should contain |
…erted CDumper inserts three dots at the end of some ansible YAML remediations, which causes the utils/ansible_playbook_to_role.py script to fail when collecting the remediations from a playbook Apparently one YAML file should contain only one document, and when multiple documents denoted by '---' start of document or '...' end of document strings are inside one YAML file, yaml.load_all should be used instead of yaml.load function.
9dc2100
to
74d2270
Compare
Code Climate has analyzed commit 74d2270 and detected 2 issues on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 63.6% (50% is the threshold). This pull request will bring the total coverage in the repository to 42.8% (0.0% change). View more on Code Climate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I experience a smaller speedup, on my machine ~ 6 seconds, but that's a great achievement! Kudos
Description:
ssg/yaml.py
used bybuild-scripts/collect_remediations.py
Issues:
yaml.py/ordered_dump
does not work. This is seemingly because the underlying emitter classes are different foryaml.Dumper
andyaml.CDumper
, and while the former contains theincrease_indent
method, the latter does not (https://github.com/yaml/pyyaml/blob/8cdff2c80573b8be8e8ad28929264a913a63aa33/yaml/_yaml.pyx and https://github.com/yaml/pyyaml/blob/8cdff2c80573b8be8e8ad28929264a913a63aa33/lib/yaml/emitter.py, respectively). I found that some people had the exact same issue here: Indentation of sequence elements yaml/libyaml#224 and there was no response from the maintainers oflibyaml
. Althoughyamllint
says that some ansible tasks inbuild/rhel8/fixes/ansible
have invalid indentation, running the test suite on some of these ansible tasks (such as sssd_offline_cred_expiration) with the--remediate-using ansible
option produced no errors, so I am not sure if this is actually a problem. If needed, a simple regex substitution could be added to the ordered_dump function to add the extra indentation (modifying and recompilinglibyaml
seems needlessly complicated).