-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,5 @@ modules: | |
# for nodejs:10, ship all profiles | ||
- name: nodejs | ||
stream: 10 | ||
- name: something-else | ||
stream: 1.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
from .gitlab import GitlabLoader | ||
from .local import LocalLoader | ||
from ubiconfig.utils.yaml_dec_constructor import add_yaml_dec_constructor | ||
|
||
__all__ = ['GitlabLoader', 'LocalLoader'] | ||
|
||
add_yaml_dec_constructor() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from yaml.constructor import SafeConstructor | ||
from decimal import Decimal | ||
|
||
|
||
def construct_yaml_dec(self, node): | ||
""" | ||
Replaces yaml's float constructor, which would remove any trailing zeros | ||
from numbers using decimals, compromising data integrity. | ||
""" | ||
|
||
value = str(self.construct_scalar(node)) | ||
value = value.replace('_', '').lower() | ||
sign = +1 | ||
if value[0] == '-': | ||
sign = -1 | ||
if value[0] in '+-': | ||
value = value[1:] | ||
if value == '.inf': | ||
return sign*self.inf_value | ||
elif value == '.nan': | ||
return self.nan_value | ||
elif ':' in value: | ||
digits = [Decimal(part) for part in value.split(':')] | ||
digits.reverse() | ||
base = 1 | ||
value = 0.0 | ||
for digit in digits: | ||
value += digit*base | ||
base *= 60 | ||
return sign*value | ||
else: | ||
return sign*Decimal(value) | ||
|
||
|
||
def add_yaml_dec_constructor(): | ||
SafeConstructor.add_constructor(u'tag:yaml.org,2002:float', construct_yaml_dec) |