Skip to content

Commit acb88ea

Browse files
committed
Use unicode everywhere, cleanup imports #280
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 17555e1 commit acb88ea

File tree

17 files changed

+107
-71
lines changed

17 files changed

+107
-71
lines changed

src/attributecode/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717

1818
from __future__ import absolute_import
1919
from __future__ import print_function
20+
from __future__ import unicode_literals
2021

2122
from collections import namedtuple
2223
import logging
2324

25+
2426
__version__ = '3.0.0.dev5'
2527

2628
__about_spec_version__ = '2.0.0.dev2'
2729

2830
__copyright__ = """
29-
Copyright (c) 2013-2016 nexB Inc. All rights reserved. http://dejacode.org
31+
Copyright (c) 2013-2017 nexB Inc. All rights reserved. http://dejacode.org
3032
Licensed under the Apache License, Version 2.0 (the "License");
3133
you may not use this file except in compliance with the License.
3234
You may obtain a copy of the License at

src/attributecode/__main__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf8 -*-
33

44
# ============================================================================
5-
# Copyright (c) 2013-2015 nexB Inc. http://www.nexb.com/ - All rights reserved.
5+
# Copyright (c) 2013-2017 nexB Inc. http://www.nexb.com/ - All rights reserved.
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
@@ -14,6 +14,10 @@
1414
# limitations under the License.
1515
# ============================================================================
1616

17+
from __future__ import absolute_import
18+
from __future__ import print_function
19+
from __future__ import unicode_literals
20+
1721

1822
if __name__ == '__main__':
1923
from attributecode import cmd

src/attributecode/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
from __future__ import absolute_import
1818
from __future__ import print_function
19+
from __future__ import unicode_literals
1920

21+
from collections import namedtuple
2022
import json
2123
import urllib
22-
from collections import namedtuple
2324

2425
try:
2526
import httplib # Python 2

src/attributecode/attrib.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616

1717
from __future__ import absolute_import
1818
from __future__ import print_function
19+
from __future__ import unicode_literals
1920

2021
import codecs
2122
import collections
22-
import jinja2
2323
import os
2424
from posixpath import basename
2525
from posixpath import dirname
2626
from posixpath import exists
2727
from posixpath import join
2828

29+
import jinja2
30+
2931
import attributecode
3032
from attributecode import ERROR
3133
from attributecode import Error
@@ -73,7 +75,7 @@ def generate(abouts, template_string=None):
7375
if about.license_expression.value and about.license_name.value:
7476
# Split the license expression into list with license key and condition keyword
7577
lic_expression_list = about.license_expression.value.split()
76-
78+
7779

7880
lic_name_list = about.license_name.value
7981
lic_name_expression_list = []
@@ -96,7 +98,7 @@ def generate(abouts, template_string=None):
9698
lic_name_expression = ' '.join(lic_name_expression_list)
9799

98100
# Add the license name expression string into the about object
99-
about.license_name_expression = lic_name_expression
101+
about.license_name_expression = lic_name_expression
100102

101103
rendered = template.render(abouts=abouts, common_licenses=COMMON_LICENSES, license_key_and_context=sorted_license_key_and_context,
102104
license_file_name_and_key=license_file_name_and_key, license_key_to_license_name=license_key_to_license_name)

src/attributecode/cmd.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,31 @@
1616

1717
from __future__ import absolute_import
1818
from __future__ import print_function
19+
from __future__ import unicode_literals
1920

2021
import codecs
2122
import logging
2223
import os
2324
from os.path import exists, join
25+
import sys
2426

2527
import click
2628
import unicodecsv
27-
import sys
2829

2930
import attributecode
3031
from attributecode import CRITICAL
3132
from attributecode import ERROR
3233
from attributecode import INFO
3334
from attributecode import NOTSET
3435
from attributecode import WARNING
35-
from attributecode import Error
3636
from attributecode import __about_spec_version__
3737
from attributecode import __version__
3838
from attributecode import attrib
39+
from attributecode import Error
3940
from attributecode import gen
4041
from attributecode import model
41-
from attributecode import severities
4242
from attributecode.model import About
43+
from attributecode import severities
4344
from attributecode.util import extract_zip
4445
from attributecode.util import to_posix
4546

src/attributecode/gen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616

1717
from __future__ import absolute_import
1818
from __future__ import print_function
19+
from __future__ import unicode_literals
1920

2021
import codecs
2122
from collections import OrderedDict
2223
import logging
2324
import posixpath
24-
import unicodecsv
2525

26+
import unicodecsv
2627

2728
from attributecode import ERROR
2829
from attributecode import CRITICAL
2930
from attributecode import Error
3031
from attributecode import model
31-
from attributecode import util
32-
from attributecode.model import verify_license_files_in_location
3332
from attributecode.model import check_file_field_exist
33+
from attributecode import util
3434
from attributecode.util import add_unc
3535
from attributecode.util import to_posix
3636

src/attributecode/licenses.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf8 -*-
33

44
# ============================================================================
5-
# Copyright (c) 2013-2016 nexB Inc. http://www.nexb.com/ - All rights reserved.
5+
# Copyright (c) 2013-2017 nexB Inc. http://www.nexb.com/ - All rights reserved.
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
@@ -14,6 +14,10 @@
1414
# limitations under the License.
1515
# ============================================================================
1616

17+
from __future__ import absolute_import
18+
from __future__ import print_function
19+
from __future__ import unicode_literals
20+
1721
# Common license keys
1822
COMMON_LICENSES = (
1923
'aes-128-3.0',

src/attributecode/model.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,30 @@
1414
# ============================================================================
1515

1616
"""
17-
AboutCode is a tool to process ABOUT files. ABOUT files are small text files
18-
that document the provenance (aka. the origin and license) of software
19-
components as well as the essential obligation such as attribution/credits and
20-
source code redistribution. See the ABOUT spec at http://dejacode.org.
21-
22-
AbouCode reads and validates ABOUT files and collect software components
23-
inventories.
17+
AboutCode toolkit is a tool to process ABOUT files. ABOUT files are
18+
small text files that document the provenance (aka. the origin and
19+
license) of software components as well as the essential obligation
20+
such as attribution/credits and source code redistribution. See the
21+
ABOUT spec at http://dejacode.org.
22+
23+
AboutCode toolkit reads and validates ABOUT files and collect software
24+
components inventories.
2425
"""
2526

2627
from __future__ import absolute_import
2728
from __future__ import print_function
29+
from __future__ import unicode_literals
2830

31+
from collections import OrderedDict
2932
import codecs
3033
import json
3134
import os
3235
import posixpath
36+
from posixpath import dirname
3337
import re
38+
39+
from license_expression import Licensing
3440
import unicodecsv
35-
from collections import OrderedDict
36-
from posixpath import dirname
3741

3842
try:
3943
import urllib2 # Python 2
@@ -52,14 +56,17 @@
5256

5357
from attributecode import CRITICAL
5458
from attributecode import ERROR
55-
from attributecode import Error
5659
from attributecode import INFO
5760
from attributecode import WARNING
5861
from attributecode import api
62+
from attributecode import Error
5963
from attributecode import saneyaml
6064
from attributecode import util
61-
from attributecode.util import add_unc, UNC_PREFIX, UNC_PREFIX_POSIX, on_windows, copy_license_notice_files
62-
from license_expression import Licensing
65+
from attributecode.util import add_unc
66+
from attributecode.util import copy_license_notice_files
67+
from attributecode.util import on_windows
68+
from attributecode.util import UNC_PREFIX
69+
from attributecode.util import UNC_PREFIX_POSIX
6370

6471

6572
class Field(object):
@@ -384,7 +391,7 @@ def _validate(self, *args, **kwargs):
384391

385392
name = self.name
386393
# FIXME: This is a temp fix for #286
387-
# The field in ignore_checking_list is validated in the check_file_field_exist function
394+
# The field in ignore_checking_list is validated in the check_file_field_exist function
388395
ignore_checking_list = [u'license_file', u'notice_file', u'changelog_file']
389396
# mapping of normalized paths to a location or None
390397
paths = OrderedDict()
@@ -648,7 +655,7 @@ def create_fields(self):
648655
"""
649656
self.fields = OrderedDict([
650657
('about_resource', ListField(required=True)),
651-
#('about_resource', AboutResourceField(required=True)),
658+
# ('about_resource', AboutResourceField(required=True)),
652659
('name', SingleLineField(required=True)),
653660
('about_resource_path', AboutResourceField()),
654661

@@ -822,7 +829,7 @@ def as_dict(self, with_paths=False, with_absent=True, with_empty=True):
822829
# Return an empty 'about_resource_path' if the 'about_resource'
823830
# key is not found
824831
else:
825-
as_dict[arpa] = ''
832+
as_dict[arpa] = ''
826833

827834
for field in self.all_fields(with_absent=with_absent,
828835
with_empty=with_empty):
@@ -1211,7 +1218,7 @@ def field_names(abouts, with_paths=True, with_absent=True, with_empty=True):
12111218
fields = []
12121219
if with_paths:
12131220
fields.append(About.about_file_path_attr)
1214-
#fields.append(About.about_resource_path_attr)
1221+
# fields.append(About.about_resource_path_attr)
12151222

12161223
standard_fields = About().fields.keys()
12171224
if with_absent:

src/attributecode/saneyaml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf8 -*-
33

44
# ============================================================================
5-
# Copyright (c) 2015-2016 nexB Inc. http://www.nexb.com/ - All rights reserved.
5+
# Copyright (c) 2015-2017 nexB Inc. http://www.nexb.com/ - All rights reserved.
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
@@ -14,14 +14,15 @@
1414
# limitations under the License.
1515
# ============================================================================
1616

17-
1817
from __future__ import absolute_import
1918
from __future__ import print_function
19+
from __future__ import unicode_literals
2020

2121
from collections import OrderedDict
2222
from functools import partial
2323

2424
import yaml
25+
2526
try:
2627
from yaml import CSafeLoader as SafeLoader
2728
from yaml import CSafeDumper as SafeDumper

src/attributecode/util.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf8 -*-
33
# ============================================================================
4-
# Copyright (c) 2013-2016 nexB Inc. http://www.nexb.com/ - All rights reserved.
4+
# Copyright (c) 2013-2017 nexB Inc. http://www.nexb.com/ - All rights reserved.
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
77
# You may obtain a copy of the License at
@@ -15,29 +15,32 @@
1515

1616
from __future__ import absolute_import
1717
from __future__ import print_function
18+
from __future__ import unicode_literals
1819

20+
from collections import OrderedDict
1921
import codecs
2022
import errno
2123
import json
2224
import ntpath
2325
import os
26+
from os.path import abspath
27+
from os.path import dirname
28+
from os.path import join
2429
import posixpath
2530
import shutil
2631
import socket
2732
import string
2833
import sys
34+
2935
import unicodecsv
30-
from collections import OrderedDict
31-
from os.path import abspath
32-
from os.path import dirname
33-
from os.path import join
3436

3537
try:
3638
import httplib # Python 2
3739
except ImportError:
3840
import http.client as httplib # Python 3
3941

40-
from attributecode import CRITICAL, Error
42+
from attributecode import CRITICAL
43+
from attributecode import Error
4144

4245

4346
on_windows = 'win32' in sys.platform
@@ -197,7 +200,7 @@ def norm(p):
197200
relative = path[len(base) + 1:]
198201
# We don't want to keep the first segment of the root of the returned path.
199202
# See https://github.com/nexB/attributecode/issues/276
200-
#relative = posixpath.join(base_name, relative)
203+
# relative = posixpath.join(base_name, relative)
201204
return relative
202205

203206

0 commit comments

Comments
 (0)