Skip to content

Commit

Permalink
Remove unused imports and other minor cleanups #295
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Dec 4, 2020
1 parent 11165a4 commit 30ebe90
Show file tree
Hide file tree
Showing 28 changed files with 26 additions and 58 deletions.
1 change: 0 additions & 1 deletion etc/scripts/add_spdx_keys_as_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import os.path

import click
click.disable_unicode_literals_warning = True

import synclic

Expand Down
1 change: 0 additions & 1 deletion etc/scripts/buildcopytests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import sys

import click
click.disable_unicode_literals_warning = True

import scancode_config

Expand Down
1 change: 0 additions & 1 deletion etc/scripts/buildlictests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import sys

import click
click.disable_unicode_literals_warning = True
from itertools import chain

import scancode_config
Expand Down
1 change: 0 additions & 1 deletion etc/scripts/buildrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import attr
import click
click.disable_unicode_literals_warning = True
from license_expression import Licensing
import saneyaml

Expand Down
1 change: 0 additions & 1 deletion etc/scripts/genlicspdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import os

import click
click.disable_unicode_literals_warning = True

from licensedcode.models import load_licenses
from scancode.cli import run_scan
Expand Down
1 change: 0 additions & 1 deletion etc/scripts/genurlrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import os

import click
click.disable_unicode_literals_warning = True

from license_expression import Licensing

Expand Down
1 change: 0 additions & 1 deletion etc/scripts/synclic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import zipfile

import click
click.disable_unicode_literals_warning = True
import requests

from commoncode import fetch
Expand Down
1 change: 0 additions & 1 deletion etc/scripts/updateignorables.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@


import click
click.disable_unicode_literals_warning = True

from licensedcode import cache
from licensedcode import models
Expand Down
4 changes: 2 additions & 2 deletions src/cluecode/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def re_filt(matches):
continue
yield key, match, line, lineno

matcher = re.compile(pattern, re.UNICODE | re.I).match
matcher = re.compile(pattern, re.UNICODE | re.IGNORECASE).match
return re_filt

# A good reference page of email address regex is:
Expand Down Expand Up @@ -575,7 +575,7 @@ def find_pattern(location, pattern, unique=False):
Return all match groups joined as one unicode string.
Only return unique items if unique is True.
"""
pattern = re.compile(pattern, re.UNICODE | re.I)
pattern = re.compile(pattern, re.UNICODE | re.IGNORECASE)
matches = find(location, [(None, pattern,)])
if unique:
matches = unique_filter(matches)
Expand Down
10 changes: 6 additions & 4 deletions src/formattedcode/output_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
# ScanCode is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.


import io
from operator import itemgetter
from os.path import abspath
Expand All @@ -35,7 +34,6 @@
import click
import simplejson

from commoncode.fileutils import PATH_TYPE
from commoncode.fileutils import as_posixpath
from commoncode.fileutils import copytree
from commoncode.fileutils import delete
Expand Down Expand Up @@ -96,8 +94,12 @@ class CustomTemplateOutput(OutputPlugin):

PluggableCommandLineOption(('--custom-template',),
type=click.Path(
exists=True, file_okay=True, dir_okay=False,
readable=True, path_type=PATH_TYPE),
exists=True,
file_okay=True,
dir_okay=False,
readable=True,
path_type=str
),
required_options=['custom_output'],
metavar='FILE',
help='Use this Jinja template FILE as a custom template.',
Expand Down
4 changes: 2 additions & 2 deletions src/licensedcode/dmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def logger_debug(*args): pass
logger = logging.getLogger(__name__)

def logger_debug(*args):
return logger.debug(' '.join(isinstance(a, basestring) and a or repr(a) for a in args))
return logger.debug(' '.join(isinstance(a, str) and a or repr(a) for a in args))

logging.basicConfig(stream=sys.stdout)
logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -103,7 +103,7 @@ def int2unicode(nums):
"""
Convert an array of positive integers to a unicode string.
"""
return u''.join(unichr(i + 1) for i in nums)
return u''.join(chr(i + 1) for i in nums)


def trim(diffs):
Expand Down
1 change: 0 additions & 1 deletion src/packagedcode/alpine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from datetime import datetime
import email
import io
import os
from os import path
import posixpath
import re
Expand Down
2 changes: 0 additions & 2 deletions src/packagedcode/bower.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.


from functools import partial
import io
import json
import logging
Expand All @@ -32,7 +31,6 @@
from packageurl import PackageURL

from commoncode import filetype
from commoncode import ignore
from packagedcode import models
from packagedcode.utils import combine_expressions

Expand Down
6 changes: 0 additions & 6 deletions src/packagedcode/golang.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@
# ScanCode is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.


import io
import logging
import re

import attr
from packageurl import PackageURL

from commoncode import filetype
from commoncode import fileutils
from packagedcode import go_mod
from packagedcode import models


"""
Handle Go packages including go.mod and go.sum files.
"""
Expand Down
2 changes: 0 additions & 2 deletions src/packagedcode/opam.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import attr
from packageurl import PackageURL

from commoncode import filetype
from commoncode import fileutils
from packagedcode import models


Expand Down
1 change: 0 additions & 1 deletion src/packagedcode/phpcomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import sys

import attr
from packageurl import PackageURL

from commoncode import filetype
from commoncode import fileutils
Expand Down
1 change: 0 additions & 1 deletion src/packagedcode/plugin_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import attr
import click
click.disable_unicode_literals_warning = True

from plugincode.scan import ScanPlugin
from plugincode.scan import scan_impl
Expand Down
6 changes: 3 additions & 3 deletions src/packagedcode/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def find_dunder_version(location):
SPDX-License-Identifier: BSD-3-Clause
(C) 2001-2020 Chris Liechti <[email protected]>
"""
pattern = re.compile(r"^__version__\s*=\s*['\"]([^'\"]*)['\"]", re.M)
pattern = re.compile(r"^__version__\s*=\s*['\"]([^'\"]*)['\"]", re.MULTILINE)
match = find_pattern(location, pattern)
if TRACE: logger_debug('find_dunder_version:', 'location:', location, 'match:', match)
return match
Expand All @@ -457,7 +457,7 @@ def find_plain_version(location):
Return a plain version attribute string or None from searching the module
file at `location`.
"""
pattern = re.compile(r"^version\s*=\s*['\"]([^'\"]*)['\"]", re.M)
pattern = re.compile(r"^version\s*=\s*['\"]([^'\"]*)['\"]", re.MULTILINE)
match = find_pattern(location, pattern)
if TRACE: logger_debug('find_plain_version:', 'location:', location, 'match:', match)
return match
Expand All @@ -479,7 +479,7 @@ def find_setup_py_dunder_version(location):
SPDX-License-Identifier: BSD-3-Clause
(C) 2001-2020 Chris Liechti <[email protected]>
"""
pattern = re.compile(r"^\s*version\s*=\s*(.*__version__)", re.M)
pattern = re.compile(r"^\s*version\s*=\s*(.*__version__)", re.MULTILINE)
match = find_pattern(location, pattern)
if TRACE: logger_debug('find_setup_py_dunder_version:', 'location:', location, 'match:', match)
return match
Expand Down
2 changes: 0 additions & 2 deletions src/packagedcode/recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@

from commoncode import filetype
from commoncode.fileutils import file_name
from commoncode.fileutils import fsencode
from commoncode.fileutils import splitext_name
from commoncode.system import on_linux
from packagedcode import PACKAGE_TYPES
from typecode import contenttype

Expand Down
7 changes: 2 additions & 5 deletions src/scancode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class WindowsError(Exception):
pass

import click # NOQA
click.disable_unicode_literals_warning = True


from commoncode import cliutils
Expand All @@ -55,7 +54,6 @@ class WindowsError(Exception):
from commoncode.cliutils import progressmanager
from commoncode.cliutils import PluggableCommandLineOption
from commoncode.fileutils import as_posixpath
from commoncode.fileutils import PATH_TYPE
from commoncode.fileutils import POSIX_PATH_SEP
from commoncode.timeutils import time2tstamp
from commoncode.resource import Codebase
Expand Down Expand Up @@ -191,8 +189,7 @@ def validate_depth(ctx, param, value):

@click.argument('input',
metavar='<OUTPUT FORMAT OPTION(s)> <input>...', nargs=-1,
# ensure that the input path is bytes on Linux, unicode elsewhere
type=click.Path(exists=True, readable=True, path_type=PATH_TYPE))
type=click.Path(exists=True, readable=True, path_type=str))

@click.option('--strip-root',
is_flag=True,
Expand Down Expand Up @@ -526,7 +523,7 @@ def echo_func(*_args, **_kwargs):
if not common_prefix:
# we have no common prefix, but all relative. therefore the
# parent/root is the current ddirectory
common_prefix = PATH_TYPE('.')
common_prefix = str('.')

elif not os.path.isdir(common_prefix):
msg = 'Invalid inputs: all input paths must share a common parent directory.'
Expand Down
1 change: 0 additions & 1 deletion src/scancode/cli_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import os
import time

from commoncode.system import on_linux
from commoncode.system import on_windows
from scancode_config import scancode_root_dir

Expand Down
19 changes: 8 additions & 11 deletions src/textcode/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import re
import string

from commoncode.text import toascii

"""
Extract raw ASCII strings from (possibly) binary strings.
Expand All @@ -50,20 +49,18 @@
MIN_LEN = 4
MIN_LEN_STR = b'4'

def strings_from_file(location, buff_size=1024 * 1024, ascii=False, clean=True, min_len=MIN_LEN):
def strings_from_file(location, buff_size=1024 * 1024, clean=True, min_len=MIN_LEN):
"""
Yield unicode strings made only of ASCII characters found in file at location.
Process the file in chunks (to limit memory usage). If ascii is True, strings
are converted to plain ASCII "str or byte" strings instead of unicode.
Yield unicode strings made only of printable ASCII characters found in file
at `location``. Process the file in chunks of `buff_size` bytes (to limit
memory usage).
"""
with open(location, 'rb') as f:
while 1:
buf = f.read(buff_size)
if not buf:
break
for s in strings_from_string(buf, clean=clean, min_len=min_len):
if ascii:
s = toascii(s)
s = s.strip()
if len(s) >= min_len:
yield s
Expand Down Expand Up @@ -94,10 +91,10 @@ def strings_from_file(location, buff_size=1024 * 1024, ascii=False, clean=True,

def strings_from_string(binary_string, clean=False, min_len=0):
"""
Yield strings extracted from a (possibly binary) string. The strings are ASCII
printable characters only. If clean is True, also clean and filter short and
repeated strings.
Note: we do not keep the offset of where a string was found (e.g. match.start).
Yield strings extracted from a (possibly binary) string `binary_string`. The
strings are ASCII printable characters only. If `clean` is True, also clean
and filter short and repeated strings. Note: we do not keep the offset of
where a string was found (e.g. match.start).
"""
for match in ascii_strings(binary_string):
s = decode(match.group())
Expand Down
1 change: 0 additions & 1 deletion tests/cluecode/test_plugin_email_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import os

import click
click.disable_unicode_literals_warning = True

from commoncode.testcase import FileDrivenTesting

Expand Down
1 change: 0 additions & 1 deletion tests/licensedcode/test_plugin_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import os

import click
click.disable_unicode_literals_warning = True
import pytest

from commoncode.testcase import FileDrivenTesting
Expand Down
1 change: 0 additions & 1 deletion tests/licensedcode/test_plugin_license_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import os

import click
click.disable_unicode_literals_warning = True

from commoncode.testcase import FileDrivenTesting

Expand Down
4 changes: 1 addition & 3 deletions tests/scancode/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
import os

import click
click.disable_unicode_literals_warning = True
import pytest

from commoncode import fileutils
from commoncode.fileutils import fsencode
from commoncode.testcase import FileDrivenTesting
from commoncode.system import on_linux
from commoncode.system import on_mac
Expand Down Expand Up @@ -442,7 +440,7 @@ def test_scan_does_not_fail_when_scanning_unicode_test_files_from_express():
test_path = u'unicode_fixtures.tar.gz'

test_dir = test_env.extract_test_tar_raw(test_path)
test_dir = fsencode(test_dir)
test_dir = os.fsencode(test_dir)

args = ['-n0', '--info', '--license', '--copyright', '--package', '--email',
'--url', '--strip-root', '--json', '-', test_dir]
Expand Down
2 changes: 2 additions & 0 deletions tests/scancode/test_scancode_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
- code style
- ABOUT files
- release archives creation
NOTE: it has imports limited to the standard library by design
"""


Expand Down
1 change: 0 additions & 1 deletion tests/summarycode/test_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import os

import click
click.disable_unicode_literals_warning = True
import pytest

from commoncode.testcase import FileDrivenTesting
Expand Down

0 comments on commit 30ebe90

Please sign in to comment.