Skip to content

Commit d1fae02

Browse files
Abhishek-Dev09pombredanne
authored andcommitted
Drop Python 2 for scancode-toolkit
Signed-off-by: Abhishek Kumar <abhishek.kasyap09@gmail.com>
1 parent b4ea9c6 commit d1fae02

36 files changed

Lines changed: 80 additions & 326 deletions

src/formattedcode/output_html.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
from commoncode.fileutils import fsencode
5050
from commoncode.fileutils import parent_directory
5151
from commoncode.system import on_linux
52-
from commoncode.system import py2
53-
from commoncode.system import py3
5452

5553
from plugincode.output import output_impl
5654
from plugincode.output import OutputPlugin
@@ -122,10 +120,6 @@ def is_enabled(self, custom_output, custom_template, **kwargs):
122120
def process_codebase(self, codebase, custom_output, custom_template, **kwargs):
123121
results = self.get_files(codebase, **kwargs)
124122
version = codebase.get_or_create_current_header().tool_version
125-
126-
if on_linux and py2:
127-
custom_template = fsencode(custom_template)
128-
129123
template_loc = custom_template
130124
output_file = custom_output
131125
write_templated(output_file, results, version, template_loc)
@@ -329,12 +323,8 @@ def create_html_app(output_file, results, version, scanned_path): # NOQA
329323

330324
# write json data
331325
# FIXME: this should a regular JSON scan format
332-
if py2:
333-
mode = 'wb'
334-
prefix = b'data='
335-
if py3:
336-
mode = 'w'
337-
prefix = u'data='
326+
mode = 'w'
327+
prefix = u'data='
338328
with io.open(join(target_assets_dir, 'data.js'), mode) as f:
339329
f.write(prefix)
340330
simplejson.dump(results, f, iterable_as_array=True)

src/formattedcode/output_json.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
from six import string_types
3232

3333
from commoncode import compat
34-
from commoncode.system import py2
35-
from commoncode.system import py3
3634
from plugincode.output import output_impl
3735
from plugincode.output import OutputPlugin
3836
from scancode import CommandLineOption
@@ -65,19 +63,11 @@ def logger_debug(*args):
6563
and a or repr(a) for a in args))
6664

6765

68-
if py2:
69-
mode = 'wb'
70-
space = b' '
71-
comma = b','
72-
colon = b':'
73-
eol = b'\n'
74-
75-
if py3:
76-
mode = 'w'
77-
space = u' '
78-
comma = u','
79-
colon = u':'
80-
eol = u'\n'
66+
mode = 'w'
67+
space = u' '
68+
comma = u','
69+
colon = u':'
70+
eol = u'\n'
8171

8272

8373
@output_impl

src/formattedcode/output_jsonlines.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
import simplejson
3131

32-
from commoncode.system import py2
33-
from commoncode.system import py3
3432
from plugincode.output import output_impl
3533
from plugincode.output import OutputPlugin
3634
from scancode import CommandLineOption
@@ -42,21 +40,12 @@
4240
"""
4341

4442

45-
if py2:
46-
mode = 'wb'
47-
space = b' '
48-
comma = b','
49-
colon = b':'
50-
eol = b'\n'
51-
file_key = b'files'
52-
53-
if py3:
54-
mode = 'w'
55-
space = u' '
56-
comma = u','
57-
colon = u':'
58-
eol = u'\n'
59-
file_key = u'files'
43+
mode = 'w'
44+
space = u' '
45+
comma = u','
46+
colon = u':'
47+
eol = u'\n'
48+
file_key = u'files'
6049

6150

6251
@output_impl

src/licensedcode/cache.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from commoncode.fileutils import resource_iter
3939
from commoncode.fileutils import create_dir
4040
from commoncode import ignore
41-
from commoncode.system import py3
4241

4342
from scancode_config import scancode_cache_dir
4443
from scancode_config import scancode_src_dir
@@ -285,10 +284,7 @@ def load_index(cache_file, use_loads=False):
285284
'Please delete "{cache_file}" and retry.\n'
286285
'If the problem persists, copy this error message '
287286
'and submit a bug report.\n'.format(**locals()))
288-
if py3:
289-
raise ex_type(message).with_traceback(ex_traceback)
290-
else:
291-
six.reraise(ex_type, message, ex_traceback)
287+
raise ex_type(message).with_traceback(ex_traceback)
292288

293289

294290
_ignored_from_hash = partial(
@@ -314,8 +310,7 @@ def tree_checksum(tree_base_dir=scancode_src_dir, _ignored=_ignored_from_hash):
314310
resources = resource_iter(tree_base_dir, ignored=_ignored, with_dirs=False)
315311
hashable = (pth + str(getmtime(pth)) + str(getsize(pth)) for pth in resources)
316312
hashable = ''.join(sorted(hashable))
317-
if py3:
318-
hashable=hashable.encode('utf-8')
313+
hashable=hashable.encode('utf-8')
319314
return md5(hashable).hexdigest()
320315

321316

src/licensedcode/match_hash.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
from six import string_types
3131

32-
from commoncode.system import py2
33-
from commoncode.system import py3
3432
from licensedcode.match import LicenseMatch
3533
from licensedcode.spans import Span
3634

@@ -65,10 +63,7 @@ def tokens_hash(tokens):
6563
"""
6664
Return a digest binary string computed from a sequence of numeric token ids.
6765
"""
68-
if py2:
69-
as_bytes = array('h', tokens).tostring()
70-
if py3:
71-
as_bytes = array('h', tokens).tobytes()
66+
as_bytes = array('h', tokens).tobytes()
7267
return md5(as_bytes).digest()
7368

7469

src/licensedcode/tokenize.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
from binascii import crc32
4141
import re
4242

43-
from commoncode.system import py2
44-
from commoncode.system import py3
4543
from licensedcode.stopwords import STOPWORDS
4644
from textcode.analysis import numbered_text_lines
4745

@@ -229,8 +227,7 @@ def select_ngrams(ngrams, with_pos=False):
229227
# FIXME: use a proper hash
230228
nghs = []
231229
for ng in ngram:
232-
if ((py2 and isinstance(ng, basestring))
233-
or (py3 and isinstance(ng, str))):
230+
if isinstance(ng, str):
234231
ng = bytearray(ng, encoding='utf-8')
235232
else:
236233
ng = bytearray(str(ng).encode('utf-8'))

src/packagedcode/jar_manifest.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import attr
3333

3434
from commoncode.fileutils import as_posixpath
35-
from commoncode.fileutils import py2
3635
from packagedcode.utils import normalize_vcs_url
3736
from packagedcode.maven import parse_scm_connection
3837
from packagedcode.models import Package
@@ -82,10 +81,7 @@ def parse_manifest(location):
8281
"""
8382
Return a Manifest parsed from the file at `location` or None if this
8483
cannot be parsed. """
85-
if py2:
86-
mode = 'rb'
87-
else:
88-
mode = 'r'
84+
mode = 'r'
8985
with open(location, mode) as manifest:
9086
return parse_manifest_data(manifest.read())
9187

src/packagedcode/pypi.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949

5050
from commoncode import filetype
5151
from commoncode import fileutils
52-
from commoncode.system import py2
5352
from packagedcode import models
5453
from packagedcode.utils import build_description
5554
from packagedcode.utils import combine_expressions
@@ -243,10 +242,7 @@ def parse_with_dparse(location):
243242
filetypes.pipfile,
244243
filetypes.pipfile_lock):
245244
return
246-
if py2:
247-
mode = 'rb'
248-
else:
249-
mode = 'r'
245+
mode = 'r'
250246
with open(location, mode) as f:
251247
content = f.read()
252248

@@ -329,10 +325,7 @@ def parse_setup_py(location):
329325
return
330326

331327
# FIXME: what if this is unicode text?
332-
if py2:
333-
mode = 'rb'
334-
else:
335-
mode = 'r'
328+
mode = 'r'
336329
with open(location, mode) as inp:
337330
setup_text = inp.read()
338331

src/packagedcode/recognize.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from commoncode.fileutils import fsencode
3838
from commoncode.fileutils import splitext_name
3939
from commoncode.system import on_linux
40-
from commoncode.system import py2
4140
from packagedcode import PACKAGE_TYPES
4241
from typecode import contenttype
4342

@@ -90,9 +89,6 @@ def recognize_packages(location):
9089
for package_type in PACKAGE_TYPES:
9190
# Note: default to True if there is nothing to match against
9291
metafiles = package_type.metafiles
93-
if on_linux and py2:
94-
metafiles = (fsencode(m) for m in metafiles)
95-
9692
if any(fnmatch.fnmatchcase(filename, metaf) for metaf in metafiles):
9793
for recognized in package_type.recognize(location):
9894
if TRACE:logger_debug('recognize_packages: metafile matching: recognized:', recognized)
@@ -114,9 +110,6 @@ def recognize_packages(location):
114110
extension_matched = False
115111
extensions = package_type.extensions
116112
if extensions:
117-
if on_linux and py2:
118-
extensions = (fsencode(e) for e in extensions)
119-
120113
extensions = (e.lower() for e in extensions)
121114
extension_matched = any(fnmatch.fnmatchcase(extension, ext_pat)
122115
for ext_pat in extensions)

src/scancode/cli.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class WindowsError(Exception):
6868
from commoncode.fileutils import PATH_TYPE
6969
from commoncode.fileutils import POSIX_PATH_SEP
7070
from commoncode.timeutils import time2tstamp
71-
from commoncode.system import py2
7271
from commoncode.system import on_windows
7372
from commoncode.system import on_linux
7473

@@ -590,10 +589,7 @@ def echo_func(*_args, **_kwargs):
590589

591590
if not isinstance(input, (list, tuple)):
592591
# nothing else todo
593-
if on_linux and py2:
594-
assert isinstance(input, bytes)
595-
else:
596-
assert isinstance(input, compat.unicode)
592+
assert isinstance(input, compat.unicode)
597593

598594
elif len(input) == 1:
599595
# we received a single input path, so we treat this as a single path
@@ -1206,10 +1202,7 @@ def scan_codebase(codebase, scanners, processes=1, timeout=DEFAULT_TIMEOUT,
12061202

12071203
while True:
12081204
try:
1209-
if py2:
1210-
location, rid, scan_errors, scan_time, scan_result, scan_timings = scans.next()
1211-
else:
1212-
location, rid, scan_errors, scan_time, scan_result, scan_timings = next(scans)
1205+
location, rid, scan_errors, scan_time, scan_result, scan_timings = next(scans)
12131206

12141207
if TRACE_DEEP:
12151208
logger_debug(

0 commit comments

Comments
 (0)