diff --git a/etc/scripts/genurlrules.py b/etc/scripts/genurlrules.py index 206103bdeaa..1f55f4ffd24 100644 --- a/etc/scripts/genurlrules.py +++ b/etc/scripts/genurlrules.py @@ -24,7 +24,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import os import click @@ -113,7 +112,7 @@ def combine_expressions(expressions, relation='AND', licensing=Licensing()): type(expressions))) # Remove duplicate element in the expressions list - expressions = OrderedDict((x, True) for x in expressions).keys() + expressions = dict((x, True) for x in expressions).keys() if len(expressions) == 1: return expressions[0] diff --git a/etc/scripts/scancli.py b/etc/scripts/scancli.py index af010c896c6..5273e9a90fe 100644 --- a/etc/scripts/scancli.py +++ b/etc/scripts/scancli.py @@ -12,7 +12,6 @@ # specific language governing permissions and limitations under the License. -from collections import OrderedDict import json from os.path import abspath from os.path import dirname @@ -59,7 +58,7 @@ def scan(locations, deserialize=False, scancode_root_dir=None): channel.send(scan_kwargs) # execute func-call remotely results = channel.receive() if deserialize: - results = json.loads(results, object_pairs_hook=OrderedDict) + results = json.loads(results) yield results diff --git a/etc/scripts/sch2js/sch2js.py b/etc/scripts/sch2js/sch2js.py index cd75e071be9..059e14f259a 100644 --- a/etc/scripts/sch2js/sch2js.py +++ b/etc/scripts/sch2js/sch2js.py @@ -39,8 +39,7 @@ """ if __name__ == '__main__': - from collections import OrderedDict - + from six import iteritems from schematics.types.base import BaseType @@ -76,7 +75,7 @@ def jsonschema_for_single_field(field_instance): """ Return a mapping for the schema of a single field. """ - field_schema = OrderedDict() + field_schema = {} field_schema['type'] = SCHEMATIC_TYPE_TO_JSON_TYPE.get( field_instance.__class__.__name__, 'string') @@ -97,7 +96,7 @@ def jsonschema_for_fields(model): """ Return a mapping for the schema of a collection of fields. """ - properties = OrderedDict() + properties = {} required = [] for field_name, field_instance in iteritems(model.fields): serialized_name = getattr(field_instance, 'serialized_name', None) or field_name @@ -109,7 +108,7 @@ def jsonschema_for_fields(model): try: node = jsonschema_for_model(field_instance.model_class, 'array') if hasattr(field_instance, 'metadata'): - _node = OrderedDict() + _node = {} _node['type'] = node.pop('type') _node['title'] = field_instance.metadata.get('label', '') _node['description'] = field_instance.metadata.get('description', '') @@ -117,7 +116,7 @@ def jsonschema_for_fields(model): node = _node except AttributeError: field_schema = jsonschema_for_single_field(field_instance.field) - node = OrderedDict() + node = {} node['type'] = 'array' if hasattr(field_instance, 'metadata'): node['title'] = field_instance.metadata.get('label', '') @@ -156,23 +155,23 @@ def jsonschema_for_model(model, _type='object'): schema_title = '' schema_description = '' - schema = OrderedDict([ - ('type', 'object'), - ('title', schema_title), - ('description', schema_description), - ]) + schema = { + 'type': 'object', + 'title': schema_title, + 'description':schema_description, + } if required: schema['required'] = required if hasattr(model, '_schema_order'): ordered_properties = [(i, properties.pop(i)) for i in model._schema_order] - schema['properties'] = OrderedDict(ordered_properties) + schema['properties'] = dict(ordered_properties) else: schema['properties'] = properties if _type == 'array': - schema = OrderedDict([ + schema = dict([ ('type', 'array'), ('items', schema), ]) @@ -185,7 +184,7 @@ def to_jsonschema(model, **kwargs): Return a a JSON schema mapping for the `model` class. """ schema_id = kwargs.pop('schema_id', '') - jsonschema = OrderedDict([ + jsonschema = dict([ ('$schema', 'http://json-schema.org/draft-04/schema#'), ('id', schema_id) ]) diff --git a/etc/scripts/synclic.py b/etc/scripts/synclic.py index 88b84bb3e94..0f4c2ded685 100644 --- a/etc/scripts/synclic.py +++ b/etc/scripts/synclic.py @@ -24,7 +24,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import os @@ -316,7 +315,7 @@ def get_response(url, headers, params): status = response.status_code if status != requests.codes.ok: # NOQA raise Exception('Failed HTTP request for %(url)r: %(status)r' % locals()) - return response.json(object_pairs_hook=OrderedDict) + return response.json(object_pairs_hook=dict) def clean_text(text): @@ -381,7 +380,7 @@ def fetch_licenses(self, scancode_licenses, from_repo=SPDX_DEFAULT_REPO): # Skip the old plus licenses. We use them in # ScanCode, but they are deprecated in SPDX. continue - details = json.loads(archive.read(path), object_pairs_hook=OrderedDict) + details = json.loads(archive.read(path)) lic = self.build_license(details, scancode_licenses) if lic: yield lic @@ -613,7 +612,7 @@ def call_deja_api(api_url, api_key, paginate=0, headers=None, params=None): params = params or {} def _get_results(response): - return response.json(object_pairs_hook=OrderedDict) + return response.json(object_pairs_hook=dict) if paginate: assert isinstance(paginate, int) @@ -760,7 +759,7 @@ def get_owner(api_url, api_key, name): def license_to_dict(lico): """ - Return an OrderedDict of license data with texts for API calls. + Return an dict of license data with texts for API calls. Fields with empty values are not included. """ licm = dict( diff --git a/src/cluecode/plugin_copyright.py b/src/cluecode/plugin_copyright.py index 6e87f9fc638..9580ff13f30 100644 --- a/src/cluecode/plugin_copyright.py +++ b/src/cluecode/plugin_copyright.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import attr @@ -39,7 +38,7 @@ class CopyrightScanner(ScanPlugin): Scan a Resource for copyrights. """ - resource_attributes = OrderedDict([ + resource_attributes = dict([ ('copyrights',attr.ib(default=attr.Factory(list))), ('holders',attr.ib(default=attr.Factory(list))), ('authors',attr.ib(default=attr.Factory(list))), diff --git a/src/formattedcode/output_csv.py b/src/formattedcode/output_csv.py index 6267f301579..8ed7291f732 100644 --- a/src/formattedcode/output_csv.py +++ b/src/formattedcode/output_csv.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import saneyaml from six import string_types @@ -81,7 +80,7 @@ def write_csv(results, output_file): # FIXMe: this is reading all in memory results = list(results) - headers = OrderedDict([ + headers = dict([ ('info', []), ('license_expression', []), ('license', []), @@ -132,7 +131,7 @@ def collect_keys(mapping, key_group): errors = scanned_file.pop('scan_errors', []) - file_info = OrderedDict(Resource=path) + file_info = dict(Resource=path) file_info.update(((k, v) for k, v in scanned_file.items() # FIXME: info are NOT lists: lists are the actual scans if not isinstance(v, (list, dict)))) @@ -143,12 +142,12 @@ def collect_keys(mapping, key_group): yield file_info for lic_exp in scanned_file.get('license_expressions', []): - inf = OrderedDict(Resource=path, license_expression=lic_exp) + inf = dict(Resource=path, license_expression=lic_exp) collect_keys(inf, 'license_expression') yield inf for licensing in scanned_file.get('licenses', []): - lic = OrderedDict(Resource=path) + lic = dict(Resource=path) for k, val in licensing.items(): # do not include matched text for now. if k == 'matched_text': @@ -178,7 +177,7 @@ def collect_keys(mapping, key_group): yield lic for copyr in scanned_file.get('copyrights', []): - inf = OrderedDict(Resource=path) + inf = dict(Resource=path) inf['copyright'] = copyr['value'] inf['start_line'] = copyr['start_line'] inf['end_line'] = copyr['start_line'] @@ -186,7 +185,7 @@ def collect_keys(mapping, key_group): yield inf for copyr in scanned_file.get('holders', []): - inf = OrderedDict(Resource=path) + inf = dict(Resource=path) inf['copyright_holder'] = copyr['value'] inf['start_line'] = copyr['start_line'] inf['end_line'] = copyr['start_line'] @@ -194,7 +193,7 @@ def collect_keys(mapping, key_group): yield inf for copyr in scanned_file.get('authors', []): - inf = OrderedDict(Resource=path) + inf = dict(Resource=path) inf['author'] = copyr['value'] inf['start_line'] = copyr['start_line'] inf['end_line'] = copyr['start_line'] @@ -202,13 +201,13 @@ def collect_keys(mapping, key_group): yield inf for email in scanned_file.get('emails', []): - email_info = OrderedDict(Resource=path) + email_info = dict(Resource=path) email_info.update(email) collect_keys(email_info, 'email') yield email_info for url in scanned_file.get('urls', []): - url_info = OrderedDict(Resource=path) + url_info = dict(Resource=path) url_info.update(url) collect_keys(url_info, 'url') yield url_info @@ -227,7 +226,7 @@ def pretty(data): if not data: return None seqtypes = list, tuple - maptypes = OrderedDict, dict + maptypes = dict, dict coltypes = seqtypes + maptypes if isinstance(data, seqtypes): if len(data) == 1 and isinstance(data[0], string_types): @@ -281,7 +280,7 @@ def flatten_package(_package, path, prefix='package__'): package_columns = get_package_columns() - pack = OrderedDict(Resource=path) + pack = dict(Resource=path) for k, val in _package.items(): if k not in package_columns: continue diff --git a/src/formattedcode/output_html.py b/src/formattedcode/output_html.py index 03c12c82959..6087f9724f0 100644 --- a/src/formattedcode/output_html.py +++ b/src/formattedcode/output_html.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io from operator import itemgetter from os.path import abspath @@ -162,9 +161,9 @@ def generate_output(results, version, template): from licensedcode.cache import get_licenses_db - converted = OrderedDict() - converted_infos = OrderedDict() - converted_packages = OrderedDict() + converted = {} + converted_infos = {} + converted_packages = {} licenses = {} LICENSES = 'licenses' @@ -175,7 +174,7 @@ def generate_output(results, version, template): # Create a flattened data dict keyed by path for scanned_file in results: - scanned_file = OrderedDict(scanned_file) + scanned_file = dict(scanned_file) path = scanned_file['path'] results = [] if COPYRIGHTS in scanned_file: @@ -210,7 +209,7 @@ def generate_output(results, version, template): # should rather just pass a the list of files from the scan # results and let the template handle this rather than # denormalizing the list here?? - converted_infos[path] = OrderedDict() + converted_infos[path] = {} for name, value in scanned_file.items(): if name in (LICENSES, PACKAGES, COPYRIGHTS, EMAILS, URLS): continue @@ -219,7 +218,7 @@ def generate_output(results, version, template): if PACKAGES in scanned_file: converted_packages[path] = scanned_file[PACKAGES] - licenses = OrderedDict(sorted(licenses.items())) + licenses = dict(sorted(licenses.items())) files = { 'license_copyright': converted, diff --git a/src/formattedcode/output_json.py b/src/formattedcode/output_json.py index af0b3299e17..388949740e2 100644 --- a/src/formattedcode/output_json.py +++ b/src/formattedcode/output_json.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import jsonstreams from six import string_types @@ -144,7 +143,7 @@ def get_results(codebase, as_list=False, **kwargs): """ codebase.add_files_count_to_current_header() - results = OrderedDict([('headers', codebase.get_headers()), ]) + results = dict([('headers', codebase.get_headers()), ]) # add codebase toplevel attributes such as summaries if codebase.attributes: diff --git a/src/formattedcode/output_jsonlines.py b/src/formattedcode/output_jsonlines.py index 80a64fbe66e..e289650be21 100644 --- a/src/formattedcode/output_jsonlines.py +++ b/src/formattedcode/output_jsonlines.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import simplejson @@ -60,7 +59,7 @@ def process_codebase(self, codebase, output_json_lines, **kwargs): codebase.add_files_count_to_current_header() - headers = OrderedDict(headers=codebase.get_headers()) + headers = dict(headers=codebase.get_headers()) simplejson_kwargs = dict( iterable_as_array=True, diff --git a/src/licensedcode/models.py b/src/licensedcode/models.py index 4d1814ecdcd..e317885758b 100644 --- a/src/licensedcode/models.py +++ b/src/licensedcode/models.py @@ -25,7 +25,6 @@ from collections import Counter from collections import defaultdict -from collections import OrderedDict from functools import partial from itertools import chain import io @@ -218,7 +217,7 @@ def text(self): def to_dict(self): """ - Return an OrderedDict of license data (excluding texts). + Return an dict of license data (excluding texts). Fields with empty values are not included. """ @@ -238,7 +237,7 @@ def dict_fields(attr, value): return False return True - data = attr.asdict(self, filter=dict_fields, dict_factory=OrderedDict) + data = attr.asdict(self, filter=dict_fields, dict_factory=dict) cv = data.get('minimum_coverage') if cv and isinstance(cv, float) and int(cv) == cv: cv = int(cv) @@ -934,7 +933,7 @@ def to_dict(self): Return an ordered mapping of self, excluding texts. Used for serialization. Empty values are not included. """ - data = OrderedDict() + data = {} if self.license_expression: data['license_expression'] = self.license_expression diff --git a/src/licensedcode/plugin_license.py b/src/licensedcode/plugin_license.py index 9f24de10f38..c8000e83b79 100644 --- a/src/licensedcode/plugin_license.py +++ b/src/licensedcode/plugin_license.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from functools import partial import attr @@ -56,7 +55,7 @@ class LicenseScanner(ScanPlugin): Scan a Resource for licenses. """ - resource_attributes = OrderedDict([ + resource_attributes = dict([ ('licenses', attr.ib(default=attr.Factory(list))), ('license_expressions', attr.ib(default=attr.Factory(list))), ('percentage_of_license_text', attr.ib(default=0)), diff --git a/src/licensedcode/plugin_license_policy.py b/src/licensedcode/plugin_license_policy.py index 24f57ae4bf4..e7e60d9d7ee 100644 --- a/src/licensedcode/plugin_license_policy.py +++ b/src/licensedcode/plugin_license_policy.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from os.path import exists from os.path import isdir @@ -103,7 +102,7 @@ def has_policy_duplicates(license_policy_location): """ policies = load_license_policy(license_policy_location).get('license_policies', []) - unique_policies = OrderedDict() + unique_policies = {} if policies == []: return False diff --git a/src/packagedcode/bower.py b/src/packagedcode/bower.py index 0f6f6686beb..e1dfbed90f3 100644 --- a/src/packagedcode/bower.py +++ b/src/packagedcode/bower.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from functools import partial import io import json @@ -79,7 +78,7 @@ def parse(location): return with io.open(location, encoding='utf-8') as loc: - package_data = json.load(loc, object_pairs_hook=OrderedDict) + package_data = json.load(loc) return build_package(package_data) diff --git a/src/packagedcode/build.py b/src/packagedcode/build.py index a636c5c9535..3795ca49190 100644 --- a/src/packagedcode/build.py +++ b/src/packagedcode/build.py @@ -24,7 +24,6 @@ from collections import defaultdict -from collections import OrderedDict import ast import logging import os @@ -124,7 +123,7 @@ def recognize(cls, location): and statement.value.func.id.endswith(starlark_rule_types)): rule_name = statement.value.func.id # Process the rule arguments - args = OrderedDict() + args = {} for kw in statement.value.keywords: arg_name = kw.arg if isinstance(kw.value, ast.Str): diff --git a/src/packagedcode/cargo.py b/src/packagedcode/cargo.py index 32c826af001..d4db6971415 100644 --- a/src/packagedcode/cargo.py +++ b/src/packagedcode/cargo.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import logging import re @@ -88,7 +87,7 @@ def parse(location): filename = filetype.is_file(location) and fileutils.file_name(location).lower() handler = handlers.get(filename) if handler: - return handler and handler(toml.load(location, _dict=OrderedDict)) + return handler and handler(toml.load(location, _dict=dict)) def build_cargo_toml_package(package_data): diff --git a/src/packagedcode/chef.py b/src/packagedcode/chef.py index 1c189a29e66..a9e74419db1 100644 --- a/src/packagedcode/chef.py +++ b/src/packagedcode/chef.py @@ -22,7 +22,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import logging @@ -150,7 +149,7 @@ def format(self, tokens, outfile): and its values are those variable's values. This dictionary is then dumped to `outfile` as JSON. """ - metadata = OrderedDict(depends=OrderedDict()) + metadata = dict(depends={}) line = [] identifiers_and_literals = ( Token.Name, @@ -202,7 +201,7 @@ def parse(location): """ if is_metadata_json(location): with io.open(location, encoding='utf-8') as loc: - package_data = json.load(loc, object_pairs_hook=OrderedDict) + package_data = json.load(loc) return build_package(package_data) if is_metadata_rb(location): @@ -210,7 +209,7 @@ def parse(location): file_contents = loc.read() formatted_file_contents = highlight( file_contents, RubyLexer(), ChefMetadataFormatter()) - package_data = json.loads(formatted_file_contents, object_pairs_hook=OrderedDict) + package_data = json.loads(formatted_file_contents) return build_package(package_data) diff --git a/src/packagedcode/conda.py b/src/packagedcode/conda.py index a768b036464..731a93cb1f0 100644 --- a/src/packagedcode/conda.py +++ b/src/packagedcode/conda.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import logging import sys @@ -216,7 +215,7 @@ def get_variables(location): {% set version = "0.45.0" %} {% set sha256 = "bc7512f2eef785b037d836f4cc6faded457ac277f75c6e34eccd12da7c85258f" %} """ - result = OrderedDict() + result = {} with io.open(location, encoding='utf-8') as loc: for line in loc.readlines(): if not line: diff --git a/src/packagedcode/debian.py b/src/packagedcode/debian.py index ec6f3c65991..b1ae49021e5 100644 --- a/src/packagedcode/debian.py +++ b/src/packagedcode/debian.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import logging import os @@ -244,7 +243,7 @@ def build_package(package_data, distro='debian'): package.namespace = distro # add debian-specific package 'qualifiers' - package.qualifiers = OrderedDict([ + package.qualifiers = dict([ ('arch', package_data.get('architecture')), ]) diff --git a/src/packagedcode/freebsd.py b/src/packagedcode/freebsd.py index 8b461e5d5c3..8dbcc4b0e3d 100644 --- a/src/packagedcode/freebsd.py +++ b/src/packagedcode/freebsd.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import logging @@ -123,7 +122,7 @@ def build_package(package_data): package = FreeBSDPackage() # add freebsd-specific package 'qualifiers' - qualifiers = OrderedDict([ + qualifiers = dict([ ('arch', package_data.get('arch')), ('origin', package_data.get('origin')), ]) @@ -177,7 +176,7 @@ def license_mapper(package_data, package): if not licenses: return - declared_license = OrderedDict() + declared_license = {} lics = [l.strip() for l in licenses if l and l.strip()] declared_license['licenses'] = lics if license_logic: diff --git a/src/packagedcode/gemfile_lock.py b/src/packagedcode/gemfile_lock.py index cc3bf3bfe9c..acfd480fd6c 100644 --- a/src/packagedcode/gemfile_lock.py +++ b/src/packagedcode/gemfile_lock.py @@ -24,7 +24,6 @@ from collections import namedtuple -from collections import OrderedDict import functools import logging import re @@ -219,9 +218,9 @@ def as_nv_tree(self): dicts. The tree root is self. Each key is a name/version tuple. Values are dicts. """ - tree = OrderedDict() + tree = {} root = (self.name, self.version,) - tree[root] = OrderedDict() + tree[root] = {} for _name, gem in self.dependencies.items(): tree[root].update(gem.as_nv_tree()) return tree @@ -255,9 +254,9 @@ def dependency_tree(self): Return a tree of dependencies as nested mappings. Each key is a "name@version" string and values are dicts. """ - tree = OrderedDict() + tree = {} root = '{}@{}'.format(self.name or '', self.version or '') - tree[root] = OrderedDict() + tree[root] = {} for _name, gem in self.dependencies.items(): tree[root].update(gem.dependency_tree()) return tree @@ -266,7 +265,7 @@ def to_dict(self): """ Return a native mapping for this Gem. """ - return OrderedDict([ + return dict([ ('name', self.name), ('version', self.version), ('platform', self.platform), @@ -386,10 +385,10 @@ def __init__(self, lockfile): } # the final tree of dependencies, keyed by name - self.dependency_tree = OrderedDict() + self.dependency_tree = {} # a flat dict of all gems, keyed by name - self.all_gems = OrderedDict() + self.all_gems = {} self.platforms = [] diff --git a/src/packagedcode/godeps.py b/src/packagedcode/godeps.py index 6af8582bf86..0abfb7dfddc 100644 --- a/src/packagedcode/godeps.py +++ b/src/packagedcode/godeps.py @@ -24,7 +24,6 @@ from collections import namedtuple -from collections import OrderedDict import io import json import logging @@ -121,9 +120,9 @@ def load(self, location): """ if isinstance(location, string_types): with io.open(location, encoding='utf-8') as godep: - data = json.load(godep, object_pairs_hook=OrderedDict) + data = json.load(godep) else: - data = json.load(location, object_pairs_hook=OrderedDict) + data = json.load(location) for key, value in data.items(): name = NAMES.get(key) @@ -149,7 +148,7 @@ def parse_deps(self, deps): return deps_list or [] def to_dict(self): - dct = OrderedDict() + dct = {} dct.update([ ('import_path', self.import_path), ('go_version', self.go_version), diff --git a/src/packagedcode/golang.py b/src/packagedcode/golang.py index a9474578ba8..6519d4bd0fb 100644 --- a/src/packagedcode/golang.py +++ b/src/packagedcode/golang.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import logging import re diff --git a/src/packagedcode/haxe.py b/src/packagedcode/haxe.py index a92deaaa10b..f31cd677797 100644 --- a/src/packagedcode/haxe.py +++ b/src/packagedcode/haxe.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import logging @@ -127,7 +126,7 @@ def parse(location): return with io.open(location, encoding='utf-8') as loc: - package_data = json.load(loc, object_pairs_hook=OrderedDict) + package_data = json.load(loc) return build_package(package_data) diff --git a/src/packagedcode/jar_manifest.py b/src/packagedcode/jar_manifest.py index caafe09177d..1998d855e14 100644 --- a/src/packagedcode/jar_manifest.py +++ b/src/packagedcode/jar_manifest.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import re import attr @@ -98,7 +97,7 @@ def parse_section(section): """ Return a mapping of key/values for a manifest `section` string """ - data = OrderedDict() + data = {} for line in section.splitlines(False): if not line: continue @@ -273,7 +272,7 @@ def dget(s): description = None # create the mapping we will return - package = OrderedDict() + package = {} package['type'] = package_type package['namespace'] = namespace package['name'] = name @@ -304,14 +303,14 @@ def dget(s): # Implementation-Vendor: The Apache Software Foundation i_vend = dget('Implementation-Vendor') if i_vend: - parties.append(OrderedDict(role='vendor', name=i_vend)) + parties.append(dict(role='vendor', name=i_vend)) # Specification-Vendor: Sun Microsystems, Inc. s_vend = dget('Specification-Vendor') if s_vend == i_vend: s_vend = None if s_vend: - parties.append(OrderedDict(role='spec-vendor', name=s_vend)) + parties.append(dict(role='spec-vendor', name=s_vend)) # Bundle-Vendor: %providerName # Bundle-Vendor: %provider_name @@ -319,7 +318,7 @@ def dget(s): # Bundle-Vendor: http://supercsv.sourceforge.net/ and http://spiffyframe b_vend = dget('Bundle-Vendor') or dget('BundleVendor') if b_vend: - v = OrderedDict(role='vendor', name=b_vend) + v = dict(role='vendor', name=b_vend) if v not in parties: parties.append(v) @@ -328,7 +327,7 @@ def dget(s): m_email = dget('Module-Email') m_owner = dget('Module-Owner') if m_owner: - o = OrderedDict(role='owner', name=m_owner) + o = dict(role='owner', name=m_owner) if m_email and m_email != m_owner: o['email'] = m_email parties.append(o) diff --git a/src/packagedcode/maven.py b/src/packagedcode/maven.py index e5076e5178a..c2b911ce6cf 100644 --- a/src/packagedcode/maven.py +++ b/src/packagedcode/maven.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import logging import os.path @@ -273,7 +272,7 @@ def to_dict(self): """ Return a mapping representing this POM """ - return OrderedDict([ + return dict([ ('group_id', self.group_id), ('artifact_id', self.artifact_id), ('version', str(self.version) if self.version else None), @@ -617,7 +616,7 @@ def _get_comments(self, xml=None): def _find_licenses(self): """Return an iterable of license mappings.""" for lic in self.pom_data.findall('licenses/license'): - yield OrderedDict([ + yield dict([ ('name', self._get_attribute('name', lic)), ('url', self._get_attribute('url', lic)), ('comments', self._get_attribute('comments', lic)), @@ -628,7 +627,7 @@ def _find_licenses(self): def _find_parties(self, key='developers/developer'): """Return an iterable of party mappings for a given xpath.""" for party in self.pom_data.findall(key): - yield OrderedDict([ + yield dict([ ('id', self._get_attribute('id', party)), ('name', self._get_attribute('name', party)), ('email', self._get_attribute('email', party)), @@ -643,7 +642,7 @@ def _find_mailing_lists(self): for ml in self.pom_data.findall('mailingLists/mailingList'): archive_url = self._get_attribute('archive', ml) # TODO: add 'otherArchives/otherArchive' as lists? - yield OrderedDict([ + yield dict([ ('name', self._get_attribute('name', ml)), ('archive_url', archive_url), ]) @@ -653,7 +652,7 @@ def _find_scm(self): scm = self.pom_data.find('scm') if scm is None: return {} - return OrderedDict([ + return dict([ ('connection', self._get_attribute('connection', scm)), ('developer_connection', self._get_attribute('developer_connection', scm)), ('url', self._get_attribute('url', scm)), @@ -665,7 +664,7 @@ def _find_issue_management(self): imgt = self.pom_data.find('issueManagement') if imgt is None: return {} - return OrderedDict([ + return dict([ ('system', self._get_attribute('system', imgt)), ('url', self._get_attribute('url', imgt)), ]) @@ -675,7 +674,7 @@ def _find_ci_management(self): cimgt = self.pom_data.find('ciManagement') if cimgt is None: return {} - return OrderedDict([ + return dict([ ('system', self._get_attribute('system', cimgt)), ('url', self._get_attribute('url', cimgt)), ]) @@ -687,7 +686,7 @@ def _find_repository(self, xpath, xml=None): repo = xml.find(xpath) if repo is None: return {} - return OrderedDict([ + return dict([ ('id', self._get_attribute('id', repo)), ('name', self._get_attribute('name', repo)), ('url', self._get_attribute('url', repo)), @@ -698,7 +697,7 @@ def _find_distribution_management(self): dmgt = self.pom_data.find('distributionManagement') if dmgt is None: return {} - return OrderedDict([ + return dict([ ('download_url', self._get_attribute('distributionManagement/downloadUrl')), ('site', self._find_repository('distributionManagement/site')), ('repository', self._find_repository('distributionManagement/repository')), @@ -716,10 +715,10 @@ def to_dict(self): """ Return a mapping representing this POM. """ - dependencies = OrderedDict() + dependencies = {} for scope, deps in self.dependencies.items(): dependencies[scope] = [ - OrderedDict([ + dict([ ('group_id', gid), ('artifact_id', aid), ('version', version), @@ -727,7 +726,7 @@ def to_dict(self): ]) for ((gid, aid, version), required) in deps] - return OrderedDict([ + return dict([ ('model_version', self.model_version), ('group_id', self.group_id), ('artifact_id', self.artifact_id), diff --git a/src/packagedcode/models.py b/src/packagedcode/models.py index a0b1c15f282..6c0a5f98bec 100644 --- a/src/packagedcode/models.py +++ b/src/packagedcode/models.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import logging import sys @@ -95,9 +94,9 @@ class BaseModel(object): def to_dict(self, **kwargs): """ - Return an OrderedDict of primitive Python types. + Return an dict of primitive Python types. """ - return attr.asdict(self, dict_factory=OrderedDict) + return attr.asdict(self, dict_factory=dict) @classmethod def create(cls, ignore_unknown=True, **kwargs): @@ -290,9 +289,9 @@ def set_purl(self, package_url): def to_dict(self, **kwargs): """ - Return an OrderedDict of primitive Python types. + Return an dict of primitive Python types. """ - mapping = attr.asdict(self, dict_factory=OrderedDict) + mapping = attr.asdict(self, dict_factory=dict) if not kwargs.get('exclude_properties'): mapping['purl'] = self.purl mapping['repository_homepage_url'] = self.repository_homepage_url() diff --git a/src/packagedcode/npm.py b/src/packagedcode/npm.py index 778f4bdd720..386a5b867e6 100644 --- a/src/packagedcode/npm.py +++ b/src/packagedcode/npm.py @@ -25,7 +25,6 @@ import base64 from collections import defaultdict -from collections import OrderedDict from functools import partial import io import json @@ -254,12 +253,12 @@ def parse(location): """ if is_package_json(location): with io.open(location, encoding='utf-8') as loc: - package_data = json.load(loc, object_pairs_hook=OrderedDict) + package_data = json.load(loc) yield build_package(package_data) if is_package_lock(location) or is_npm_shrinkwrap(location): with io.open(location, encoding='utf-8') as loc: - package_data = json.load(loc, object_pairs_hook=OrderedDict) + package_data = json.load(loc) for package in build_packages_from_lockfile(package_data): yield package diff --git a/src/packagedcode/opam.py b/src/packagedcode/opam.py index a1166ce93fd..6341be30f11 100644 --- a/src/packagedcode/opam.py +++ b/src/packagedcode/opam.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import logging import re diff --git a/src/packagedcode/phpcomposer.py b/src/packagedcode/phpcomposer.py index 32f7179a2e4..0f7b9736fb8 100644 --- a/src/packagedcode/phpcomposer.py +++ b/src/packagedcode/phpcomposer.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from functools import partial import io import json @@ -155,12 +154,12 @@ def parse(location): """ if is_phpcomposer_json(location): with io.open(location, encoding='utf-8') as loc: - package_data = json.load(loc, object_pairs_hook=OrderedDict) + package_data = json.load(loc) yield build_package_from_json(package_data) elif is_phpcomposer_lock(location): with io.open(location, encoding='utf-8') as loc: - package_data = json.load(loc, object_pairs_hook=OrderedDict) + package_data = json.load(loc) for package in build_packages_from_lock(package_data): yield package diff --git a/src/packagedcode/plugin_package.py b/src/packagedcode/plugin_package.py index 436192bf0ca..363eaef92ed 100644 --- a/src/packagedcode/plugin_package.py +++ b/src/packagedcode/plugin_package.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import attr import click @@ -67,7 +66,7 @@ class PackageScanner(ScanPlugin): right file or directory level. """ - resource_attributes = OrderedDict() + resource_attributes = {} resource_attributes['packages'] = attr.ib(default=attr.Factory(list), repr=False) sort_order = 6 diff --git a/src/packagedcode/pypi.py b/src/packagedcode/pypi.py index 713948a5c78..862eb99744d 100644 --- a/src/packagedcode/pypi.py +++ b/src/packagedcode/pypi.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import ast import io import json @@ -180,7 +179,7 @@ def parse_with_pkginfo(pkginfo): homepage_url=pkginfo.home_page, ) package = PythonPackage(**common_data) - declared_license = OrderedDict() + declared_license = {} if pkginfo.license: # TODO: We should make the declared license as it is, this should be updated in scancode to parse a pure string declared_license['license'] = pkginfo.license @@ -302,7 +301,7 @@ def parse_pipfile_lock(location): with open(location) as f: content = f.read() - data = json.loads(content, object_pairs_hook=OrderedDict) + data = json.loads(content) sha256 = None if '_meta' in data: @@ -327,7 +326,7 @@ def parse_setup_py(location): with open(location) as inp: setup_text = inp.read() - setup_args = OrderedDict() + setup_args = {} # Parse setup.py file and traverse the AST tree = ast.parse(setup_text) @@ -393,7 +392,7 @@ def parse_setup_py(location): ) ) - declared_license = OrderedDict() + declared_license = {} license_setuptext = setup_args.get('license') declared_license['license'] = license_setuptext @@ -634,7 +633,7 @@ def parse_metadata(location): return with open(location, 'rb') as infs: - infos = json.load(infs, object_pairs_hook=OrderedDict) + infos = json.load(infs) extensions = infos.get('extensions') if TRACE: logger_debug('parse_metadata: extensions:', extensions) @@ -668,7 +667,7 @@ def parse_metadata(location): else: other_classifiers.append(classifier) - declared_license = OrderedDict() + declared_license = {} lic = infos.get('license') if lic: declared_license['license'] = lic diff --git a/src/packagedcode/rubygems.py b/src/packagedcode/rubygems.py index 15b9d994ade..75bca9303b3 100644 --- a/src/packagedcode/rubygems.py +++ b/src/packagedcode/rubygems.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import logging import os from os.path import abspath @@ -613,7 +612,7 @@ def normalize(gem_data, known_fields=known_fields): field in a gem mapping. Ensure that all known fields are present even if empty. """ - return OrderedDict( + return dict( [(k, gem_data.get(k) or None) for k in known_fields] ) diff --git a/src/packagedcode/spec.py b/src/packagedcode/spec.py index 55ca540e7c6..157f10b0239 100644 --- a/src/packagedcode/spec.py +++ b/src/packagedcode/spec.py @@ -22,7 +22,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import logging import re @@ -114,7 +113,7 @@ def parse_spec(self, location): parser = GemfileParser(location) deps = parser.parse() - dependencies = OrderedDict() + dependencies = {} for key in deps: depends = deps.get(key, []) or [] for dep in depends: diff --git a/src/packagedcode/utils.py b/src/packagedcode/utils.py index bcfa8bf7232..dcba940d0b1 100644 --- a/src/packagedcode/utils.py +++ b/src/packagedcode/utils.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from license_expression import Licensing from six import string_types @@ -172,7 +171,7 @@ def combine_expressions(expressions, relation='AND', licensing=Licensing()): type(expressions))) # Remove duplicate element in the expressions list - expressions = list(OrderedDict((x, True) for x in expressions).keys()) + expressions = list(dict((x, True) for x in expressions).keys()) if len(expressions) == 1: return expressions[0] diff --git a/src/packagedcode/win_pe.py b/src/packagedcode/win_pe.py index a526064b995..b83897d6942 100644 --- a/src/packagedcode/win_pe.py +++ b/src/packagedcode/win_pe.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from contextlib import closing import attr @@ -172,8 +171,8 @@ def pe_info(location): if not T.is_winexe: return {} - result = OrderedDict([(k, None,) for k in PE_INFO_KEYS]) - extra_data = result['extra_data'] = OrderedDict() + result = dict([(k, None,) for k in PE_INFO_KEYS]) + extra_data = result['extra_data'] = {} with closing(pefile.PE(location)) as pe: if not hasattr(pe, 'FileInfo'): diff --git a/src/scancode/api.py b/src/scancode/api.py index 527f6d24125..2f4c609d399 100644 --- a/src/scancode/api.py +++ b/src/scancode/api.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from itertools import islice from os.path import getsize import logging @@ -70,7 +69,7 @@ def get_copyrights(location, deadline=sys.maxsize, **kwargs): if dtype == 'copyrights': copyrights.append( - OrderedDict([ + dict([ ('value', value), ('start_line', start), ('end_line', end) @@ -78,7 +77,7 @@ def get_copyrights(location, deadline=sys.maxsize, **kwargs): ) elif dtype == 'holders': holders.append( - OrderedDict([ + dict([ ('value', value), ('start_line', start), ('end_line', end) @@ -86,14 +85,14 @@ def get_copyrights(location, deadline=sys.maxsize, **kwargs): ) elif dtype == 'authors': authors.append( - OrderedDict([ + dict([ ('value', value), ('start_line', start), ('end_line', end) ]) ) - results = OrderedDict([ + results = dict([ ('copyrights', copyrights), ('holders', holders), ('authors', authors), @@ -126,7 +125,7 @@ def get_emails(location, threshold=50, test_slow_mode=False, test_error_mode=Fal found_emails = islice(found_emails, threshold) for email, line_num in found_emails: - result = OrderedDict() + result = {} results.append(result) result['email'] = email result['start_line'] = line_num @@ -148,7 +147,7 @@ def get_urls(location, threshold=50, **kwargs): found_urls = islice(found_urls, threshold) for urls, line_num in found_urls: - result = OrderedDict() + result = {} results.append(result) result['url'] = urls result['start_line'] = line_num @@ -216,7 +215,7 @@ def get_licenses(location, min_score=0, query_tokens_length = match.query.tokens_length(with_unknown=True) percentage_of_license_text = round((matched_tokens_length / query_tokens_length) * 100, 2) - return OrderedDict([ + return dict([ ('licenses', detected_licenses), ('license_expressions', detected_expressions), ('percentage_of_license_text', percentage_of_license_text), @@ -243,7 +242,7 @@ def _licenses_data_from_match( detected_licenses = [] for license_key in match.rule.license_keys(): lic = licenses.get(license_key) - result = OrderedDict() + result = {} detected_licenses.append(result) result['key'] = lic.key result['score'] = match.score() @@ -265,7 +264,7 @@ def _licenses_data_from_match( result['spdx_url'] = spdx_url result['start_line'] = match.start_line result['end_line'] = match.end_line - matched_rule = result['matched_rule'] = OrderedDict() + matched_rule = result['matched_rule'] = {} matched_rule['identifier'] = match.rule.identifier matched_rule['license_expression'] = match.rule.license_expression matched_rule['licenses'] = match.rule.license_keys() @@ -317,7 +316,7 @@ def get_file_info(location, **kwargs): """ Return a mapping of file information collected for the file at `location`. """ - result = OrderedDict() + result = {} # TODO: move date and size these to the inventory collection step??? result['date'] = get_last_modified_date(location) or None diff --git a/src/scancode/cli.py b/src/scancode/cli.py index 47abdec1855..845dea93ae2 100644 --- a/src/scancode/cli.py +++ b/src/scancode/cli.py @@ -30,7 +30,6 @@ import scancode_config from collections import defaultdict -from collections import OrderedDict from functools import partial import os import logging @@ -583,7 +582,7 @@ def echo_func(*_args, **_kwargs): # Find and create known plugin instances and collect the enabled ######################################################################## - enabled_plugins_by_stage = OrderedDict() + enabled_plugins_by_stage = {} all_enabled_plugins_by_qname = {} non_enabled_plugins_by_qname = {} @@ -666,7 +665,7 @@ def echo_func(*_args, **_kwargs): # Setup enabled and required plugins ######################################################################## - setup_timings = OrderedDict() + setup_timings = {} plugins_setup_start = time() if not quiet and not verbose: @@ -713,7 +712,7 @@ def echo_func(*_args, **_kwargs): '%(stage)s:%(name)s:' % locals()) raise ScancodeError(msg + '\n' + traceback.format_exc()) - resource_attributes = OrderedDict() + resource_attributes = {} for _, name, attribs in sorted(sortable_resource_attributes): resource_attributes.update(attribs) @@ -749,7 +748,7 @@ def echo_func(*_args, **_kwargs): '%(stage)s:%(name)s:' % locals()) raise ScancodeError(msg + '\n' + traceback.format_exc()) - codebase_attributes = OrderedDict() + codebase_attributes = {} for _, name, attribs in sorted(sortable_codebase_attributes): codebase_attributes.update(attribs) @@ -1222,9 +1221,9 @@ def scan_resource(location_rid, scanners, timeout=DEFAULT_TIMEOUT, """ scan_time = time() location, rid = location_rid - results = OrderedDict() + results = {} scan_errors = [] - timings = OrderedDict() if with_timing else None + timings = {} if with_timing else None if not with_threading: interruptor = fake_interruptible @@ -1505,7 +1504,7 @@ def get_pretty_params(ctx, generic_paths=False): # coerce to string for non-basic supported types if not (value in (True, False, None) - or isinstance(value, (str, string_types, bytes, tuple, list, dict, OrderedDict))): + or isinstance(value, (str, string_types, bytes, tuple, list, dict, dict))): value = repr(value) # opts is a list of CLI options as in "--strip-root": the last opt is @@ -1517,4 +1516,4 @@ def get_pretty_params(ctx, generic_paths=False): else: options.append((cli_opt, value)) - return OrderedDict(sorted(args) + sorted(options)) + return dict(sorted(args) + sorted(options)) diff --git a/src/scancode/cli_test_utils.py b/src/scancode/cli_test_utils.py index f8ccc8bde56..5bc9c40a4f4 100644 --- a/src/scancode/cli_test_utils.py +++ b/src/scancode/cli_test_utils.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import os @@ -190,7 +189,7 @@ def load_json_result_from_string(string, remove_file_date=False): """ Load the JSON scan results `string` as UTF-8 JSON. """ - scan_results = json.loads(string, object_pairs_hook=OrderedDict) + scan_results = json.loads(string) # clean new headers attributes streamline_headers(scan_results.get('headers', [])) # clean file_level attributes @@ -250,7 +249,7 @@ def check_jsonlines_scan(expected_file, result_file, regen=False, remove_file_da If `remove_file_date` is True, the file.date attribute is removed. """ with io.open(result_file, encoding='utf-8') as res: - results = [json.loads(line, object_pairs_hook=OrderedDict) for line in res] + results = [json.loads(line) for line in res] streamline_jsonlines_scan(results, remove_file_date) @@ -259,7 +258,7 @@ def check_jsonlines_scan(expected_file, result_file, regen=False, remove_file_da json.dump(results, reg, indent=2, separators=(',', ': ')) with io.open(expected_file, encoding='utf-8') as res: - expected = json.load(res, object_pairs_hook=OrderedDict) + expected = json.load(res) streamline_jsonlines_scan(expected, remove_file_date) diff --git a/src/scancode/outdated.py b/src/scancode/outdated.py index 4fcbbe591e2..e416144def5 100644 --- a/src/scancode/outdated.py +++ b/src/scancode/outdated.py @@ -45,7 +45,6 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -from collections import OrderedDict import datetime import json import logging @@ -197,7 +196,7 @@ def get_latest_version(new_version_url='https://pypi.org/pypi/scancode-toolkit/j raise Exception(msg) # The check is done using python.org PyPI API - payload = response.json(object_pairs_hook=OrderedDict) + payload = response.json(object_pairs_hook=dict) releases = [ r for r in payload['releases'] if not packaging_version.parse(r).is_prerelease] releases = sorted(releases, key=packaging_version.parse) diff --git a/src/scancode/plugin_info.py b/src/scancode/plugin_info.py index 733648e672c..1117165c72e 100644 --- a/src/scancode/plugin_info.py +++ b/src/scancode/plugin_info.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import attr @@ -39,7 +38,7 @@ class InfoScanner(ScanPlugin): Scan a file Resource for miscellaneous information such as mime/filetype and basic checksums. """ - resource_attributes = OrderedDict([ + resource_attributes = dict([ ('date', attr.ib(default=None, repr=False)), ('sha1', attr.ib(default=None, repr=False)), ('md5', attr.ib(default=None, repr=False)), diff --git a/src/summarycode/classify.py b/src/summarycode/classify.py index ee32c65d836..66706fde12c 100644 --- a/src/summarycode/classify.py +++ b/src/summarycode/classify.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from six import string_types @@ -77,7 +76,7 @@ class FileClassifier(PreScanPlugin): """ Classify a file such as a COPYING file or a package manifest with a flag. """ - resource_attributes = OrderedDict([ + resource_attributes = dict([ ('is_legal', Boolean(help='True if this file is likely a "legal", license-related' 'file such as a COPYING or LICENSE file.')), diff --git a/src/summarycode/plugin_consolidate.py b/src/summarycode/plugin_consolidate.py index 433314b03c4..e0f7ededc03 100644 --- a/src/summarycode/plugin_consolidate.py +++ b/src/summarycode/plugin_consolidate.py @@ -24,7 +24,6 @@ from collections import Counter -from collections import OrderedDict import attr @@ -99,7 +98,7 @@ def dict_fields(attr, value): self.consolidated_holders = sorted(set(self.core_holders + self.other_holders)) # TODO: Verify and test that we are generating detectable copyrights self.consolidated_copyright = 'Copyright (c) {}'.format(', '.join(self.consolidated_holders)) - return attr.asdict(self, filter=dict_fields, dict_factory=OrderedDict) + return attr.asdict(self, filter=dict_fields, dict_factory=dict) @attr.s @@ -109,7 +108,7 @@ class ConsolidatedComponent(object): consolidation = attr.ib() def to_dict(self, **kwargs): - c = OrderedDict(type=self.type) + c = dict(type=self.type) c.update(self.consolidation.to_dict()) return c @@ -142,7 +141,7 @@ class Consolidator(PostScanPlugin): the identifier of the consolidated component or consolidated package it is part of is in the Resource's ``consolidated_to`` field. """ - codebase_attributes = OrderedDict( + codebase_attributes = dict( consolidated_components=attr.ib(default=attr.Factory(list)), consolidated_packages=attr.ib(default=attr.Factory(list)) ) diff --git a/src/summarycode/score.py b/src/summarycode/score.py index c1f4e91d89b..eda7ee06671 100644 --- a/src/summarycode/score.py +++ b/src/summarycode/score.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from itertools import chain import attr @@ -92,7 +91,7 @@ def is_good_license(detected_license): rule = detected_license['matched_rule'] coverage = rule.get('match_coverage') or 0 relevance = rule.get('rule_relevance') or 0 - match_types = OrderedDict([ + match_types = dict([ ('is_license_text', rule['is_license_text']), ('is_license_notice', rule['is_license_notice']), ('is_license_reference', rule['is_license_reference']), @@ -162,7 +161,7 @@ def compute_license_score(codebase): """ score = 0 - scoring_elements = OrderedDict(score=score) + scoring_elements = dict(score=score) for element in SCORING_ELEMENTS: element_score = element.scorer(codebase) diff --git a/src/summarycode/summarizer.py b/src/summarycode/summarizer.py index 883a244e39d..c6725280e05 100644 --- a/src/summarycode/summarizer.py +++ b/src/summarycode/summarizer.py @@ -24,7 +24,6 @@ from collections import Counter -from collections import OrderedDict import attr from six import string_types @@ -112,7 +111,7 @@ class ScanSummary(PostScanPlugin): """ sort_order = 10 - codebase_attributes = OrderedDict(summary=attr.ib(default=attr.Factory(OrderedDict))) + codebase_attributes = dict(summary=attr.ib(default=attr.Factory(dict))) options = [ PluggableCommandLineOption(('--summary',), @@ -135,10 +134,10 @@ class ScanSummaryWithDetails(PostScanPlugin): Summarize a scan at the codebase level and keep file and directory details. """ # mapping of summary data at the codebase level for the whole codebase - codebase_attributes = OrderedDict(summary=attr.ib(default=attr.Factory(OrderedDict))) + codebase_attributes = dict(summary=attr.ib(default=attr.Factory(dict))) # store summaries at the file and directory level in this attribute when # keep details is True - resource_attributes = OrderedDict(summary=attr.ib(default=attr.Factory(OrderedDict))) + resource_attributes = dict(summary=attr.ib(default=attr.Factory(dict))) sort_order = 100 options = [ @@ -196,7 +195,7 @@ def summarize_codebase(codebase, keep_details, **kwargs): if keep_details: summary = root.summary else: - summary = root.extra_data.get('summary', OrderedDict()) + summary = root.extra_data.get('summary', {}) codebase.attributes.summary.update(summary) if TRACE: logger_debug('codebase summary:', summary) @@ -291,7 +290,7 @@ def summarize_values(values, attribute): from summarycode.copyright_summary import summarize_holders from summarycode.copyright_summary import summarize_copyrights - value_summarizers_by_attr = OrderedDict( + value_summarizers_by_attr = dict( license_expressions=summarize_licenses, copyrights=summarize_copyrights, holders=summarize_holders, @@ -309,7 +308,7 @@ class ScanKeyFilesSummary(PostScanPlugin): sort_order = 150 # mapping of summary data at the codebase level for key files - codebase_attributes = OrderedDict(summary_of_key_files=attr.ib(default=attr.Factory(OrderedDict))) + codebase_attributes = dict(summary_of_key_files=attr.ib(default=attr.Factory(dict))) options = [ PluggableCommandLineOption(('--summary-key-files',), @@ -351,7 +350,7 @@ def summarize_codebase_key_files(codebase, **kwargs): if k in really_summarizable_attributes] # create one counter for each summarized attribute - summarizable_values_by_key = OrderedDict([(key, []) for key in summarizable_attributes]) + summarizable_values_by_key = dict([(key, []) for key in summarizable_attributes]) # filter to get only key files key_files = (res for res in codebase.walk(topdown=True) @@ -372,7 +371,7 @@ def summarize_codebase_key_files(codebase, **kwargs): summarized = summarize_values(values, key) summary_counters.append((key, summarized)) - sorted_summaries = OrderedDict( + sorted_summaries = dict( [(key, sorted_counter(counter)) for key, counter in summary_counters]) codebase.attributes.summary_of_key_files = sorted_summaries @@ -386,7 +385,7 @@ class ScanByFacetSummary(PostScanPlugin): Summarize a scan at the codebase level groupping by facets. """ sort_order = 200 - codebase_attributes = OrderedDict(summary_by_facet=attr.ib(default=attr.Factory(list))) + codebase_attributes = dict(summary_by_facet=attr.ib(default=attr.Factory(list))) options = [ PluggableCommandLineOption(('--summary-by-facet',), @@ -417,8 +416,8 @@ def summarize_codebase_by_facet(codebase, **kwargs): logger_debug('summarize_codebase_by_facet for attributes:', summarizable_attributes) # create one group of by-facet values lists for each summarized attribute - summarizable_values_by_key_by_facet = OrderedDict([ - (facet, OrderedDict([(key, []) for key in summarizable_attributes])) + summarizable_values_by_key_by_facet = dict([ + (facet, dict([(key, []) for key in summarizable_attributes])) for facet in facet_module.FACETS ]) @@ -444,10 +443,10 @@ def summarize_codebase_by_facet(codebase, **kwargs): for key, values in summarizable_values_by_key.items() ) - sorted_summaries = OrderedDict( + sorted_summaries = dict( [(key, sorted_counter(counter)) for key, counter in summary_counters]) - facet_summary = OrderedDict(facet=facet) + facet_summary = dict(facet=facet) facet_summary['summary'] = sorted_summaries final_summaries.append(facet_summary) diff --git a/src/summarycode/utils.py b/src/summarycode/utils.py index eb121f4de24..529b51f9fae 100644 --- a/src/summarycode/utils.py +++ b/src/summarycode/utils.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict def get_resource_summary(resource, key, as_attribute=False): @@ -37,8 +36,8 @@ def get_resource_summary(resource, key, as_attribute=False): if as_attribute: summary = resource.summary else: - summary = resource.extra_data.get('summary', OrderedDict()) - summary = summary or OrderedDict() + summary = resource.extra_data.get('summary', {}) + summary = summary or {} return summary.get(key) or None @@ -55,7 +54,7 @@ def set_resource_summary(resource, key, value, as_attribute=False): else: summary = resource.extra_data.get('summary') if not summary: - summary = OrderedDict([(key, value)]) + summary = dict([(key, value)]) resource.extra_data['summary'] = summary summary[key] = value @@ -72,6 +71,6 @@ def by_count_value(value_count): return -count, value or '' summarized = [ - OrderedDict([('value', value), ('count', count)]) + dict([('value', value), ('count', count)]) for value, count in sorted(counter.items(), key=by_count_value)] return summarized diff --git a/src/textcode/analysis.py b/src/textcode/analysis.py index ec02e69a21c..c4802307fa9 100644 --- a/src/textcode/analysis.py +++ b/src/textcode/analysis.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import os @@ -228,7 +227,7 @@ def js_map_sources_lines(location): We care only about the presence of these tags for detection: version, sources, sourcesContent. """ with io.open(location, encoding='utf-8') as jsm: - content = json.load(jsm, object_pairs_hook=OrderedDict) + content = json.load(jsm) sources = content.get('sourcesContent', []) for entry in sources: for line in entry.splitlines(): diff --git a/tests/cluecode/cluecode_test_utils.py b/tests/cluecode/cluecode_test_utils.py index 3f40e37903b..9d12c5597ea 100644 --- a/tests/cluecode/cluecode_test_utils.py +++ b/tests/cluecode/cluecode_test_utils.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io from itertools import chain from os import path @@ -110,8 +109,8 @@ def to_dict(self): filtered = [field for field in attr.fields(CopyrightTest) if '_file' in field.name] fields_filter = attr.filters.exclude(*filtered) - data = attr.asdict(self, filter=fields_filter, dict_factory=OrderedDict) - return OrderedDict([ + data = attr.asdict(self, filter=fields_filter, dict_factory=dict) + return dict([ (key, value) for key, value in data.items() # do not dump false and empties if value]) @@ -180,7 +179,7 @@ def by_count_value(value_count): value, count = value_count return -count, value - summarized = [OrderedDict([('value', value), ('count', count)]) + summarized = [dict([('value', value), ('count', count)]) for value, count in sorted(counter.items(), key=by_count_value)] return summarized diff --git a/tests/formattedcode/test_output_csv.py b/tests/formattedcode/test_output_csv.py index f67eb843b42..597fd8c8ed0 100644 --- a/tests/formattedcode/test_output_csv.py +++ b/tests/formattedcode/test_output_csv.py @@ -25,7 +25,6 @@ import io -from collections import OrderedDict import json import os @@ -50,7 +49,7 @@ def load_scan(json_input): with io.open(json_input, encoding='utf-8') as jsonf: scan = jsonf.read() - scan_results = json.loads(scan, object_pairs_hook=OrderedDict) + scan_results = json.loads(scan) scan_results = scan_results['files'] return scan_results @@ -60,7 +59,7 @@ def check_json(result, expected_file, regen=False): with io.open(expected_file, 'w', encoding='utf-8') as reg: reg.write(json.dumps(result, indent=4, separators=(',', ': '))) with io.open(expected_file, encoding='utf-8') as exp: - expected = json.load(exp, object_pairs_hook=OrderedDict) + expected = json.load(exp) assert expected == result @@ -100,7 +99,7 @@ def load_csv(location): def test_flatten_scan_minimal(): test_json = test_env.get_test_loc('csv/flatten_scan/minimal.json') scan = load_scan(test_json) - headers = OrderedDict([ + headers = dict([ ('info', []), ('license', []), ('copyright', []), @@ -116,7 +115,7 @@ def test_flatten_scan_minimal(): def test_flatten_scan_can_process_path_with_and_without_leading_slash(): test_json = test_env.get_test_loc('csv/flatten_scan/path_with_and_without_leading_slash.json') scan = load_scan(test_json) - headers = OrderedDict([ + headers = dict([ ('info', []), ('license', []), ('copyright', []), @@ -161,7 +160,7 @@ def test_csv_minimal(): def test_flatten_scan_full(): test_json = test_env.get_test_loc('csv/flatten_scan/full.json') scan = load_scan(test_json) - headers = OrderedDict([ + headers = dict([ ('info', []), ('license', []), ('copyright', []), @@ -178,7 +177,7 @@ def test_flatten_scan_full(): def test_flatten_scan_key_ordering(): test_json = test_env.get_test_loc('csv/flatten_scan/key_order.json') scan = load_scan(test_json) - headers = OrderedDict([ + headers = dict([ ('info', []), ('license', []), ('copyright', []), @@ -196,7 +195,7 @@ def test_flatten_scan_with_no_keys_does_not_error_out(): # this scan has no results at all test_json = test_env.get_test_loc('csv/flatten_scan/no_keys.json') scan = load_scan(test_json) - headers = OrderedDict([ + headers = dict([ ('info', []), ('license', []), ('copyright', []), @@ -205,7 +204,7 @@ def test_flatten_scan_with_no_keys_does_not_error_out(): ('package', []), ]) result = list(flatten_scan(scan, headers)) - expected_headers = OrderedDict([ + expected_headers = dict([ ('info', []), ('license', []), ('copyright', []), @@ -221,7 +220,7 @@ def test_flatten_scan_with_no_keys_does_not_error_out(): def test_flatten_scan_can_process_package_license_when_license_value_is_null(): test_json = test_env.get_test_loc('csv/flatten_scan/package_license_value_null.json') scan = load_scan(test_json) - headers = OrderedDict([ + headers = dict([ ('info', []), ('license', []), ('copyright', []), diff --git a/tests/formattedcode/test_output_jsonlines.py b/tests/formattedcode/test_output_jsonlines.py index 11a826f3c84..e492d26df47 100644 --- a/tests/formattedcode/test_output_jsonlines.py +++ b/tests/formattedcode/test_output_jsonlines.py @@ -24,7 +24,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import os @@ -54,7 +53,7 @@ def test_jsonlines_with_timing(): run_scan_click(['-i', '--timing', test_dir, '--json-lines', result_file]) with io.open(result_file, encoding='utf-8') as res: - file_results = [json.loads(line, object_pairs_hook=OrderedDict) for line in res] + file_results = [json.loads(line) for line in res] first_line = True for res in file_results: diff --git a/tests/formattedcode/test_output_spdx.py b/tests/formattedcode/test_output_spdx.py index a8f7a88eabe..39c637f3073 100644 --- a/tests/formattedcode/test_output_spdx.py +++ b/tests/formattedcode/test_output_spdx.py @@ -24,7 +24,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import os import re @@ -69,7 +68,7 @@ def load_and_clean_rdf(location): with io.open(location, encoding='utf-8') as co: content = co.read() content = strip_variable_text(content) - data = xmltodict.parse(content, dict_constructor=OrderedDict) + data = xmltodict.parse(content, dict_constructor=dict) return sort_nested(data) @@ -79,7 +78,7 @@ def sort_nested(data): sequence with any nested sequences or mappings sorted recursively. """ seqtypes = list, tuple - maptypes = OrderedDict, dict + maptypes = dict, dict coltypes = seqtypes + maptypes @@ -89,7 +88,7 @@ def sort_nested(data): if isinstance(v, coltypes): v = sort_nested(v) new_data.append((k, v)) - return OrderedDict(sorted(new_data, key=_sorter)) + return dict(sorted(new_data, key=_sorter)) elif isinstance(data, seqtypes): new_data = [] @@ -106,7 +105,7 @@ def _sorter(data): data structure composed of mappings and sequences. Used as a sorting key. """ seqtypes = list, tuple - maptypes = OrderedDict, dict + maptypes = dict, dict coltypes = seqtypes + maptypes if isinstance(data, maptypes): @@ -141,7 +140,7 @@ def check_rdf_scan(expected_file, result_file, regen=False): json.dump(result, o, indent=2) else: with io.open(expected_file, encoding='utf-8') as i: - expected = json.load(i, object_pairs_hook=OrderedDict) + expected = json.load(i) expected = load_and_clean_rdf(result_file) assert json.dumps(expected, indent=2) == json.dumps(result, indent=2) diff --git a/tests/licensedcode/licensedcode_test_utils.py b/tests/licensedcode/licensedcode_test_utils.py index 4dd5056b9dc..f4d5b4c948f 100644 --- a/tests/licensedcode/licensedcode_test_utils.py +++ b/tests/licensedcode/licensedcode_test_utils.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import os import traceback @@ -118,7 +117,7 @@ def __attrs_post_init__(self, *args, **kwargs): 'have explanatory notes: for: file://' + self.data_file) def to_dict(self): - dct = OrderedDict() + dct = {} if self.license_expressions: dct['license_expressions'] = self.license_expressions if self.expected_failure: diff --git a/tests/licensedcode/test_detection_validate.py b/tests/licensedcode/test_detection_validate.py index c23c2b52f79..fbcfc54e46a 100644 --- a/tests/licensedcode/test_detection_validate.py +++ b/tests/licensedcode/test_detection_validate.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import os import unittest @@ -151,7 +150,7 @@ def check_ignorable_clues(rule, regen=False): scan_data.update(api.get_urls(text_file, threshold=0)) scan_data.update(api.get_emails(text_file, threshold=0)) - results = OrderedDict() + results = {} for what, detections in scan_data.items(): # remove lines for detected in detections: @@ -163,7 +162,7 @@ def check_ignorable_clues(rule, regen=False): detections = sorted(set(chain(*(detected.values() for detected in detections)))) results['ignorable_' + what] = detections - results = OrderedDict([(k, v) for k, v in sorted(results.items()) if v]) + results = dict([(k, v) for k, v in sorted(results.items()) if v]) if regen: for k, v in results.items(): @@ -171,7 +170,7 @@ def check_ignorable_clues(rule, regen=False): rule.dump() # collect ignorables - expected = OrderedDict([ + expected = dict([ ('ignorable_copyrights', rule.ignorable_copyrights or []), ('ignorable_holders', rule.ignorable_holders or []), ('ignorable_authors', rule.ignorable_authors or []), @@ -179,7 +178,7 @@ def check_ignorable_clues(rule, regen=False): ('ignorable_emails', rule.ignorable_emails or []), ]) - expected = OrderedDict([(k, v) for k, v in sorted(expected.items()) if v]) + expected = dict([(k, v) for k, v in sorted(expected.items()) if v]) try: assert expected == results diff --git a/tests/licensedcode/test_match_spdx_lid.py b/tests/licensedcode/test_match_spdx_lid.py index c2573b913c4..9ed42583330 100644 --- a/tests/licensedcode/test_match_spdx_lid.py +++ b/tests/licensedcode/test_match_spdx_lid.py @@ -24,7 +24,6 @@ import os -from collections import OrderedDict import json import unittest @@ -91,7 +90,7 @@ def test_method(self): expected = results else: with open(expected_loc, 'rb') as ef: - expected = json.load(ef, encoding='utf-8', object_pairs_hook=OrderedDict) + expected = json.load(ef, encoding='utf-8') assert expected == results diff --git a/tests/licensedcode/test_models.py b/tests/licensedcode/test_models.py index 9bf2d408246..ca652528246 100644 --- a/tests/licensedcode/test_models.py +++ b/tests/licensedcode/test_models.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import json import os @@ -43,7 +42,7 @@ def check_json(expected, results, regen=False): with open(expected, mode) as ex: json.dump(results, ex, indent=2, separators=(',', ': ')) with open(expected) as ex: - expected = json.load(ex, object_pairs_hook=OrderedDict) + expected = json.load(ex) assert expected == results diff --git a/tests/licensedcode/test_plugin_license_policy.py b/tests/licensedcode/test_plugin_license_policy.py index 6be6fddd20a..59d488833aa 100644 --- a/tests/licensedcode/test_plugin_license_policy.py +++ b/tests/licensedcode/test_plugin_license_policy.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict from os.path import dirname from os.path import join @@ -179,39 +178,39 @@ def test_has_policy_duplicates_invalid_no_dupes(self): def test_load_license_policy_duplicate_keys(self): test_file = self.get_test_loc('plugin_license_policy/load_license_policy_duplicate_keys.yml') - expected = OrderedDict([ + expected = dict([ ('license_policies', [ - OrderedDict([ + dict([ ('license_key', 'broadcom-commercial'), ('label', 'Restricted License'), ('color_code', '#FFcc33'), ('icon', 'icon-warning-sign'), ]), - OrderedDict([ + dict([ ('license_key', 'bsd-1988'), ('label', 'Approved License'), ('color_code', '#008000'), ('icon', 'icon-ok-circle'), ]), - OrderedDict([ + dict([ ('license_key', 'esri-devkit'), ('label', 'Restricted License'), ('color_code', '#FFcc33'), ('icon', 'icon-warning-sign'), ]), - OrderedDict([ + dict([ ('license_key', 'oracle-java-ee-sdk-2010'), ('label', 'Restricted License'), ('color_code', '#FFcc33'), ('icon', 'icon-warning-sign'), ]), - OrderedDict([ + dict([ ('license_key', 'rh-eula'), ('label', 'Restricted License'), ('color_code', '#FFcc33'), ('icon', 'icon-warning-sign'), ]), - OrderedDict([ + dict([ ('license_key', 'broadcom-commercial'), ('label', 'Approved License'), ('color_code', '#008000'), @@ -227,33 +226,33 @@ def test_load_license_policy_duplicate_keys(self): def test_load_license_policy_valid(self): test_file = self.get_test_loc('plugin_license_policy/load_license_policy_valid.yml') - expected = OrderedDict([ + expected = dict([ ('license_policies', [ - OrderedDict([ + dict([ ('license_key', 'broadcom-commercial'), ('label', 'Restricted License'), ('color_code', '#FFcc33'), ('icon', 'icon-warning-sign'), ]), - OrderedDict([ + dict([ ('license_key', 'bsd-1988'), ('label', 'Approved License'), ('color_code', '#008000'), ('icon', 'icon-ok-circle'), ]), - OrderedDict([ + dict([ ('license_key', 'esri-devkit'), ('label', 'Restricted License'), ('color_code', '#FFcc33'), ('icon', 'icon-warning-sign'), ]), - OrderedDict([ + dict([ ('license_key', 'oracle-java-ee-sdk-2010'), ('label', 'Restricted License'), ('color_code', '#FFcc33'), ('icon', 'icon-warning-sign'), ]), - OrderedDict([ + dict([ ('license_key', 'rh-eula'), ('label', 'Restricted License'), ('color_code', '#FFcc33'), @@ -269,7 +268,7 @@ def test_load_license_policy_valid(self): def test_load_license_policy_empty(self): test_file = self.get_test_loc('plugin_license_policy/load_license_policy_empty.yml') - expected = OrderedDict([ + expected = dict([ (u'license_policies', []) ]) diff --git a/tests/licensedcode/test_tokenize.py b/tests/licensedcode/test_tokenize.py index d0db359963f..776ee588112 100644 --- a/tests/licensedcode/test_tokenize.py +++ b/tests/licensedcode/test_tokenize.py @@ -25,7 +25,6 @@ import io -from collections import OrderedDict import itertools import json import os @@ -338,7 +337,7 @@ def test_query_tokenizer_can_parse_ill_formed_legacy_template_from_file(self, re json.dump(result, ex, indent=2, separators=(',', ': ')) with io.open(expected_file, encoding='utf-8') as ex: - expected = json.load(ex, object_pairs_hook=OrderedDict) + expected = json.load(ex) assert expected == result diff --git a/tests/packagedcode/packages_test_utils.py b/tests/packagedcode/packages_test_utils.py index cf25bc0d25d..5559276ea7a 100644 --- a/tests/packagedcode/packages_test_utils.py +++ b/tests/packagedcode/packages_test_utils.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import os.path import json import shutil @@ -54,7 +53,7 @@ def check_package(self, package, expected_loc, regen=False): shutil.copy(regened_exp_loc, expected_loc) with open(expected_loc, 'rb') as ex: - expected = json.load(ex, encoding='utf-8', object_pairs_hook=OrderedDict) + expected = json.load(ex, encoding='utf-8') try: assert expected == results @@ -83,7 +82,7 @@ def check_packages(self, packages, expected_loc, regen=False): shutil.copy(regened_exp_loc, expected_loc) with open(expected_loc, 'rb') as ex: - expected_packages = json.load(ex, encoding='utf-8', object_pairs_hook=OrderedDict) + expected_packages = json.load(ex, encoding='utf-8') for expected_package, result in zip(expected_packages, results): assert expected_package == result diff --git a/tests/packagedcode/test_chef.py b/tests/packagedcode/test_chef.py index 08ce76b0a05..7fb1c25f73d 100644 --- a/tests/packagedcode/test_chef.py +++ b/tests/packagedcode/test_chef.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import os.path from packagedcode import chef @@ -49,7 +48,7 @@ def test_parse_from_rb_dependency_requirement(self): self.check_package(chef.parse(test_file), expected_file, regen=False) def test_build_package(self): - package_data = OrderedDict( + package_data = dict( name='test', version='0.01', description='test package', @@ -59,7 +58,7 @@ def test_build_package(self): self.check_package(chef.build_package(package_data), expected_file, regen=False) def test_build_package_long_description(self): - package_data = OrderedDict( + package_data = dict( name='test', version='0.01', long_description='test package', @@ -69,7 +68,7 @@ def test_build_package_long_description(self): self.check_package(chef.build_package(package_data), expected_file, regen=False) def test_build_package_dependencies(self): - package_data = OrderedDict( + package_data = dict( name='test', version='0.01', long_description='test package', @@ -80,7 +79,7 @@ def test_build_package_dependencies(self): self.check_package(chef.build_package(package_data), expected_file, regen=False) def test_build_package_parties(self): - package_data = OrderedDict( + package_data = dict( name='test', version='0.01', long_description='test package', @@ -92,7 +91,7 @@ def test_build_package_parties(self): self.check_package(chef.build_package(package_data), expected_file, regen=False) def test_build_package_code_view_url_and_bug_tracking_url(self): - package_data = OrderedDict( + package_data = dict( name='test', version='0.01', long_description='test package', diff --git a/tests/packagedcode/test_conda.py b/tests/packagedcode/test_conda.py index a6a068f4595..ccdc9e831a7 100644 --- a/tests/packagedcode/test_conda.py +++ b/tests/packagedcode/test_conda.py @@ -24,7 +24,6 @@ import os -from collections import OrderedDict from packages_test_utils import PackageTester from packagedcode import conda @@ -37,12 +36,12 @@ class TestConda(PackageTester): def test_parse_get_varialble(self): test_file = self.get_test_loc('conda/meta.yaml') results = conda.get_variables(test_file) - assert OrderedDict([(u'version', u'0.45.0'), (u'sha256', u'bc7512f2eef785b037d836f4cc6faded457ac277f75c6e34eccd12da7c85258f')]) == results + assert dict([(u'version', u'0.45.0'), (u'sha256', u'bc7512f2eef785b037d836f4cc6faded457ac277f75c6e34eccd12da7c85258f')]) == results def test_get_yaml_data(self): test_file = self.get_test_loc('conda/meta.yaml') results = conda.get_yaml_data(test_file) - assert (u'package', OrderedDict([(u'name', u'abeona'), (u'version', u'0.45.0')])) == list(results.items())[0] + assert (u'package', dict([(u'name', u'abeona'), (u'version', u'0.45.0')])) == list(results.items())[0] def test_parse(self): test_file = self.get_test_loc('conda/meta.yaml') diff --git a/tests/packagedcode/test_gemfile_lock.py b/tests/packagedcode/test_gemfile_lock.py index fb213656368..5c89a95fd23 100644 --- a/tests/packagedcode/test_gemfile_lock.py +++ b/tests/packagedcode/test_gemfile_lock.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import json import os import shutil @@ -52,7 +51,7 @@ def check_results(self, results, expected_loc, regen=False): shutil.copy(regened_exp_loc, expected_loc) with open(expected_loc) as ex: - expected = json.load(ex, object_pairs_hook=OrderedDict) + expected = json.load(ex) try: assert expected == results @@ -356,7 +355,7 @@ def test_Gem_to_dict(self): (u'tag', None), (u'requirements', []), (u'dependencies', - OrderedDict([(u'a@1', OrderedDict([(u'b@2', OrderedDict())]))])) + dict([(u'a@1', dict([(u'b@2', {})]))])) ] results = a.to_dict() diff --git a/tests/packagedcode/test_godeps.py b/tests/packagedcode/test_godeps.py index 184b559145d..c7132a3add0 100644 --- a/tests/packagedcode/test_godeps.py +++ b/tests/packagedcode/test_godeps.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import os @@ -57,12 +56,12 @@ def test_parse_basic(self): 'import_path': u'github.com/kr/hk', 'go_version': u'go1.1.2', 'dependencies': [ - OrderedDict([ + dict([ ('import_path', u'code.google.com/p/go-netrc/netrc'), ('revision', u'28676070ab99'), ('comment', None) ]), - OrderedDict([ + dict([ ('import_path', u'github.com/kr/binarydist'), ('revision', u'3380ade90f8b0dfa3e363fd7d7e941fa857d0d13'), ('comment', None) diff --git a/tests/packagedcode/test_jar_manifest.py b/tests/packagedcode/test_jar_manifest.py index 4342f61810e..da81e235648 100644 --- a/tests/packagedcode/test_jar_manifest.py +++ b/tests/packagedcode/test_jar_manifest.py @@ -24,7 +24,6 @@ import io -from collections import OrderedDict import json import os.path @@ -54,7 +53,7 @@ def check_parse_manifest(self, test_manifest, regen=False): json.dump(parsed_manifest, ex, indent=2) with io.open(expected_manifest_loc, encoding='utf-8') as ex: - expected = json.load(ex, object_pairs_hook=OrderedDict) + expected = json.load(ex) assert json.dumps(expected) == json.dumps(parsed_manifest) @@ -75,7 +74,7 @@ def check_get_normalized_package_data(self, test_manifest, regen=False): json.dump(package, ex, indent=2) with io.open(expected_json_loc, 'rb') as ex: - expected = json.load(ex, encoding='utf-8', object_pairs_hook=OrderedDict) + expected = json.load(ex, encoding='utf-8') assert json.dumps(expected) == json.dumps(package) diff --git a/tests/packagedcode/test_maven.py b/tests/packagedcode/test_maven.py index 881614e3754..090e9cf557a 100644 --- a/tests/packagedcode/test_maven.py +++ b/tests/packagedcode/test_maven.py @@ -24,7 +24,6 @@ import io -from collections import OrderedDict import json import os.path @@ -78,7 +77,7 @@ def compare_results(results, test_pom_loc, expected_json_loc, regen=False): json.dump(results, ex, indent=2) with io.open(expected_json_loc, encoding='utf-8') as ex: - expected = json.load(ex, object_pairs_hook=OrderedDict) + expected = json.load(ex) results_dump = json.dumps(results, indent=2) expected_dump = json.dumps(expected, indent=2) @@ -176,7 +175,7 @@ def test_pom_issue_management_properties_are_resolved(self): test_loc = self.get_test_loc('maven2/xml-format-maven-plugin-3.0.6.pom') pom = maven.MavenPom(test_loc) pom.resolve() - expected = OrderedDict([ + expected = dict([ (u'system', 'GitHub Issues'), (u'url', 'https://github.com/acegi/xml-format-maven-plugin/issues')] ) diff --git a/tests/packagedcode/test_package_models.py b/tests/packagedcode/test_package_models.py index 68cee50a002..bf6e3937ab7 100644 --- a/tests/packagedcode/test_package_models.py +++ b/tests/packagedcode/test_package_models.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import os.path from packagedcode import models @@ -43,7 +42,7 @@ def test_Package_creation_and_dump(self): ('namespace', None), ('name', u'someAndroidPAcakge'), ('version', None), - ('qualifiers', OrderedDict()), + ('qualifiers', {}), ('subpath', None), ('primary_language', u'Java'), ('description', None), @@ -98,18 +97,18 @@ def test_Package_model_qualifiers_are_serialized_as_mappings(self): type='maven', name='this', version='23', - qualifiers=OrderedDict(this='that') + qualifiers=dict(this='that') ) - assert OrderedDict(this='that') == package.to_dict()['qualifiers'] + assert dict(this='that') == package.to_dict()['qualifiers'] def test_Package_model_qualifiers_are_kept_as_mappings(self): package = models.Package( type='maven', name='this', version='23', - qualifiers=OrderedDict(this='that') + qualifiers=dict(this='that') ) - assert OrderedDict(this='that') == package.qualifiers + assert dict(this='that') == package.qualifiers def test_Package_model_qualifiers_are_converted_to_mappings(self): package = models.Package( @@ -118,7 +117,7 @@ def test_Package_model_qualifiers_are_converted_to_mappings(self): version='23', qualifiers='this=that' ) - assert OrderedDict(this='that') == package.qualifiers + assert dict(this='that') == package.qualifiers def test_Package_full(self): diff --git a/tests/packagedcode/test_pypi.py b/tests/packagedcode/test_pypi.py index 50db424479e..ad351c4d1e7 100644 --- a/tests/packagedcode/test_pypi.py +++ b/tests/packagedcode/test_pypi.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import os from unittest.case import skipIf from unittest.case import expectedFailure @@ -68,7 +67,7 @@ def test_parse_metadata(self): ] assert expected_classifiers == package.keywords expected = [ - OrderedDict([ + dict([ ('type', u'person'), ('role', u'contact'), ('name', u'Benjamin Peterson'), ('email', None), ('url', None)]) ] @@ -83,7 +82,7 @@ def test_parse_pkg_info(self): assert 'Import CSV and Excel files' == package.description assert 'BSD' in package.declared_license assert 'http://nexb.com' == package.homepage_url - expected = [OrderedDict([('type', u'person'), ('role', u''), ('name', u'Francois Granade'), ('email', None), ('url', None)])] + expected = [dict([('type', u'person'), ('role', u''), ('name', u'Francois Granade'), ('email', None), ('url', None)])] assert expected == [p.to_dict() for p in package.parties] @skipIf(on_windows, 'Somehow this fails on Windows') @@ -490,7 +489,7 @@ def test_parse_setup_py_with_computed_versions(self, test_loc, expected_loc, reg with open(expected_loc, 'rb') as ex: expected = json.load( - ex, encoding='utf-8', object_pairs_hook=OrderedDict) + ex, encoding='utf-8') try: assert expected == results diff --git a/tests/packagedcode/test_rpm.py b/tests/packagedcode/test_rpm.py index 01bcd41c470..3dfa432d944 100644 --- a/tests/packagedcode/test_rpm.py +++ b/tests/packagedcode/test_rpm.py @@ -24,7 +24,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import os @@ -44,7 +43,7 @@ def test_parse_to_package(self): ('namespace', None), ('name', 'libproxy-bin'), ('version', '0.3.0-4.el6_3'), - ('qualifiers', OrderedDict()), + ('qualifiers', {}), ('subpath', None), ('primary_language', None), ('description', @@ -52,7 +51,7 @@ def test_parse_to_package(self): 'The libproxy-bin package contains the proxy binary for libproxy'), ('release_date', None), ('parties', [ - OrderedDict([ + dict([ ('type', None), ('role', 'vendor'), ('name', 'CentOS'), @@ -155,7 +154,7 @@ def check_json(result, expected_file, regen=False): reg.write(json.dumps(result, indent=4, separators=(',', ': '))) with io.open(expected_file, encoding='utf-8') as exp: - expected = json.load(exp, object_pairs_hook=OrderedDict) + expected = json.load(exp) assert json.dumps(expected) == json.dumps(result) diff --git a/tests/packagedcode/test_rubygems.py b/tests/packagedcode/test_rubygems.py index 9671a9f00a5..3a2a6a06d48 100644 --- a/tests/packagedcode/test_rubygems.py +++ b/tests/packagedcode/test_rubygems.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import os @@ -134,7 +133,7 @@ def check_rubygem(self): json.dump(package, ex, indent=2) with io.open(expected_json_loc, encoding='utf-8') as ex: - expected = json.load(ex, object_pairs_hook=OrderedDict) + expected = json.load(ex) assert expected == package if isinstance(test_name, bytes): diff --git a/tests/packagedcode/test_win_pe.py b/tests/packagedcode/test_win_pe.py index d16f78f67ef..a51a1c4b88e 100644 --- a/tests/packagedcode/test_win_pe.py +++ b/tests/packagedcode/test_win_pe.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import os @@ -48,7 +47,7 @@ def check_win_pe(self, test_file, regen=False): json.dump(result, out, indent=2) with io.open(expected_file, encoding='utf-8') as expect: - expected = json.load(expect, object_pairs_hook=OrderedDict) + expected = json.load(expect) assert expected == result diff --git a/tests/scancode/test_api.py b/tests/scancode/test_api.py index 35f43438137..c64ff3a7c48 100644 --- a/tests/scancode/test_api.py +++ b/tests/scancode/test_api.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import os from commoncode.testcase import FileBasedTesting @@ -88,15 +87,15 @@ def test_get_file_info_include_size(self): def test_get_copyrights_include_copyrights_and_authors(self): test_file = self.get_test_loc('api/copyright/iproute.c') cops = api.get_copyrights(test_file) - expected = OrderedDict([ + expected = dict([ ('copyrights', [ - OrderedDict([(u'value', u'Copyright (c) 2010 Patrick McHardy'), (u'start_line', 2), (u'end_line', 2)]) + dict([(u'value', u'Copyright (c) 2010 Patrick McHardy'), (u'start_line', 2), (u'end_line', 2)]) ]), ('holders', [ - OrderedDict([(u'value', u'Patrick McHardy'), (u'start_line', 2), (u'end_line', 2)]) + dict([(u'value', u'Patrick McHardy'), (u'start_line', 2), (u'end_line', 2)]) ]), ('authors', [ - OrderedDict([(u'value', u'Patrick McHardy '), (u'start_line', 11), (u'end_line', 11)]) + dict([(u'value', u'Patrick McHardy '), (u'start_line', 11), (u'end_line', 11)]) ]), ]) @@ -106,9 +105,9 @@ def test_get_emails(self): test_file = self.get_test_loc('api/email/3w-xxxx.c') results = api.get_emails(test_file) expected = dict(emails=[ - OrderedDict([(u'email', u'linux@3ware.com'), (u'start_line', 1), (u'end_line', 1)]), - OrderedDict([(u'email', u'acme@conectiva.com.br'), (u'start_line', 3), (u'end_line', 3)]), - OrderedDict([(u'email', u'andre@suse.com'), (u'start_line', 5), (u'end_line', 5)]) + dict([(u'email', u'linux@3ware.com'), (u'start_line', 1), (u'end_line', 1)]), + dict([(u'email', u'acme@conectiva.com.br'), (u'start_line', 3), (u'end_line', 3)]), + dict([(u'email', u'andre@suse.com'), (u'start_line', 5), (u'end_line', 5)]) ]) assert expected == results results = api.get_emails(test_file, threshold=0) @@ -118,7 +117,7 @@ def test_get_emails_with_threshold(self): test_file = self.get_test_loc('api/email/3w-xxxx.c') results = api.get_emails(test_file, threshold=1) expected = dict(emails=[ - OrderedDict([(u'email', u'linux@3ware.com'), (u'start_line', 1), (u'end_line', 1)]), + dict([(u'email', u'linux@3ware.com'), (u'start_line', 1), (u'end_line', 1)]), ]) assert expected == results @@ -126,9 +125,9 @@ def test_get_urls(self): test_file = self.get_test_loc('api/url/IMarkerActionFilter.java') results = api.get_urls(test_file) expected = dict(urls=[ - OrderedDict([(u'url', u'http://www.eclipse.org/legal/epl-v10.html'), (u'start_line', 2), (u'end_line', 2)]), - OrderedDict([(u'url', u'https://github.com/rpm-software-management'), (u'start_line', 4), (u'end_line', 4)]), - OrderedDict([(u'url', u'https://gitlab.com/Conan_Kudo'), (u'start_line', 6), (u'end_line', 6)]), + dict([(u'url', u'http://www.eclipse.org/legal/epl-v10.html'), (u'start_line', 2), (u'end_line', 2)]), + dict([(u'url', u'https://github.com/rpm-software-management'), (u'start_line', 4), (u'end_line', 4)]), + dict([(u'url', u'https://gitlab.com/Conan_Kudo'), (u'start_line', 6), (u'end_line', 6)]), ]) assert expected == results results = api.get_urls(test_file, threshold=0) @@ -137,7 +136,7 @@ def test_get_urls(self): def test_get_urls_with_threshold(self): test_file = self.get_test_loc('api/url/IMarkerActionFilter.java') expected = dict(urls=[ - OrderedDict([(u'url', u'http://www.eclipse.org/legal/epl-v10.html'), (u'start_line', 2), (u'end_line', 2)]) + dict([(u'url', u'http://www.eclipse.org/legal/epl-v10.html'), (u'start_line', 2), (u'end_line', 2)]) ]) results = api.get_urls(test_file, threshold=1) assert expected == results diff --git a/tests/scancode/test_cli.py b/tests/scancode/test_cli.py index 21d78737468..a09bc066f3a 100644 --- a/tests/scancode/test_cli.py +++ b/tests/scancode/test_cli.py @@ -23,7 +23,6 @@ # Visit https://github.com/nexB/scancode-toolkit/ for support and download. -from collections import OrderedDict import io import json import os @@ -376,7 +375,7 @@ def test_scan_works_with_multiple_processes_and_timeouts(): (u'scan_errors', [u'ERROR: for scanner: emails:\nERROR: Processing interrupted: timeout after 0 seconds.'])] ] - result_json = json.loads(open(result_file).read(), object_pairs_hook=OrderedDict) + result_json = json.loads(open(result_file).read()) assert sorted(sorted(x) for x in expected) == sorted(sorted(x.items()) for x in result_json['files'])