Skip to content

Commit 1a77f7b

Browse files
committed
Use saneyaml library
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent a4e31f1 commit 1a77f7b

File tree

7 files changed

+55
-253
lines changed

7 files changed

+55
-253
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def read(*names, **kwargs):
7070
'jinja2 >= 2.9, < 3.0',
7171
'click >= 6.7, < 7.0',
7272
"backports.csv ; python_version<'3.6'",
73-
'PyYAML >= 3.0, < 4.0',
73+
'PyYAML >= 3.11, <=3.13',
74+
'saneyaml',
7475
'boolean.py >= 3.5, < 4.0',
7576
'license_expression >= 0.94, < 1.0',
7677
],

src/attributecode/model.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@
5353
from urllib.error import HTTPError # NOQA
5454

5555
from license_expression import Licensing
56+
import saneyaml
5657

5758
from attributecode import CRITICAL
5859
from attributecode import ERROR
5960
from attributecode import INFO
6061
from attributecode import WARNING
6162
from attributecode import api
6263
from attributecode import Error
63-
from attributecode import saneyaml
6464
from attributecode import util
6565
from attributecode.util import add_unc
6666
from attributecode.util import copy_license_notice_files
@@ -1015,8 +1015,6 @@ def load(self, location, use_mapping=False, mapping_file=None):
10151015
loc = add_unc(loc)
10161016
with codecs.open(loc, encoding='utf-8') as txt:
10171017
input_text = txt.read()
1018-
# Check for duplicated key
1019-
yaml.load(input_text, Loader=util.NoDuplicateLoader)
10201018
"""
10211019
The running_inventory defines if the current process is 'inventory' or not.
10221020
This is used for the validation of the path of the 'about_resource'.
@@ -1030,7 +1028,9 @@ def load(self, location, use_mapping=False, mapping_file=None):
10301028
# wrap the value of the boolean field in quote to avoid
10311029
# automatically conversion from yaml.load
10321030
input = util.wrap_boolean_value(input_text) # NOQA
1033-
errs = self.load_dict(saneyaml.load(input), base_dir, running_inventory, use_mapping, mapping_file)
1031+
data = saneyaml.load(input, allow_duplicate_keys=False)
1032+
1033+
errs = self.load_dict(data, base_dir, running_inventory, use_mapping, mapping_file)
10341034
errors.extend(errs)
10351035
except Exception as e:
10361036
msg = 'Cannot load invalid ABOUT file: %(location)r: %(e)r\n' + str(e)
@@ -1121,7 +1121,8 @@ def dumps(self, use_mapping=False, mapping_file=False, with_absent=False, with_e
11211121
lic_dict['url'] = lic_group[3]
11221122
about_data.setdefault('licenses', []).append(lic_dict)
11231123
formatted_about_data = util.format_output(about_data, use_mapping, mapping_file)
1124-
return saneyaml.dump(formatted_about_data)
1124+
1125+
return saneyaml.dump(formatted_about_data, indent=2)
11251126

11261127
def dump(self, location, use_mapping=False, mapping_file=False, with_absent=False, with_empty=True):
11271128
"""

src/attributecode/saneyaml.py

Lines changed: 0 additions & 217 deletions
This file was deleted.

tests/test_gen.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,10 @@ def test_load_inventory(self):
7070
else:
7171
assert e.message in expected_error_messages
7272

73-
expected = [u'about_resource: .\n'
74-
u'name: AboutCode\n'
75-
u'version: 0.11.0\n'
76-
u'description: |-\n'
77-
u' multi\n'
78-
u' line\n']
73+
expected = ['about_resource: .\n'
74+
'name: AboutCode\n'
75+
'version: 0.11.0\n'
76+
'description: |\n multi\n line\n']
7977
result = [a.dumps(use_mapping=False, mapping_file=False, with_absent=False, with_empty=False)
8078
for a in abouts]
8179
assert expected == result
@@ -101,15 +99,14 @@ def test_load_inventory_with_mapping(self):
10199
else:
102100
assert e.message in expected_error_messages
103101

104-
expected = [u'about_resource: .\n'
105-
u'name: AboutCode\n'
106-
u'version: 0.11.0\n'
107-
u'copyright: Copyright (c) nexB, Inc.\n'
108-
u'resource: this.ABOUT\n'
109-
u'description: |-\n'
110-
u' multi\n'
111-
u' line\n'
112-
]
102+
expected = [
103+
'about_resource: .\n'
104+
'name: AboutCode\n'
105+
'version: 0.11.0\n'
106+
'copyright: Copyright (c) nexB, Inc.\n'
107+
'resource: this.ABOUT\n'
108+
'description: |\n multi\n line\n'
109+
]
113110
result = [a.dumps(use_mapping, mapping_file=False, with_absent=False, with_empty=False)
114111
for a in abouts]
115112
assert expected == result
@@ -171,9 +168,9 @@ def test_generate(self):
171168
expected = (u'about_resource: .\n'
172169
u'name: AboutCode\n'
173170
u'version: 0.11.0\n'
174-
u'description: |-\n'
175-
u' multi\n'
176-
u' line\n')
171+
u'description: |\n'
172+
u' multi\n'
173+
u' line\n')
177174
assert expected == in_mem_result
178175

179176
def test_generate_not_overwrite_original_license_file(self):
@@ -190,7 +187,7 @@ def test_generate_not_overwrite_original_license_file(self):
190187
u'name: AboutCode\n'
191188
u'version: 0.11.0\n'
192189
u'licenses:\n'
193-
u' - file: this.LICENSE\n')
190+
u' - file: this.LICENSE\n')
194191
assert expected == in_mem_result
195192

196193
def test_deduplicate(self):

tests/test_model.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -709,24 +709,24 @@ def test_About_dumps(self):
709709
a = model.About(test_file)
710710
assert [] == a.errors
711711

712-
expected = u'''about_resource: .
712+
expected = '''about_resource: .
713713
name: AboutCode
714714
version: 0.11.0
715715
copyright: Copyright (c) 2013-2014 nexB Inc.
716716
license_expression: apache-2.0
717717
author:
718-
- Jillian Daguil
719-
- Chin Yeung Li
720-
- Philippe Ombredanne
721-
- Thomas Druez
722-
description: |-
723-
AboutCode is a tool
724-
to process ABOUT files.
725-
An ABOUT file is a file.
718+
- Jillian Daguil
719+
- Chin Yeung Li
720+
- Philippe Ombredanne
721+
- Thomas Druez
722+
description: |
723+
AboutCode is a tool
724+
to process ABOUT files.
725+
An ABOUT file is a file.
726726
homepage_url: http://dejacode.org
727727
licenses:
728-
- file: apache-2.0.LICENSE
729-
key: apache-2.0
728+
- file: apache-2.0.LICENSE
729+
key: apache-2.0
730730
notice_file: NOTICE
731731
owner: nexB Inc.
732732
vcs_repository: https://github.com/dejacode/about-code-tool.git
5.44 KB
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
about_resource: saneyaml-0.1-py2.py3-none-any.whl
2+
attribute: true
3+
checksum_md5: 53509e4f1ee9f6565158163a56513b7c
4+
checksum_sha1: a66920309794ead47711473a21f1c7d003acd005
5+
contact: http://www.nexb.com/contactus.html
6+
copyright: Copyright (c) nexB Inc. and others.
7+
download_url: https://files.pythonhosted.org/packages/21/13/3d639adcd97fc22cfc4acfd23330cc26f96a85a5b992d93086684e24ac14/saneyaml-0.1-py2.py3-none-any.whl
8+
homepage_url: https://github.com/nexB/saneyaml
9+
license_expression: apache-2.0
10+
licenses:
11+
- file: apache-2.0.LICENSE
12+
key: apache-2.0
13+
name: Apache License 2.0
14+
name: saneyaml
15+
owner: nexB
16+
owner_url: http://www.nexb.com/
17+
package_url: pkg:pypi/[email protected]
18+
track_changes: true
19+
vcs_repository: https://github.com/nexB/saneyaml
20+
version: '0.1'

0 commit comments

Comments
 (0)