Skip to content

Commit c588b4e

Browse files
committed
Merge branch Abhishek-Dev09/295-drop-py2
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2 parents e87d3dd + c7e3cc2 commit c588b4e

69 files changed

Lines changed: 593 additions & 1611 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

etc/scripts/scanserv.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ def run_scan(location, **kwargs):
4545

4646

4747
if __name__ == '__channelexec__':
48-
from commoncode import compat
4948
for kwargs in channel: # NOQA
5049
# a mapping of kwargs or a location string
51-
if isinstance(kwargs, (str, compat.unicode)):
50+
if isinstance(kwargs, (str, str)):
5251
channel.send(run_scan(kwargs)) # NOQA
5352
elif isinstance(kwargs, dict):
5453
channel.send(run_scan(**kwargs)) # NOQA

etc/scripts/synclic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
from commoncode import fetch
4747
from commoncode import fileutils
48-
from commoncode import compat
4948

5049
import licensedcode
5150
from licensedcode.models import load_licenses
@@ -898,7 +897,7 @@ def update_external(_attrib, _sc_val, _ext_val):
898897

899898
continue
900899

901-
if (isinstance(scancode_value, compat.unicode) and isinstance(external_value, compat.unicode)):
900+
if (isinstance(scancode_value, str) and isinstance(external_value, str)):
902901
# keep the stripped and normalized spaces value
903902
# normalized spaces
904903
normalized_scancode_value = ' '.join(scancode_value.split())

src/cluecode/finder.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
from six import string_types
3434
import urlpy
3535

36-
from commoncode import compat
37-
from commoncode.system import py3
3836
from commoncode.text import toascii
3937
from cluecode import finder_data
4038
from textcode import analysis
@@ -251,7 +249,7 @@ def find_urls(location, unique=True):
251249
if TRACE_URL:
252250
logger_debug('find_urls: lineno:', lineno, '_line:', repr(_line),
253251
'type(url):', type(url), 'url:', repr(url))
254-
yield compat.unicode(url), lineno
252+
yield str(url), lineno
255253

256254

257255
EMPTY_URLS = set(['https', 'http', 'ftp', 'www', ])
@@ -462,7 +460,7 @@ def get_ip(s):
462460
return False
463461

464462
try:
465-
ip = ipaddress.ip_address(compat.unicode(s))
463+
ip = ipaddress.ip_address(str(s))
466464
return ip
467465
except ValueError:
468466
return False

src/formattedcode/output_csv.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from six import string_types
3434
import unicodecsv
3535

36-
from commoncode import compat
3736
from formattedcode import FileOptionType
3837
from plugincode.output import output_impl
3938
from plugincode.output import OutputPlugin
@@ -320,7 +319,7 @@ def flatten_package(_package, path, prefix='package__'):
320319
if isinstance(component_val, list):
321320
component_val = '\n'.join(component_val)
322321

323-
if not isinstance(component_val, compat.unicode):
322+
if not isinstance(component_val, str):
324323
component_val = repr(component_val)
325324

326325
existing = pack.get(component_new_key) or []
@@ -338,7 +337,7 @@ def flatten_package(_package, path, prefix='package__'):
338337

339338
pack[nk] = ''
340339

341-
if isinstance(val, compat.unicode):
340+
if isinstance(val, str):
342341
pack[nk] = val
343342
else:
344343
# Use repr if not a string

src/formattedcode/output_html.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,13 @@
4040
import click
4141
import simplejson
4242

43-
from commoncode import compat
4443
from commoncode.fileutils import PATH_TYPE
4544
from commoncode.fileutils import as_posixpath
4645
from commoncode.fileutils import copytree
4746
from commoncode.fileutils import delete
4847
from commoncode.fileutils import file_name
4948
from commoncode.fileutils import file_base_name
50-
from commoncode.fileutils import fsencode
5149
from commoncode.fileutils import parent_directory
52-
from commoncode.system import on_linux
53-
from commoncode.system import py2
54-
from commoncode.system import py3
5550
from formattedcode import FileOptionType
5651
from commoncode.cliutils import PluggableCommandLineOption
5752
from commoncode.cliutils import OUTPUT_GROUP
@@ -121,10 +116,6 @@ def is_enabled(self, custom_output, custom_template, **kwargs):
121116
def process_codebase(self, codebase, custom_output, custom_template, **kwargs):
122117
results = self.get_files(codebase, **kwargs)
123118
version = codebase.get_or_create_current_header().tool_version
124-
125-
if on_linux and py2:
126-
custom_template = fsencode(custom_template)
127-
128119
template_loc = custom_template
129120
output_file = custom_output
130121
write_templated(output_file, results, version, template_loc)
@@ -139,7 +130,7 @@ def write_templated(output_file, results, version, template_loc):
139130
template = get_template(template_loc)
140131

141132
for template_chunk in generate_output(results, version, template):
142-
assert isinstance(template_chunk, compat.unicode)
133+
assert isinstance(template_chunk, str)
143134
try:
144135
output_file.write(template_chunk)
145136
except Exception:
@@ -326,16 +317,9 @@ def create_html_app(output_file, results, version, scanned_path): # NOQA
326317
with io.open(join(target_assets_dir, 'help.html'), 'w', encoding='utf-8') as f:
327318
f.write(rendered_help)
328319

329-
# write json data
330320
# FIXME: this should a regular JSON scan format
331-
if py2:
332-
mode = 'wb'
333-
prefix = b'data='
334-
if py3:
335-
mode = 'w'
336-
prefix = u'data='
337-
with io.open(join(target_assets_dir, 'data.js'), mode) as f:
338-
f.write(prefix)
321+
with io.open(join(target_assets_dir, 'data.js'), 'w') as f:
322+
f.write('data=')
339323
simplejson.dump(results, f, iterable_as_array=True)
340324

341325
except HtmlAppAssetCopyWarning as w:

src/formattedcode/output_json.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import jsonstreams
3131
from six import string_types
3232

33-
from commoncode.system import py2
34-
from commoncode.system import py3
3533
from formattedcode import FileOptionType
3634
from commoncode.cliutils import PluggableCommandLineOption
3735
from commoncode.cliutils import OUTPUT_GROUP
@@ -64,27 +62,12 @@ def logger_debug(*args):
6462
and a or repr(a) for a in args))
6563

6664

67-
if py2:
68-
mode = 'wb'
69-
space = b' '
70-
comma = b','
71-
colon = b':'
72-
eol = b'\n'
73-
74-
if py3:
75-
mode = 'w'
76-
space = u' '
77-
comma = u','
78-
colon = u':'
79-
eol = u'\n'
80-
81-
8265
@output_impl
8366
class JsonCompactOutput(OutputPlugin):
8467

8568
options = [
8669
PluggableCommandLineOption(('--json', 'output_json',),
87-
type=FileOptionType(mode=mode, lazy=True),
70+
type=FileOptionType(mode='w', lazy=True),
8871
metavar='FILE',
8972
help='Write scan output as compact JSON to FILE.',
9073
help_group=OUTPUT_GROUP,
@@ -103,7 +86,7 @@ class JsonPrettyOutput(OutputPlugin):
10386

10487
options = [
10588
PluggableCommandLineOption(('--json-pp', 'output_json_pp',),
106-
type=FileOptionType(mode=mode, lazy=True),
89+
type=FileOptionType(mode='w', lazy=True),
10790
metavar='FILE',
10891
help='Write scan output as pretty-printed JSON to FILE.',
10992
help_group=OUTPUT_GROUP,
@@ -134,10 +117,10 @@ def write_results(codebase, output_file, pretty=False, **kwargs):
134117
# If `output_file` is a path string, open the file at path `output_file` and use it as `output_file`
135118
close_fd = False
136119
if isinstance(output_file, string_types):
137-
output_file = open(output_file, mode)
120+
output_file = open(output_file, 'w')
138121
close_fd = True
139122

140-
# Begin writing JSON to `output_file`
123+
# Begin wri'w' JSON to `output_file`
141124
with jsonstreams.Stream(jsonstreams.Type.object, fd=output_file, close_fd=close_fd, **jsonstreams_kwargs) as s:
142125
# Write headers
143126
codebase.add_files_count_to_current_header()
@@ -151,10 +134,8 @@ def write_results(codebase, output_file, pretty=False, **kwargs):
151134

152135
# Write files
153136
codebase_files = OutputPlugin.get_files(codebase, **kwargs)
154-
if py3:
155-
# OutputPlugin.get_files() returns a `map()`, which isn's JSON
156-
# serializable in Python 3
157-
codebase_files = list(codebase_files)
137+
# OutputPlugin.get_files() returns a generator, not JSON-serializable
138+
codebase_files = list(codebase_files)
158139
s.write('files', codebase_files)
159140

160141

src/formattedcode/output_jsonlines.py

Lines changed: 6 additions & 25 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 formattedcode import FileOptionType
3533
from commoncode.cliutils import OUTPUT_GROUP
3634
from commoncode.cliutils import PluggableCommandLineOption
@@ -42,29 +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'
60-
61-
6243
@output_impl
6344
class JsonLinesOutput(OutputPlugin):
6445

6546
options = [
6647
PluggableCommandLineOption(('--json-lines', 'output_json_lines',),
67-
type=FileOptionType(mode=mode, lazy=True),
48+
type=FileOptionType(mode='w', lazy=True),
6849
metavar='FILE',
6950
help='Write scan output as JSON Lines to FILE.',
7051
help_group=OUTPUT_GROUP,
@@ -86,21 +67,21 @@ def process_codebase(self, codebase, output_json_lines, **kwargs):
8667
simplejson_kwargs = dict(
8768
iterable_as_array=True,
8869
encoding='utf-8',
89-
separators=(comma, colon,)
70+
separators=(u',', u':',)
9071
)
9172
output_json_lines.write(
9273
simplejson.dumps(headers, **simplejson_kwargs))
93-
output_json_lines.write(eol)
74+
output_json_lines.write('\n')
9475

9576
for name, value in codebase.attributes.to_dict().items():
9677
if value:
9778
smry = {name: value}
9879
output_json_lines.write(
9980
simplejson.dumps(smry, **simplejson_kwargs))
100-
output_json_lines.write(eol)
81+
output_json_lines.write('\n')
10182

10283
for scanned_file in files:
103-
scanned_file_line = {file_key: [scanned_file]}
84+
scanned_file_line = {'files': [scanned_file]}
10485
output_json_lines.write(
10586
simplejson.dumps(scanned_file_line, **simplejson_kwargs))
106-
output_json_lines.write(eol)
87+
output_json_lines.write('\n')

src/formattedcode/output_spdx.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ def write_spdx(output_file, files, tool_name, tool_version, notice, input_file,
196196
"""
197197
Write scan output as SPDX Tag/value or RDF.
198198
"""
199+
as_rdf = not as_tagvalue
199200
_patch_license_list()
200-
201201
absinput = abspath(input_file)
202202

203203
if isdir(absinput):
@@ -341,24 +341,20 @@ def write_spdx(output_file, files, tool_name, tool_version, notice, input_file,
341341

342342
if as_tagvalue:
343343
from spdx.writers.tagvalue import write_document # NOQA
344-
else:
344+
elif as_rdf:
345345
from spdx.writers.rdf import write_document # NOQA
346346

347347
if as_tagvalue:
348-
# unicode text everywhere
349348
spdx_output = StringIO()
350-
else:
351-
# rdf as utf-encoded bytes on Py2
349+
elif as_rdf:
350+
# rdf is utf-encoded bytes
352351
spdx_output = BytesIO()
353352

354353
write_document(doc, spdx_output, validate=False)
355354
result = spdx_output.getvalue()
356355

357-
if as_tagvalue:
358-
# unicode text everywhere
359-
pass
360-
else:
361-
# rdf as utf-encoded bytes on Py2
356+
if as_rdf:
357+
# rdf is utf-encoded bytes
362358
result = result.decode('utf-8')
363359

364360
output_file.write(result)

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/data/licenses/ecfonts-1.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ short_name: latex-ec-fonts
33
name: Copyright notice to the ec fonts
44
category: Permissive
55
homepage_url: http://dante.ctan.org
6+
owner: Joerg Knappen
67
text_urls:
78
- http://dante.ctan.org/tex-archive/fonts/ec/src/copyrite.txt

0 commit comments

Comments
 (0)